Device drivers must not create device attributes!
Posted Jun 26, 2003 15:14 UTC (Thu) by Alan.Stern
Parent article: Driver porting: Devices and attributes
This otherwise helpful article contains a mistake that has been made by several developers. Device drivers do not own the device structures they register; these are owned by the bus driver. The most important consequence of this is that the device driver cannot know when all references to its device structure have gone away. References to a device attribute file may persist indefinitely, for as long as a user process has the attribute file open.
This means that even after a driver has de-registered its device and has been rmmod'ed and unloaded from memory, the attribute's show() or store() methods might be called. Of course this would be a disaster, since the code for that method would no longer exist.
People now recognize that drivers should only create attributes for device structures that they own. The proper way to create a device-specific attribute is to attach the attribute to a class_device, because the driver is able to create and own its class_devices. A driver should never attach an attribute to the device structure it is bound to.
to post comments)