diff mbox series

xfs: use kvmemdup() to replace kvmalloc + memcpy

Message ID 1a12a05451a1fc9bc37e739a79a0ba667656ade4.1735267151.git.xiaopei01@kylinos.cn (mailing list archive)
State New
Headers show
Series xfs: use kvmemdup() to replace kvmalloc + memcpy | expand

Commit Message

Pei Xiao Dec. 27, 2024, 2:53 a.m. UTC
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 mbox series

Patch

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);