Re: [PATCH, RFC] sysfs: only allow one scheduled removal callback per kobj

Alex Chiang
2009-03-11T18:14:24Z

* Cornelia Huck <cornelia.huck@de.ibm.com>:
> On Wed, 11 Mar 2009 08:32:28 -0700,
> Greg KH <gregkh@suse.de> wrote:
>
> > Why can't you use device_unregister()? Or, you could use device_del(),
> > which lets you rely on the fact that the device structure is still
> > around for a bit, but it will disappear from sysfs. Just don't forget
> > to do the final put_device() on it to free the memory and "really"
> > release it.
> >
> > Or am I missing something else here?
>
> You can't unregister a device from one of its attribute callbacks, it
> locks up in sysfs (removing the sysfs dir waits for all active
> references to be dropped, but the reference obtained before calling
> ->store won't be dropped until after ->store returned...)
> device_schedule_callback() was introduced to solve exactly that problem.

Yes, that is exactly why I used device_schedule_callback.

> (For the original oops, I'd rather solve the problem by making sure the
> caller doesn't trigger removal several times - should probably be less
> code than the proposed patch?)

The scsi stuff [sdev_store_delete()] is susceptible to exactly
the same problem.

I could put the "only allow one removal per kobj" code into my
specific code path, but I think it makes more sense to put it in
the common code.

Thanks.

/ac