misc: pass miscdevice through file's private_data
PATCH 1/1 misc: pass miscdevice through file's private_data
Make the miscdevice accessible through the file's private_data.
Previously, this was done only when an open() file operation had been registered. If no custom open() file operation was defined, private_data was set to NULL.
This subtle quirk was confusing, to the point where kernel code registered *empty* file open operations to have private_data point to the misc device structure and avoid duplicating that logic.
And it could easily lead to bugs, where the addition or removal of a custom open() file operation surprisingly changes the initial value of a file's private_data structure.
To resolve this, we now place the miscdevice in the file's private_data member unconditionally when open() is called.
---
All kernel code that uses private_data and misc_register() has been checked for potential regressions and the code that relied on this subtle behavior (only FUSE) has been fixed.
Although I feel confident about this patch, it might still be a good idea to keep this in linux-next for at least a whole cycle, as Martin Kepplinger suggested. As you wish.
Mind that the documentation about this change has already been submitted by Martin and accepted into linux-next (commit 03190c67).
drivers/char/misc.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-)
drivers/char/misc.c +8 -3
@@ -140,12 +140,17 @@ static int misc_open(struct inode * inode, struct file * file) goto fail; } +/* +* Place the miscdevice in the file's +* private_data so it can be used by the +* file operations, including f_op->open below +*/ + file->private_data = c; + err =0 ;replace_fops (file, new_fops); -if (file->f_op->open) { - file->private_data = c; +if (file->f_op->open) err = file->f_op->open (inode,file); - } fail:mutex_unlock (&misc_mtx);return err;
Signature · 1 line
2.1.0