From: lists@kaiser.cx (Martin Kaiser) Date: Wed, 21 Mar 2018 17:26:57 +0100 Subject: sysfs unbind, miscdev Message-ID: <20180321162657.GA3508@botnar.kaiser.cx> To: kernelnewbies@lists.kernelnewbies.org List-Id: kernelnewbies.lists.kernelnewbies.org 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