sysfs unbind, miscdev

Martin Kaiser lists at kaiser.cx
Wed Mar 21 12:26:57 EDT 2018


Dear all,

I have a driver that is an spi device on one side and a miscdevice on
the other.

By default, it has the sysfs bind and unbind nodes (I know that I can
deactiate them).

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.)

During the unbind, the driver's remove function is called and all devres
resources are freed. Amongst them is a struct that is used as
file->prvate_data for the miscdev. The client can still continue to
write to the miscdev and crash the driver because file->private_data
points to invalid data now.

What is the correct way to handle this? Is there a way to "disconnect"
all clients of the miscdev during remove?

Thanks,
Martin



More information about the Kernelnewbies mailing list