refcounting for devclass_get_devices()

Nate Lawson nate at root.org
Sat Apr 17 22:06:24 PDT 2004


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


More information about the freebsd-current mailing list