Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756290AbbEEHNY (ORCPT ); Tue, 5 May 2015 03:13:24 -0400 Received: from mail113-250.mail.alibaba.com ([205.204.113.250]:46522 "EHLO us-alimail-mta1.hst.scl.en.alidc.net" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1756229AbbEEHNR (ORCPT ); Tue, 5 May 2015 03:13:17 -0400 X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R141e4;FP=0|-1|-1|-1|0|-1|-1|-1;HT=r41g03020;MF=hillf.zj@alibaba-inc.com;PH=DS;RN=3;RT=3;SR=0; Reply-To: "Hillf Danton" From: "Hillf Danton" To: "'NeilBrown'" Cc: "'Al Viro'" , "linux-kernel" References: <0a0201d08701$bb0ea2c0$312be840$@alibaba-inc.com> In-Reply-To: <0a0201d08701$bb0ea2c0$312be840$@alibaba-inc.com> 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 Message-ID: <0a0301d08702$d8c41d80$8a4c5880$@alibaba-inc.com> MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit X-Mailer: Microsoft Outlook 14.0 Thread-Index: AQEy0EA9HtXUTZu5TVqnCZwJkMYDvZ6oYwRQ Content-Language: zh-cn Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2290 Lines: 77 > > From: NeilBrown > > 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 > Signed-off-by: Al Viro > --- > 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 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/