Hello, Eric.
On 01/02/2010 12:16 AM, Eric W. Biederman wrote:
The synchronization against read/write ops is in sysfs_deactivate on
purpose so that drivers (most common users) don't have to worry about
sysfs ops accessing different parts of data structures once
device_del() is complete. Implementing the exlusion at the driver
level is possible but not easy because some hardware devices are
represented with complex data structures, some of them are reused when
devices are exchanged and some sysfs ops end up accessing the
hardware. So, it's often not possible to simply disassociate the data
structure and float it till the last reference goes away. There needs
to be a synchronization point where the driver can tell that nothing
is accessing released data structure or hardware resource after it and
it's far easier to define it at the sysfs level.
Nobody would know when that final put will actually happen. In
progress sysfs ops might access the hardware after the hardware is
gone or replaced with another unit.
I don't think this is really relevant to the problem at hand but
adding lockdep annotations would definitely be beneficial, which BTW
is another reason to leave the synchronization in sysfs_deactivate as
the trade off is between deadlocks which can be detected somewhat
reliably with lockdep and scary race conditions which may involve
hardware in mysterious ways.
Thanks.
--
tejun
--