[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20240902080417.427993-2-toolmanp@tlmp.cc>
Date: Mon, 2 Sep 2024 16:04:16 +0800
From: Yiyang Wu <toolmanp@...p.cc>
To: hsiangkao@...ux.alibaba.com
Cc: linux-erofs@...ts.ozlabs.org,
linux-kernel@...r.kernel.org,
Yiyang Wu <toolmanp@...p.cc>,
Al Viro <viro@...iv.linux.org.uk>
Subject: [PATCH V3 1/2] erofs: use kmemdup_nul in erofs_fill_symlink
Remove open coding in erofs_fill_symlink.
Suggested-by: Al Viro <viro@...iv.linux.org.uk>
Link: https://lore.kernel.org/all/20240425222847.GN2118490@ZenIV
Signed-off-by: Yiyang Wu <toolmanp@...p.cc>
---
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 = EROFS_I(inode);
unsigned int bsz = i_blocksize(inode);
- char *lnk;
/* if it cannot be handled with fast symlink scheme */
if (vi->datalayout != EROFS_INODE_FLAT_INLINE ||
@@ -188,24 +187,19 @@ static int erofs_fill_symlink(struct inode *inode, void *kaddr,
return 0;
}
- lnk = kmalloc(inode->i_size + 1, GFP_KERNEL);
- if (!lnk)
- return -ENOMEM;
-
m_pofs += 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] = '\0';
+
+ inode->i_link = kmemdup_nul(kaddr + m_pofs, inode->i_size, GFP_KERNEL);
+ if (!inode->i_link)
+ return -ENOMEM;
- inode->i_link = lnk;
inode->i_op = &erofs_fast_symlink_iops;
return 0;
}
--
2.46.0
Powered by blists - more mailing lists