Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756830AbbEEIeZ (ORCPT ); Tue, 5 May 2015 04:34:25 -0400 Received: from cantor2.suse.de ([195.135.220.15]:54111 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756811AbbEEIeS (ORCPT ); Tue, 5 May 2015 04:34:18 -0400 Date: Tue, 5 May 2015 18:34:07 +1000 From: NeilBrown To: "Hillf Danton" Cc: "'Al Viro'" , "linux-kernel" Subject: Re: [PATCH 03/79] ovl: rearrange ovl_follow_link to it doesn't need to call ->put_link Message-ID: <20150505183407.4b5e02f9@notabene.brown> In-Reply-To: <0a0301d08702$d8c41d80$8a4c5880$@alibaba-inc.com> References: <0a0201d08701$bb0ea2c0$312be840$@alibaba-inc.com> <0a0301d08702$d8c41d80$8a4c5880$@alibaba-inc.com> X-Mailer: Claws Mail 3.10.1-162-g4d0ed6 (GTK+ 2.24.25; x86_64-suse-linux-gnu) MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; boundary="Sig_/y6r_LzQJvyxdkLxI6qmsTJa"; protocol="application/pgp-signature" Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 3693 Lines: 117 --Sig_/y6r_LzQJvyxdkLxI6qmsTJa Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable On Tue, 05 May 2015 15:12:28 +0800 "Hillf Danton" wrote: > >=20 > > From: NeilBrown > >=20 > > 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. > >=20 > > 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. > >=20 > > Signed-off-by: NeilBrown > > Signed-off-by: Al Viro > > --- > > fs/overlayfs/inode.c | 25 ++++++++++++------------- > > 1 file changed, 12 insertions(+), 13 deletions(-) > >=20 > > 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 =3D NULL; > >=20 > > realdentry =3D ovl_dentry_real(dentry); > > realinode =3D realdentry->d_inode; > > @@ -152,25 +153,23 @@ static void *ovl_follow_link(struct dentry *dentr= y, struct nameidata *nd) > > if (WARN_ON(!realinode->i_op->follow_link)) > > return ERR_PTR(-EPERM); > >=20 > > - ret =3D 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 =3D 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 =3D realdentry; > > - data->cookie =3D ret; > > + } > >=20 > > - return data; > > - } else { > > - return NULL; > > + ret =3D realinode->i_op->follow_link(realdentry, nd); > > + if (IS_ERR(ret)) { > > + kfree(data); > > + return ret; > > } > > + > > + if (data) >=20 > No need to check again(see the above kfree(data) please). kfree(NULL) is perfectly valid. NeilBrown >=20 > > + data->cookie =3D ret; > > + > > + return data; > > } > >=20 > > static void ovl_put_link(struct dentry *dentry, struct nameidata *nd, = void *c) > > -- > > 2.1.4 --Sig_/y6r_LzQJvyxdkLxI6qmsTJa Content-Type: application/pgp-signature Content-Description: OpenPGP digital signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v2 iQIVAwUBVUiAfznsnt1WYoG5AQLk5BAAsrCs37kdr8hYx0OmbPO+ppcdov+GMsAg 9P5Nrigx7SFBNbDhxgEAAtC3IpWKe/w8yMnuAYEtOG8KzlLY3s1oE1uBz660SmGu wjeFrIEXcm26X4+JTLlCJoRh0JqtI31GqrDgNT2CTy0E7SctOi1wBrdEDFFEoO7B 3jNLrhTCt9YCJHuxKpQRRfjMGx3gkwLCqsJB95TkzW9/JrRzCGeOFS1ebKennGIT KneZYc26cLyWFRcBtZMoKde9DyvDBiHJmyjXnkfQhB7dlmap9NZbv2+X2EjmLYM1 SoqzBgwu8BAkx7sZgHOd86LpO4J830/TfOL8wh9OKIUpedc9MNm/+L5hd9870htw HmUsB5JSJwqkab/S0kI9ivgKyiovpPGLjGGdX3tLTVs/m7/QKMeXgo1VqeSWpMGA HZQHBJEWgr/osGy1paJlQ/U1cd+zJDIEu1+WcUCJRL1VWY9+x+xGxQkUo5k8Josa 71BMAy/VBp1R8k44uIU8lG/efzlE7vNuz74rkSJ3sjNSaXQkPPXugidy+OJzFaYI zxzlKuqotdcQIVQhFeciAQzEaLMeF9kwA+zJAVTqV/DXbwZYNm6CC73Lb/ZgSqo6 cFRh8o3HI53jUmRFu27CU7Njo/pQS11AZEvqycGh91g2QOricVFbr9XEZ3PvFRqK szfthuLue6w= =ZN7l -----END PGP SIGNATURE----- --Sig_/y6r_LzQJvyxdkLxI6qmsTJa-- -- 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/