Race in removal of host class device attribute file

Alan Stern
2003-10-16T21:09:05Z

I've created a class device attribute file for the hosts supported by the
usb-storage driver, using the shost_attrs member of the host template.
It seems to contain an intractable race condition when unregistering the
host. There's no way for the driver to know when the scsi host's class
device is released, so there's no way to know when it's safe to deallocate
the host's driver-specific data structure. Waiting until
scsi_remove_host() returns isn't good enough, because a user process might
keep the attribute file open and thus prevent release of the class device
indefinitely.

What's the right way to solve this problem? It seems to me that it must
involve creating a kobject in the driver-specific host data structure, on
which the class device's release() routine could do a kobject_put(). That
way the driver would be able to tell when it should free the data
structure. But code to handle this would have to be added to the scsi
core.

Alan Stern