Re: Race in removal of host class device attribute file

Mike Anderson
2003-10-16T22:43:48Z

Alan Stern [stern@rowland.harvard.edu] wrote:
> 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
>

The free of this data has to happen on some release function. How are
you allocating the data / class_device_attribute structure? If the
allocation came from the scsi_host_alloc extra bytes the data will not
be free'd until scsi_host_dev_release().

-andmike
--
Michael Anderson
andmike@us.ibm.com