From: "Hillf Danton" <hillf.zj@alibaba-inc.com>
To: "'NeilBrown'" <neilb@suse.de>
Cc: "'Al Viro'" <viro@zeniv.linux.org.uk>,
"linux-kernel" <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH 03/79] ovl: rearrange ovl_follow_link to it doesn't need to call ->put_link
Date: Tue, 05 May 2015 15:12:28 +0800 [thread overview]
Message-ID: <0a0301d08702$d8c41d80$8a4c5880$@alibaba-inc.com> (raw)
In-Reply-To: <0a0201d08701$bb0ea2c0$312be840$@alibaba-inc.com>
>
> From: NeilBrown <neilb@suse.de>
>
> ovl_follow_link current calls ->put_link on an error path.
> However ->put_link is about to change in a way that it will be
> impossible to call it from ovl_follow_link.
>
> So rearrange the code to avoid the need for that error path.
> Specifically: move the kmalloc() call before the ->follow_link()
> call to the subordinate filesystem.
>
> Signed-off-by: NeilBrown <neilb@suse.de>
> Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
> ---
> fs/overlayfs/inode.c | 25 ++++++++++++-------------
> 1 file changed, 12 insertions(+), 13 deletions(-)
>
> diff --git a/fs/overlayfs/inode.c b/fs/overlayfs/inode.c
> index 04f1248..1b4b9c5e 100644
> --- a/fs/overlayfs/inode.c
> +++ b/fs/overlayfs/inode.c
> @@ -145,6 +145,7 @@ static void *ovl_follow_link(struct dentry *dentry, struct nameidata *nd)
> void *ret;
> struct dentry *realdentry;
> struct inode *realinode;
> + struct ovl_link_data *data = NULL;
>
> realdentry = ovl_dentry_real(dentry);
> realinode = realdentry->d_inode;
> @@ -152,25 +153,23 @@ static void *ovl_follow_link(struct dentry *dentry, struct nameidata *nd)
> if (WARN_ON(!realinode->i_op->follow_link))
> return ERR_PTR(-EPERM);
>
> - ret = realinode->i_op->follow_link(realdentry, nd);
> - if (IS_ERR(ret))
> - return ret;
> -
> if (realinode->i_op->put_link) {
> - struct ovl_link_data *data;
> -
> data = kmalloc(sizeof(struct ovl_link_data), GFP_KERNEL);
> - if (!data) {
> - realinode->i_op->put_link(realdentry, nd, ret);
> + if (!data)
> return ERR_PTR(-ENOMEM);
> - }
> data->realdentry = realdentry;
> - data->cookie = ret;
> + }
>
> - return data;
> - } else {
> - return NULL;
> + ret = realinode->i_op->follow_link(realdentry, nd);
> + if (IS_ERR(ret)) {
> + kfree(data);
> + return ret;
> }
> +
> + if (data)
No need to check again(see the above kfree(data) please).
> + data->cookie = ret;
> +
> + return data;
> }
>
> static void ovl_put_link(struct dentry *dentry, struct nameidata *nd, void *c)
> --
> 2.1.4
next parent reply other threads:[~2015-05-05 7:13 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <0a0201d08701$bb0ea2c0$312be840$@alibaba-inc.com>
2015-05-05 7:12 ` Hillf Danton [this message]
2015-05-05 8:34 ` NeilBrown
2015-05-05 5:22 [RFC][PATCHSET] non-recursive pathname resolution Al Viro
2015-05-05 5:21 ` [PATCH 03/79] ovl: rearrange ovl_follow_link to it doesn't need to call ->put_link Al Viro
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='0a0301d08702$d8c41d80$8a4c5880$@alibaba-inc.com' \
--to=hillf.zj@alibaba-inc.com \
--cc=linux-kernel@vger.kernel.org \
--cc=neilb@suse.de \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®