From: Marcin Slusarz <marcin.slusarz@gmail.com>
To: Christoph Hellwig <hch@lst.de>
Cc: LKML <linux-kernel@vger.kernel.org>,
Andrew Morton <akpm@linux-foundation.org>,
Al Viro <viro@ZenIV.linux.org.uk>
Subject: Re: [PATCH 3/6] vfs: open_exec cleanup
Date: Thu, 22 May 2008 17:57:05 +0200 [thread overview]
Message-ID: <20080522155645.GA8447@joi> (raw)
In-Reply-To: <20080519055334.GA14902@lst.de>
On Mon, May 19, 2008 at 07:53:34AM +0200, Christoph Hellwig wrote:
> On Mon, May 19, 2008 at 12:01:49AM +0200, Marcin Slusarz wrote:
> > open_exec is needlessly indented, calls ERR_PTR with 0 argument
> > (which is not valid errno) and jumps into middle of function
> > just to return value.
> > So clean it up a bit.
>
> Still looks rather messy. See below for a better version.
looks much better, thanks
Reviewed-by: Marcin Slusarz <marcin.slusarz@gmail.com>
>
> Signed-off-by: Christoph Hellwig <hch@lst.de>
>
> Index: linux-2.6/fs/exec.c
> ===================================================================
> --- linux-2.6.orig/fs/exec.c 2008-05-19 07:45:18.000000000 +0200
> +++ linux-2.6/fs/exec.c 2008-05-19 07:53:17.000000000 +0200
> @@ -654,38 +654,40 @@ EXPORT_SYMBOL(setup_arg_pages);
> struct file *open_exec(const char *name)
> {
> struct nameidata nd;
> - int err;
> struct file *file;
> + int err;
>
> - err = path_lookup_open(AT_FDCWD, name, LOOKUP_FOLLOW, &nd, FMODE_READ|FMODE_EXEC);
> - file = ERR_PTR(err);
> + err = path_lookup_open(AT_FDCWD, name, LOOKUP_FOLLOW, &nd,
> + FMODE_READ|FMODE_EXEC);
> + if (err)
> + goto out;
>
> - if (!err) {
> - struct inode *inode = nd.path.dentry->d_inode;
> - file = ERR_PTR(-EACCES);
> - if (S_ISREG(inode->i_mode)) {
> - int err = vfs_permission(&nd, MAY_EXEC);
> - file = ERR_PTR(err);
> - if (!err) {
> - file = nameidata_to_filp(&nd,
> - O_RDONLY|O_LARGEFILE);
> - if (!IS_ERR(file)) {
> - err = deny_write_access(file);
> - if (err) {
> - fput(file);
> - file = ERR_PTR(err);
> - }
> - }
> -out:
> - return file;
> - }
> - }
> - release_open_intent(&nd);
> - path_put(&nd.path);
> + err = -EACCES;
> + if (!S_ISREG(nd.path.dentry->d_inode->i_mode))
> + goto out_path_put;
> +
> + err = vfs_permission(&nd, MAY_EXEC);
> + if (err)
> + goto out_path_put;
> +
> + file = nameidata_to_filp(&nd, O_RDONLY|O_LARGEFILE);
> + if (IS_ERR(file))
> + return file;
> +
> + err = deny_write_access(file);
> + if (err) {
> + fput(file);
> + goto out;
> }
> - goto out;
> -}
>
> + return file;
> +
> + out_path_put:
> + release_open_intent(&nd);
> + path_put(&nd.path);
> + out:
> + return ERR_PTR(err);
> +}
> EXPORT_SYMBOL(open_exec);
>
> int kernel_read(struct file *file, unsigned long offset,
>
next prev parent reply other threads:[~2008-05-22 15:57 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-05-11 20:12 [PATCH] let ERR_PTR BUILD_BUG_ON when we know its argument is not a valid errno Marcin Slusarz
2008-05-12 23:38 ` Andrew Morton
2008-05-13 20:18 ` Marcin Slusarz
2008-05-18 21:56 ` [PATCH 0/6] Sanity checks for ERR_PTR argument Marcin Slusarz
2008-05-18 21:56 ` [PATCH 1/6] ERR_PTR: if errno value is known at compile time, make sure it's valid Marcin Slusarz
2008-05-19 6:38 ` Alexey Dobriyan
2008-05-22 16:03 ` Marcin Slusarz
2008-05-18 22:01 ` [PATCH 2/6] ERR_PTR: add ERR_OR_0_PTR Marcin Slusarz
2008-05-18 23:04 ` Johannes Weiner
2008-05-19 5:55 ` Christoph Hellwig
2008-05-19 6:33 ` Al Viro
2008-05-18 22:01 ` [PATCH 3/6] vfs: open_exec cleanup Marcin Slusarz
2008-05-19 5:53 ` Christoph Hellwig
2008-05-22 15:57 ` Marcin Slusarz [this message]
2008-05-18 22:03 ` [PATCH 4/6] procfs: switch ERR_PTR to ERR_OR_0_PTR when "error" might be 0 Marcin Slusarz
2008-05-18 22:03 ` [PATCH 5/6] vfs: fix ERR_PTR abuse in generic_readlink Marcin Slusarz
2008-05-18 22:04 ` [PATCH 6/6] ERR_PTR: warn when ERR_PTR parameter is not errno value Marcin Slusarz
2008-05-18 23:13 ` Johannes Weiner
2008-05-19 6:43 ` Alexey Dobriyan
2008-05-19 12:11 ` Johannes Weiner
2008-05-22 16:08 ` Marcin Slusarz
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=20080522155645.GA8447@joi \
--to=marcin.slusarz@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=hch@lst.de \
--cc=linux-kernel@vger.kernel.org \
--cc=viro@ZenIV.linux.org.uk \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.