refcounting for devclass_get_devices()

From: Nate Lawson <nate_at_root.org>
Date: Sat, 17 Apr 2004 22:06:26 -0700 (PDT)
I am doing some locking work and ran across a tough case.  It's useful to
use devclass_get_devices() when iterating across a whole set of softcs.
However, I didn't want to implement my own refcount for the returned
pointer.  Are there any plans to deal with this interface?  As a driver,
how can I know when a device is going away or keep it refed because I hold
a pointer to its softc?  Since it mallocs data, I can't hold a device lock
across calling it and by the next instruction, one of the devices in the
array may have been destroyed.

The code is usually:

    devclass_get_devices(acpi_cmbat_devclass, &acpi_cmbat_devs,
        &acpi_cmbat_units);
    for (i = 0; i < acpi_cmbat_units; i++)
        sc = device_get_softc(acpi_cmbat_devs[i]);
        ...

Thanks,
Nate
Received on Sat Apr 17 2004 - 20:06:24 UTC

This archive was generated by hypermail 2.4.0 : Wed May 19 2021 - 11:37:51 UTC