From nobody Fri Dec 19 08:56:19 2025 Received: from mail.tlmp.cc (unknown [148.135.17.20]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6BD84186E32 for ; Mon, 2 Sep 2024 08:31:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=148.135.17.20 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725265920; cv=none; b=RJ1WYkeEm3e4ly+J/R10pLXPoWHJUi4iba7tFqgiIwSlsjIxzeaNlHTy7nc9+iOkc6kt6B32/FSmJDas9kSulityPhAzqKAsENpBGnRX8P+7BWnQWV13oI/u5nKH9QyvX1fGnKMCS+FJFlta5IQf2x4wcFGuta9nolLA0nVeqRU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725265920; c=relaxed/simple; bh=ow+4SDCxIVP7wXCPLjVIbOF8vjB9uJiyQMv5eVxiyUA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Lb60/EMC+WVfFCpZWUqc/D9YbYBgz4l6RWTrQZMP+eChe5Q44rz+ey+myUxiclJ5GMJmGw9o5PuN2kIBsL/XWDbIAnputrv2W4ilrqQ7mWUS0piE/eUq+kDEwg8uodMpHYAZ0D0H/pz0xzAYN0t0Yw04hKT5gVwye3TlGnckpqE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=tlmp.cc; spf=pass smtp.mailfrom=tlmp.cc; dkim=pass (2048-bit key) header.d=tlmp.cc header.i=@tlmp.cc header.b=OOZ72e7c; arc=none smtp.client-ip=148.135.17.20 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=tlmp.cc Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=tlmp.cc Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=tlmp.cc header.i=@tlmp.cc header.b="OOZ72e7c" Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id 9073B69905; Mon, 2 Sep 2024 04:31:53 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tlmp.cc; s=dkim; t=1725265917; h=from:subject:date:message-id:to:cc:mime-version: content-transfer-encoding:in-reply-to:references; bh=64kmKEU0tXhYV2/T9ubIckI1K+ZPFKC6qQYZpIf0Twk=; b=OOZ72e7cFDgwNfu4uNlpwiwQk4L75e6RvGKd5aCs2xXjaT9NU87UatWDF/mP8ZjeW1pHTx uycGp4OYNBlwKPei4zbrqatgDFu2o+hf13Yk3J6s+8s92Gs9r5Hvo9DRec5t27SoUqZVZx MSq8HBLFqwSGhD+ZFMf1HqTBGXpEjTh+hZiKFz8+MyKGe4FkmiikSW58fbwS3DsblI2+eO l1vpLdBJUame8RmM777lJCgexC9XG/xbQ526iuCBXY7Pvjklm3rqY1Jq8aGLw8GSbrTaFP SSTOGVYcx+LjD+BG60M2Q+GZas2xbY9OUT11TjA6DnC2E6/ZaDPBtQQvMWN/3Q== From: Yiyang Wu To: hsiangkao@linux.alibaba.com Cc: linux-erofs@lists.ozlabs.org, linux-kernel@vger.kernel.org, Al Viro Subject: [PATCH V4 1/2] erofs: use kmemdup_nul in erofs_fill_symlink Date: Mon, 2 Sep 2024 16:31:46 +0800 Message-ID: <20240902083147.450558-2-toolmanp@tlmp.cc> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240902083147.450558-1-toolmanp@tlmp.cc> References: <20240902083147.450558-1-toolmanp@tlmp.cc> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Last-TLS-Session-Version: TLSv1.3 Content-Type: text/plain; charset="utf-8" Remove open coding in erofs_fill_symlink. Suggested-by: Al Viro Link: https://lore.kernel.org/all/20240425222847.GN2118490@ZenIV Signed-off-by: Yiyang Wu Reviewed-by: Chao Yu Reviewed-by: Gao Xiang --- fs/erofs/inode.c | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/fs/erofs/inode.c b/fs/erofs/inode.c index 419432be3223..40d3f4921d81 100644 --- a/fs/erofs/inode.c +++ b/fs/erofs/inode.c @@ -179,7 +179,6 @@ static int erofs_fill_symlink(struct inode *inode, void= *kaddr, { struct erofs_inode *vi =3D EROFS_I(inode); unsigned int bsz =3D i_blocksize(inode); - char *lnk; =20 /* if it cannot be handled with fast symlink scheme */ if (vi->datalayout !=3D EROFS_INODE_FLAT_INLINE || @@ -188,24 +187,19 @@ static int erofs_fill_symlink(struct inode *inode, vo= id *kaddr, return 0; } =20 - lnk =3D kmalloc(inode->i_size + 1, GFP_KERNEL); - if (!lnk) - return -ENOMEM; - m_pofs +=3D vi->xattr_isize; /* inline symlink data shouldn't cross block boundary */ if (m_pofs + inode->i_size > bsz) { - kfree(lnk); - erofs_err(inode->i_sb, - "inline data cross block boundary @ nid %llu", + erofs_err(inode->i_sb, "inline data cross block boundary @ nid %llu", vi->nid); DBG_BUGON(1); return -EFSCORRUPTED; } - memcpy(lnk, kaddr + m_pofs, inode->i_size); - lnk[inode->i_size] =3D '\0'; +=09 + inode->i_link =3D kmemdup_nul(kaddr + m_pofs, inode->i_size, GFP_KERNEL); + if (!inode->i_link) + return -ENOMEM; =20 - inode->i_link =3D lnk; inode->i_op =3D &erofs_fast_symlink_iops; return 0; } --=20 2.46.0 From nobody Fri Dec 19 08:56:19 2025 Received: from mail.tlmp.cc (unknown [148.135.17.20]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7EF30186E3C for ; Mon, 2 Sep 2024 08:32:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=148.135.17.20 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725265923; cv=none; b=iDgiPVedZHFdstYxMps4gQwW38eTaoAxNsRnVZOU6OHt5cghDckUVkVA/Ja406Y2Mpj+PhK+ghqqlauMyDzq4X8+ueYY27/O2zwNcRbRJQktPuEDzSg0yV1gwkeRYeA3FuDeVYEAd2UYJ7g6lFPKvFx/tmvzAyhCdLt2OdOJvuo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725265923; c=relaxed/simple; bh=xnx2PRXMgDxbKZFEDeXCEeQ7X0yvH0Bb5aqn+u+vLEk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=aMNDCitjlUiFJxeIVJ6yG+aX586gVnEqel8M8FHkOmZWNeiJeXeKZFJETWoIeJohcta15+Wv0hHRZa/nj92ZSC1ce3+B/7MoWL2WtzXQr/VjXnxQQ3vfQcG0Cvv3ozzoAbC5RQT2zv3JUVVNXyJlsv2nUoMZCetGc8XgFTT2kTg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=tlmp.cc; spf=pass smtp.mailfrom=tlmp.cc; dkim=pass (2048-bit key) header.d=tlmp.cc header.i=@tlmp.cc header.b=dmTCNU95; arc=none smtp.client-ip=148.135.17.20 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=tlmp.cc Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=tlmp.cc Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=tlmp.cc header.i=@tlmp.cc header.b="dmTCNU95" Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id 3B0A569838; Mon, 2 Sep 2024 04:31:59 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tlmp.cc; s=dkim; t=1725265920; h=from:subject:date:message-id:to:cc:mime-version: content-transfer-encoding:in-reply-to:references; bh=QflOoS24gJjllSsBpAvZd6hkUmrfZHaYXPMALnugQBE=; b=dmTCNU95fKaOMqQFiVUgLJNx1MUHwrgEaErpsA6y6dBQsj82O3h69Bn4sp2rfwn21x4JyB I+f/SDwQtpyNfwvgvPU9S978k7B7kvuGbL/E3/S6F8sXMVAr+UsEtn1KmiLrmNda3TWlTR FRjmyAvWhfo1/SNz9Zi4sVIDI6B9QrquYrDqc/SmvKvGnnjKnTxOqrK6GpxcW5ifWG3S5U YccAVJmQcA3uaiJ710CF72+VyPcFhFZks6xf/c8hKl3v7kCSxyFPCgkgwDl6/G2+ArQ+ex rYvZKLLbTbVsLmZsoZ0s6/qBjMbz4t4n18qIYeAJder1NCTn5yL9vBHvzGNXOA== From: Yiyang Wu To: hsiangkao@linux.alibaba.com Cc: linux-erofs@lists.ozlabs.org, linux-kernel@vger.kernel.org, Al Viro Subject: [PATCH V4 2/2] erofs: refactor read_inode calling convention Date: Mon, 2 Sep 2024 16:31:47 +0800 Message-ID: <20240902083147.450558-3-toolmanp@tlmp.cc> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240902083147.450558-1-toolmanp@tlmp.cc> References: <20240902083147.450558-1-toolmanp@tlmp.cc> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Last-TLS-Session-Version: TLSv1.3 Content-Type: text/plain; charset="utf-8" Refactor out the iop binding behavior out of the erofs_fill_symlink and move erofs_buf into the erofs_read_inode, so that erofs_fill_inode can only deal with inode operation bindings and can be decoupled from metabuf operations. This results in better calling conventions. Note that after this patch, we do not need erofs_buf and ofs as parameters any more when calling erofs_read_inode as all the data operations are now included in itself. Suggested-by: Al Viro Link: https://lore.kernel.org/all/20240425222847.GN2118490@ZenIV/ Signed-off-by: Yiyang Wu --- fs/erofs/inode.c | 127 +++++++++++++++++++++++------------------------ 1 file changed, 61 insertions(+), 66 deletions(-) diff --git a/fs/erofs/inode.c b/fs/erofs/inode.c index 40d3f4921d81..ae11af82e2ec 100644 --- a/fs/erofs/inode.c +++ b/fs/erofs/inode.c @@ -8,8 +8,33 @@ =20 #include =20 -static void *erofs_read_inode(struct erofs_buf *buf, - struct inode *inode, unsigned int *ofs) +static int erofs_fill_symlink(struct inode *inode, void *kaddr, + unsigned int m_pofs) +{ + struct erofs_inode *vi =3D EROFS_I(inode); + unsigned int bsz =3D i_blocksize(inode); + + /* if it cannot be handled with fast symlink scheme */ + if (vi->datalayout !=3D EROFS_INODE_FLAT_INLINE || + inode->i_size >=3D bsz || inode->i_size < 0) { + return 0; + } + + m_pofs +=3D vi->xattr_isize; + /* inline symlink data shouldn't cross block boundary */ + if (m_pofs + inode->i_size > bsz) { + erofs_err(inode->i_sb, "inline data cross block boundary @ nid %llu", + vi->nid); + DBG_BUGON(1); + return -EFSCORRUPTED; + } + + inode->i_link =3D kmemdup_nul(kaddr + m_pofs, inode->i_size, GFP_KERNEL); + + return inode->i_link ? 0 : -ENOMEM; +} + +static int erofs_read_inode(struct inode *inode) { struct super_block *sb =3D inode->i_sb; struct erofs_sb_info *sbi =3D EROFS_SB(sb); @@ -20,20 +45,21 @@ static void *erofs_read_inode(struct erofs_buf *buf, struct erofs_inode_compact *dic; struct erofs_inode_extended *die, *copied =3D NULL; union erofs_inode_i_u iu; - unsigned int ifmt; - int err; + struct erofs_buf buf =3D __EROFS_BUF_INITIALIZER; + unsigned int ifmt, ofs; + int err =3D 0; =20 blkaddr =3D erofs_blknr(sb, inode_loc); - *ofs =3D erofs_blkoff(sb, inode_loc); + ofs =3D erofs_blkoff(sb, inode_loc); =20 - kaddr =3D erofs_read_metabuf(buf, sb, erofs_pos(sb, blkaddr), EROFS_KMAP); + kaddr =3D erofs_read_metabuf(&buf, sb, erofs_pos(sb, blkaddr), EROFS_KMAP= ); if (IS_ERR(kaddr)) { erofs_err(sb, "failed to get inode (nid: %llu) page, err %ld", vi->nid, PTR_ERR(kaddr)); - return kaddr; + return PTR_ERR(kaddr); } =20 - dic =3D kaddr + *ofs; + dic =3D kaddr + ofs; ifmt =3D le16_to_cpu(dic->i_format); if (ifmt & ~EROFS_I_ALL) { erofs_err(sb, "unsupported i_format %u of nid %llu", @@ -54,11 +80,11 @@ static void *erofs_read_inode(struct erofs_buf *buf, case EROFS_INODE_LAYOUT_EXTENDED: 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) { - *ofs +=3D vi->inode_isize; + if (ofs + vi->inode_isize <=3D sb->s_blocksize) { + ofs +=3D vi->inode_isize; die =3D (struct erofs_inode_extended *)dic; } else { - const unsigned int gotten =3D sb->s_blocksize - *ofs; + const unsigned int gotten =3D sb->s_blocksize - ofs; =20 copied =3D kmalloc(vi->inode_isize, GFP_KERNEL); if (!copied) { @@ -66,16 +92,16 @@ static void *erofs_read_inode(struct erofs_buf *buf, goto err_out; } memcpy(copied, dic, gotten); - kaddr =3D erofs_read_metabuf(buf, sb, erofs_pos(sb, blkaddr + 1), + kaddr =3D erofs_read_metabuf(&buf, sb, erofs_pos(sb, blkaddr + 1), EROFS_KMAP); if (IS_ERR(kaddr)) { erofs_err(sb, "failed to get inode payload block (nid: %llu), err %ld", vi->nid, PTR_ERR(kaddr)); kfree(copied); - return kaddr; + return PTR_ERR(kaddr); } - *ofs =3D vi->inode_isize - gotten; - memcpy((u8 *)copied + gotten, kaddr, *ofs); + ofs =3D vi->inode_isize - gotten; + memcpy((u8 *)copied + gotten, kaddr, ofs); die =3D copied; } vi->xattr_isize =3D erofs_xattr_ibody_size(die->i_xattr_icount); @@ -91,11 +117,10 @@ static void *erofs_read_inode(struct erofs_buf *buf, =20 inode->i_size =3D le64_to_cpu(die->i_size); kfree(copied); - copied =3D NULL; break; case EROFS_INODE_LAYOUT_COMPACT: vi->inode_isize =3D sizeof(struct erofs_inode_compact); - *ofs +=3D vi->inode_isize; + ofs +=3D vi->inode_isize; vi->xattr_isize =3D erofs_xattr_ibody_size(dic->i_xattr_icount); =20 inode->i_mode =3D le16_to_cpu(dic->i_mode); @@ -119,6 +144,11 @@ static void *erofs_read_inode(struct erofs_buf *buf, case S_IFREG: case S_IFDIR: case S_IFLNK: + if(S_ISLNK(inode->i_mode)) { + err =3D erofs_fill_symlink(inode, kaddr, ofs); + if (err) + goto err_out; + } vi->raw_blkaddr =3D le32_to_cpu(iu.raw_blkaddr); break; case S_IFCHR: @@ -165,59 +195,24 @@ static void *erofs_read_inode(struct erofs_buf *buf, inode->i_blocks =3D round_up(inode->i_size, sb->s_blocksize) >> 9; else inode->i_blocks =3D nblks << (sb->s_blocksize_bits - 9); - return kaddr; =20 err_out: - DBG_BUGON(1); - kfree(copied); - erofs_put_metabuf(buf); - return ERR_PTR(err); -} - -static int erofs_fill_symlink(struct inode *inode, void *kaddr, - unsigned int m_pofs) -{ - struct erofs_inode *vi =3D EROFS_I(inode); - unsigned int bsz =3D i_blocksize(inode); - - /* if it cannot be handled with fast symlink scheme */ - if (vi->datalayout !=3D EROFS_INODE_FLAT_INLINE || - inode->i_size >=3D bsz || inode->i_size < 0) { - inode->i_op =3D &erofs_symlink_iops; - return 0; - } - - m_pofs +=3D vi->xattr_isize; - /* inline symlink data shouldn't cross block boundary */ - if (m_pofs + inode->i_size > bsz) { - erofs_err(inode->i_sb, "inline data cross block boundary @ nid %llu", - vi->nid); - DBG_BUGON(1); - return -EFSCORRUPTED; - } -=09 - inode->i_link =3D kmemdup_nul(kaddr + m_pofs, inode->i_size, GFP_KERNEL); - if (!inode->i_link) - return -ENOMEM; - - inode->i_op =3D &erofs_fast_symlink_iops; - return 0; + DBG_BUGON(err); + erofs_put_metabuf(&buf); + return err; } =20 static int erofs_fill_inode(struct inode *inode) { struct erofs_inode *vi =3D EROFS_I(inode); - struct erofs_buf buf =3D __EROFS_BUF_INITIALIZER; - void *kaddr; - unsigned int ofs; int err =3D 0; =20 trace_erofs_fill_inode(inode); =20 /* read inode base data from disk */ - kaddr =3D erofs_read_inode(&buf, inode, &ofs); - if (IS_ERR(kaddr)) - return PTR_ERR(kaddr); + err =3D erofs_read_inode(inode); + if (err) + return err; =20 /* setup the new inode */ switch (inode->i_mode & S_IFMT) { @@ -234,9 +229,11 @@ static int erofs_fill_inode(struct inode *inode) inode_nohighmem(inode); break; case S_IFLNK: - err =3D erofs_fill_symlink(inode, kaddr, ofs); - if (err) - goto out_unlock; + if (inode->i_link) + inode->i_op =3D &erofs_fast_symlink_iops; + else + inode->i_op =3D &erofs_symlink_iops; + inode_nohighmem(inode); break; case S_IFCHR: @@ -245,10 +242,9 @@ static int erofs_fill_inode(struct inode *inode) case S_IFSOCK: inode->i_op =3D &erofs_generic_iops; init_special_inode(inode, inode->i_mode, inode->i_rdev); - goto out_unlock; + return 0; default: - err =3D -EFSCORRUPTED; - goto out_unlock; + return -EFSCORRUPTED; } =20 mapping_set_large_folios(inode->i_mapping); @@ -268,8 +264,7 @@ static int erofs_fill_inode(struct inode *inode) inode->i_mapping->a_ops =3D &erofs_fscache_access_aops; #endif } -out_unlock: - erofs_put_metabuf(&buf); + return err; } =20 --=20 2.46.0