BUG(?): class_device_driver_link()

From: Alan Stern
Date: Fri Jun 18 2004 - 15:21:00 EST


Greg:

I'm not sure if this is a bug or not, but it is inconsistent behavior in
sysfs.

When a class_device is added, if it has a regular device associated with
it and that device has a driver, a symlink is added from the class_device
to the driver. However, if the class_device is added _first_ and the
driver later, this symlink is not created. It's not clear that there's
any good way to create it, especially if the class_device is added by the
bus layer and the device driver itself is unaware of the class_device.

Is this a known problem? It definitely affects the sd driver, and maybe
others.

There is a related side-effect that is a bit unpleasant. The symlink from
the class_device to the driver increments the driver's refcount. Since
the driver is unaware of the class_device, it doesn't know to remove the
symlink when its release() method runs. Consequently, if the driver is
modprobed before the device exists and rmmod'ed after the device is added,
the rmmod will hang until the device also goes away. But if the driver is
modprobed _after_ the device exists then the rmmod will complete
immediately.

Perhaps the answer is that the bus layer must take these things into
account. Or perhaps a struct device should somehow know about all the
class_devices that refer to it.

Alan Stern


-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/