* Re: [PATCH 03/79] ovl: rearrange ovl_follow_link to it doesn't need to call ->put_link
[not found] <0a0201d08701$bb0ea2c0$312be840$@alibaba-inc.com>
@ 2015-05-05 7:12 ` Hillf Danton
2015-05-05 8:34 ` NeilBrown
0 siblings, 1 reply; 3+ messages in thread
From: Hillf Danton @ 2015-05-05 7:12 UTC (permalink / raw)
To: 'NeilBrown'; +Cc: 'Al Viro', linux-kernel
>
> 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
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH 03/79] ovl: rearrange ovl_follow_link to it doesn't need to call ->put_link
2015-05-05 7:12 ` [PATCH 03/79] ovl: rearrange ovl_follow_link to it doesn't need to call ->put_link Hillf Danton
@ 2015-05-05 8:34 ` NeilBrown
0 siblings, 0 replies; 3+ messages in thread
From: NeilBrown @ 2015-05-05 8:34 UTC (permalink / raw)
To: Hillf Danton; +Cc: 'Al Viro', linux-kernel
[-- Attachment #1: Type: text/plain, Size: 2399 bytes --]
On Tue, 05 May 2015 15:12:28 +0800 "Hillf Danton" <hillf.zj@alibaba-inc.com>
wrote:
> >
> > 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).
kfree(NULL) is perfectly valid.
NeilBrown
>
> > + data->cookie = ret;
> > +
> > + return data;
> > }
> >
> > static void ovl_put_link(struct dentry *dentry, struct nameidata *nd, void *c)
> > --
> > 2.1.4
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 811 bytes --]
^ permalink raw reply [flat|nested] 3+ messages in thread
* [PATCH 03/79] ovl: rearrange ovl_follow_link to it doesn't need to call ->put_link
2015-05-05 5:22 [RFC][PATCHSET] non-recursive pathname resolution Al Viro
@ 2015-05-05 5:21 ` Al Viro
0 siblings, 0 replies; 3+ messages in thread
From: Al Viro @ 2015-05-05 5:21 UTC (permalink / raw)
To: Linus Torvalds; +Cc: Neil Brown, Christoph Hellwig, linux-kernel, linux-fsdevel
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)
+ data->cookie = ret;
+
+ return data;
}
static void ovl_put_link(struct dentry *dentry, struct nameidata *nd, void *c)
--
2.1.4
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2015-05-05 8:34 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
[not found] <0a0201d08701$bb0ea2c0$312be840$@alibaba-inc.com>
2015-05-05 7:12 ` [PATCH 03/79] ovl: rearrange ovl_follow_link to it doesn't need to call ->put_link Hillf Danton
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
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®