From: Tom Van Braeckel <tomvanbraeckel@gmail.com>
To: arnd@arndb.de, gregkh@linuxfoundation.org
Cc: linux-kernel@vger.kernel.org,
Tom Van Braeckel <tomvanbraeckel@gmail.com>
Subject: Re: [PATCH] Misc: pass miscdevice through file's private_data
Date: Fri, 5 Dec 2014 00:01:03 +0100 [thread overview]
Message-ID: <1417734063-28489-1-git-send-email-tomvanbraeckel@gmail.com> (raw)
In-Reply-To: <20141204211342.GA22293@kroah.com>
> >
> > + /*
> > + * 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;
> > err = file->f_op->open(inode,file);
> > }
>
> These braces aren't needed anymore, right?
>
> Also, what is this now going to break? :)
>
> thanks,
>
> greg k-h
Thanks for the fast feedback!
Good point, so I made a list of all drivers that use private_data (find drivers/ -iname "*.c" -exec grep -l private_data {} \; | sort -u) and manually verified that all of them either register an open() operation, do not use the misc subsystem, or matched because of vm_private_data.
>From this investigation, I conclude that it does not break anything.
I also removed the unnecessary curly braces. Please find the new patch below.
misc: pass miscdevice through file's private_data
Place the miscdevice in the file's private_data to be used by the file operations.
Previously, this was done only when an open() operation had been registered.
But it is also useful in the other file operations, so we pass it on unconditionally.
All drivers that use private_data and misc_register() were checked to ensure they register an open() operation,
in order to verify that this improvement does not break any existing driver that uses the misc subsystem.
Signed-off-by: Tom Van Braeckel <tomvanbraeckel@gmail.com>
---
drivers/char/misc.c | 11 ++++++++---
1 file changed, 8 insertions(+), 3 deletions(-)
diff --git a/drivers/char/misc.c b/drivers/char/misc.c
index ffa97d2..d6445de 100644
--- a/drivers/char/misc.c
+++ b/drivers/char/misc.c
@@ -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;
--
1.9.1
next prev parent reply other threads:[~2014-12-04 23:01 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-12-04 21:08 [PATCH] Misc: pass miscdevice through file's private_data Tom Van Braeckel
2014-12-04 21:13 ` Greg KH
2014-12-04 23:01 ` Tom Van Braeckel [this message]
2014-12-04 23:29 ` Greg KH
2014-12-05 4:37 ` [PATCH] misc: " Tom Van Braeckel
2015-01-09 23:02 ` Greg KH
2015-01-11 15:44 ` Tom Van Braeckel
2015-03-23 12:59 ` always assign miscdevice to file->private_data Martin Kepplinger
2015-03-23 12:59 ` [PATCH 1/4] char: misc: document behaviour of open() Martin Kepplinger
2015-03-23 12:59 ` [PATCH 2/4] fbdev: pxa3xx-gcu: remove redundant implementation " Martin Kepplinger
2015-03-23 12:59 ` [PATCH 3/4] fs: btrfs: set file->private data NULL after open() because we depend on it Martin Kepplinger
2015-03-23 12:59 ` [PATCH 4/4] lguest: explicitly set miscdevice's private_data NULL Martin Kepplinger
2015-03-31 13:08 ` [PATCH] misc: pass miscdevice through file's private_data Tom Van Braeckel
2015-03-31 13:19 ` Greg KH
-- strict thread matches above, loose matches on Subject: below --
2015-03-31 14:39 Tom Van Braeckel
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1417734063-28489-1-git-send-email-tomvanbraeckel@gmail.com \
--to=tomvanbraeckel@gmail.com \
--cc=arnd@arndb.de \
--cc=gregkh@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox