sysfs unbind, miscdev

valdis.kletnieks at vt.edu valdis.kletnieks at vt.edu
Wed Mar 21 13:43:45 EDT 2018


On Wed, 21 Mar 2018 17:26:57 +0100, Martin Kaiser said:
> I have a driver that is an spi device on one side and a miscdevice on
> the other.

This way usually leads to either madness or heavy drinking.

> Surprisingly to me, I can unbind the driver from the spi device on the
> bus while there's a user space client that has an open connection to the
> miscdev.  (If the driver was a module, I don't think I could unload it
> at this point.)

Not surprising actually, because there's nothing telling the kernel that it
shouldn't allow that - the rest of the kernel is convinced that the two are
different devices handled by different drivers.

The general fix for this is usually to make sure that something on one side of
the driver takes a reference against something onthe other one, so removing one
side out from under the other becomes impossible.

Of course, this means that the two devices then have a specified ordering for
removal (which may or may not be OK).  Having both sides take a reference on
the other can be made to allow removal in either order, but done improperly will
also allow deadlocking in either order. :)

Having each side's removal do a recursive call of the other's removal code can
also work, but remember to do locking so both sides don't try it at the same time....
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 486 bytes
Desc: not available
URL: <http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20180321/33346fca/attachment.sig>


More information about the Kernelnewbies mailing list