From nobody Tue Dec 30 22:51:31 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9785EC4332F for ; Thu, 9 Nov 2023 11:53:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233907AbjKILxs (ORCPT ); Thu, 9 Nov 2023 06:53:48 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58718 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231964AbjKILxq (ORCPT ); Thu, 9 Nov 2023 06:53:46 -0500 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D418C211F for ; Thu, 9 Nov 2023 03:53:43 -0800 (PST) Received: from dggpemm500020.china.huawei.com (unknown [172.30.72.53]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4SR0dK0KNgzmXH1; Thu, 9 Nov 2023 19:50:29 +0800 (CST) Received: from localhost.localdomain (10.175.104.67) by dggpemm500020.china.huawei.com (7.185.36.49) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.31; Thu, 9 Nov 2023 19:53:41 +0800 From: WoZ1zh1 To: , CC: , , , Subject: [PATCH -next V2] erofs: code clean up for function erofs_read_inode() Date: Fri, 10 Nov 2023 03:48:21 +0800 Message-ID: <20231109194821.1719430-1-wozizhi@huawei.com> X-Mailer: git-send-email 2.39.2 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.175.104.67] X-ClientProxiedBy: dggems704-chm.china.huawei.com (10.3.19.181) To dggpemm500020.china.huawei.com (7.185.36.49) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Because variables "die" and "copied" only appear in case EROFS_INODE_LAYOUT_EXTENDED, move them from the outer space into this case. Also, call "kfree(copied)" earlier to avoid double free in the "error_out" branch. Some cleanups, no logic changes. Signed-off-by: WoZ1zh1 --- fs/erofs/inode.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/fs/erofs/inode.c b/fs/erofs/inode.c index b8ad05b4509d..a388c93eec34 100644 --- a/fs/erofs/inode.c +++ b/fs/erofs/inode.c @@ -19,7 +19,6 @@ static void *erofs_read_inode(struct erofs_buf *buf, erofs_blk_t blkaddr, nblks =3D 0; void *kaddr; struct erofs_inode_compact *dic; - struct erofs_inode_extended *die, *copied =3D NULL; unsigned int ifmt; int err; =20 @@ -53,6 +52,8 @@ static void *erofs_read_inode(struct erofs_buf *buf, =20 switch (erofs_inode_version(ifmt)) { case EROFS_INODE_LAYOUT_EXTENDED: + struct erofs_inode_extended *die, *copied =3D NULL; + vi->inode_isize =3D sizeof(struct erofs_inode_extended); /* check if the extended inode acrosses block boundary */ if (*ofs + vi->inode_isize <=3D sb->s_blocksize) { @@ -98,6 +99,7 @@ static void *erofs_read_inode(struct erofs_buf *buf, inode->i_rdev =3D 0; break; default: + kfree(copied); goto bogusimode; } i_uid_write(inode, le32_to_cpu(die->i_uid)); @@ -117,7 +119,6 @@ static void *erofs_read_inode(struct erofs_buf *buf, /* fill chunked inode summary info */ vi->chunkformat =3D le16_to_cpu(die->i_u.c.format); kfree(copied); - copied =3D NULL; break; case EROFS_INODE_LAYOUT_COMPACT: vi->inode_isize =3D sizeof(struct erofs_inode_compact); @@ -197,7 +198,6 @@ static void *erofs_read_inode(struct erofs_buf *buf, err =3D -EFSCORRUPTED; err_out: DBG_BUGON(1); - kfree(copied); erofs_put_metabuf(buf); return ERR_PTR(err); } --=20 2.39.2