[PATCH] xfs: use kvmemdup() to replace kvmalloc + memcpy

Pei Xiao posted 1 patch 1 year, 1 month ago
fs/xfs/libxfs/xfs_attr_leaf.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
[PATCH] xfs: use kvmemdup() to replace kvmalloc + memcpy
Posted by Pei Xiao 1 year, 1 month ago
Fix cocci warning:
fs/xfs/libxfs/xfs_attr_leaf.c:1061:13-20: WARNING opportunity for kmemdup

Fixes: de631e1a8b71 ("xfs: use kvmalloc for xattr buffers")
Reported-by: kernel test robot <lkp@intel.com>
Closes: https://lore.kernel.org/oe-kbuild-all/202403210204.LPPBJMhf-lkp@intel.com/
Signed-off-by: Pei Xiao <xiaopei01@kylinos.cn>
---
 fs/xfs/libxfs/xfs_attr_leaf.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/fs/xfs/libxfs/xfs_attr_leaf.c b/fs/xfs/libxfs/xfs_attr_leaf.c
index fddb55605e0c..db45f22e89d0 100644
--- a/fs/xfs/libxfs/xfs_attr_leaf.c
+++ b/fs/xfs/libxfs/xfs_attr_leaf.c
@@ -1136,8 +1136,9 @@ xfs_attr3_leaf_to_shortform(
 
 	trace_xfs_attr_leaf_to_sf(args);
 
-	tmpbuffer = kvmalloc(args->geo->blksize, GFP_KERNEL | __GFP_NOFAIL);
-	memcpy(tmpbuffer, bp->b_addr, args->geo->blksize);
+	tmpbuffer = kvmemdup(bp->b_addr, args->geo->blksize, GFP_KERNEL | __GFP_NOFAIL);
+	if (!tmpbuffer)
+		return -ENOMEM;
 
 	leaf = (xfs_attr_leafblock_t *)tmpbuffer;
 	xfs_attr3_leaf_hdr_from_disk(args->geo, &ichdr, leaf);
-- 
2.25.1