diff mbox series

xfs: use kmemdup() to replace kmalloc + memcpy

Message ID 37bbe1eb5f72685e54abb1ee6b50eaff788ecd93.1735268963.git.xiaopei01@kylinos.cn (mailing list archive)
State New
Headers show
Series xfs: use kmemdup() to replace kmalloc + memcpy | expand

Commit Message

Pei Xiao Dec. 27, 2024, 3:11 a.m. UTC
cocci warnings:
    fs/xfs/libxfs/xfs_dir2.c:336:15-22: WARNING opportunity for kmemdup

Fixes: 30f712c9dd69 ("libxfs: move source files")
Reported-by: kernel test robot <lkp@intel.com>
Closes: https://lore.kernel.org/oe-kbuild-all/202412260425.O3CDUhIi-lkp@intel.com/
Signed-off-by: Pei Xiao <xiaopei01@kylinos.cn>
---
 fs/xfs/libxfs/xfs_dir2.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

Comments

Carlos Maiolino Jan. 9, 2025, 9:39 a.m. UTC | #1
On Fri, Dec 27, 2024 at 11:11:13AM +0800, Pei Xiao wrote:
> cocci warnings:
>     fs/xfs/libxfs/xfs_dir2.c:336:15-22: WARNING opportunity for kmemdup

https://lore.kernel.org/all/20241217225811.2437150-4-mtodorovac69@gmail.com/

> 
> Fixes: 30f712c9dd69 ("libxfs: move source files")
> Reported-by: kernel test robot <lkp@intel.com>
> Closes: https://lore.kernel.org/oe-kbuild-all/202412260425.O3CDUhIi-lkp@intel.com/
> Signed-off-by: Pei Xiao <xiaopei01@kylinos.cn>
> ---
>  fs/xfs/libxfs/xfs_dir2.c | 3 +--
>  1 file changed, 1 insertion(+), 2 deletions(-)
> 
> diff --git a/fs/xfs/libxfs/xfs_dir2.c b/fs/xfs/libxfs/xfs_dir2.c
> index 202468223bf9..24251e42bdeb 100644
> --- a/fs/xfs/libxfs/xfs_dir2.c
> +++ b/fs/xfs/libxfs/xfs_dir2.c
> @@ -379,12 +379,11 @@ xfs_dir_cilookup_result(
>  					!(args->op_flags & XFS_DA_OP_CILOOKUP))
>  		return -EEXIST;
>  
> -	args->value = kmalloc(len,
> +	args->value = kmemdup(name, len,
>  			GFP_KERNEL | __GFP_NOLOCKDEP | __GFP_RETRY_MAYFAIL);
>  	if (!args->value)
>  		return -ENOMEM;
>  
> -	memcpy(args->value, name, len);
>  	args->valuelen = len;
>  	return -EEXIST;
>  }
> -- 
> 2.25.1
> 
>
Pei Xiao Jan. 9, 2025, 9:43 a.m. UTC | #2
在 2025/1/9 17:39, Carlos Maiolino 写道:
> On Fri, Dec 27, 2024 at 11:11:13AM +0800, Pei Xiao wrote:
>> cocci warnings:
>>     fs/xfs/libxfs/xfs_dir2.c:336:15-22: WARNING opportunity for kmemdup
> https://lore.kernel.org/all/20241217225811.2437150-4-mtodorovac69@gmail.com/

ok,thank you, I didn't realize it was a duplicate commit.

>> Fixes: 30f712c9dd69 ("libxfs: move source files")
>> Reported-by: kernel test robot <lkp@intel.com>
>> Closes: https://lore.kernel.org/oe-kbuild-all/202412260425.O3CDUhIi-lkp@intel.com/
>> Signed-off-by: Pei Xiao <xiaopei01@kylinos.cn>
>> ---
>>  fs/xfs/libxfs/xfs_dir2.c | 3 +--
>>  1 file changed, 1 insertion(+), 2 deletions(-)
>>
>> diff --git a/fs/xfs/libxfs/xfs_dir2.c b/fs/xfs/libxfs/xfs_dir2.c
>> index 202468223bf9..24251e42bdeb 100644
>> --- a/fs/xfs/libxfs/xfs_dir2.c
>> +++ b/fs/xfs/libxfs/xfs_dir2.c
>> @@ -379,12 +379,11 @@ xfs_dir_cilookup_result(
>>  					!(args->op_flags & XFS_DA_OP_CILOOKUP))
>>  		return -EEXIST;
>>  
>> -	args->value = kmalloc(len,
>> +	args->value = kmemdup(name, len,
>>  			GFP_KERNEL | __GFP_NOLOCKDEP | __GFP_RETRY_MAYFAIL);
>>  	if (!args->value)
>>  		return -ENOMEM;
>>  
>> -	memcpy(args->value, name, len);
>>  	args->valuelen = len;
>>  	return -EEXIST;
>>  }
>> -- 
>> 2.25.1
>>
>>
diff mbox series

Patch

diff --git a/fs/xfs/libxfs/xfs_dir2.c b/fs/xfs/libxfs/xfs_dir2.c
index 202468223bf9..24251e42bdeb 100644
--- a/fs/xfs/libxfs/xfs_dir2.c
+++ b/fs/xfs/libxfs/xfs_dir2.c
@@ -379,12 +379,11 @@  xfs_dir_cilookup_result(
 					!(args->op_flags & XFS_DA_OP_CILOOKUP))
 		return -EEXIST;
 
-	args->value = kmalloc(len,
+	args->value = kmemdup(name, len,
 			GFP_KERNEL | __GFP_NOLOCKDEP | __GFP_RETRY_MAYFAIL);
 	if (!args->value)
 		return -ENOMEM;
 
-	memcpy(args->value, name, len);
 	args->valuelen = len;
 	return -EEXIST;
 }