drm/admgpu: replace kmalloc() and memcpy() with kmemdup()
PATCH 1/3 drm/admgpu: replace kmalloc() and memcpy() with kmemdup()
The static analyser tool gave the following advice:
./drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c:1266:7-14: WARNING opportunity for kmemdup
→ 1266 tmp = kmalloc(used_size, GFP_KERNEL);
1267 if (!tmp)
1268 return -ENOMEM;
1269
→ 1270 memcpy(tmp, &host_telemetry->body.error_count, used_size);
Replacing kmalloc() + memcpy() with kmemdump() doesn't change semantics. Original code works without fault, so this is not a bug fix but proposed improvement.
---
v1:
initial version.
drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c +1 -3
@@ -1263,12 +1263,10 @@ static int amdgpu_virt_cache_host_error_counts(struct amdgpu_device *adev,if (used_size > (AMD_SRIOV_RAS_TELEMETRY_SIZE_KB <<10 ))return 0 ; - tmp =kmalloc (used_size,GFP_KERNEL ); + tmp =kmemdup (&host_telemetry->body.error_count, used_size,GFP_KERNEL );if (!tmp)return -ENOMEM ; -memcpy (tmp, &host_telemetry->body.error_count, used_size); -if (checksum !=amd_sriov_msg_checksum (tmp, used_size,0 ,0 )) goto out;
Signature · 1 line
2.43.0
PATCH 2/3 xfs/libxfs: replace kmalloc() and memcpy() with kmemdup()
The source static analysis tool gave the following advice:
./fs/xfs/libxfs/xfs_dir2.c:382:15-22: WARNING opportunity for kmemdup
→ 382 args->value = kmalloc(len,
383 GFP_KERNEL | __GFP_NOLOCKDEP | __GFP_RETRY_MAYFAIL);
384 if (!args->value)
385 return -ENOMEM;
386
→ 387 memcpy(args->value, name, len);
388 args->valuelen = len;
389 return -EEXIST;
Replacing kmalloc() + memcpy() with kmemdump() doesn't change semantics. Original code works without fault, so this is not a bug fix but proposed improvement.
---
v1:
initial version.
fs/xfs/libxfs/xfs_dir2.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
fs/xfs/libxfs/xfs_dir2.c +1 -2
@@ -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 ; }
Signature · 1 line
2.43.0
Re: [PATCH v1 2/3] xfs/libxfs: replace kmalloc() and memcpy() with kmemdup()
Quoted 13 lines · Mirsad Todorovac
The source static analysis tool gave the following advice:
./fs/xfs/libxfs/xfs_dir2.c:382:15-22: WARNING opportunity for kmemdup
→ 382
args->value= kmalloc(len,383 GFP_KERNEL | __GFP_NOLOCKDEP | __GFP_RETRY_MAYFAIL); 384 if (!args->value) 385 return -ENOMEM; 386 → 387 memcpy(args->value, name, len); 388 args->valuelen = len; 389 return -EEXIST;
Quoted 2 lines
Replacing
kmalloc()+memcpy()withkmemdump()doesn't change semantics. Original code works without fault, so this is not a bug fix but proposed improvement.
I guess this is all right, but seeing as this code is shared with userspace ("libxfs"), making this change will just add to the wrappers that we have to have:
void *kmemdup_noprof(const void *src, size_t len, gfp_t gfp)
{
void *p;
p = kmalloc_node_track_caller_noprof(len, gfp, NUMA_NO_NODE, _RET_IP_);
if (p)
memcpy(p, src, len);
return p;
}Is this sufficiently better? That's a question for the kernel maintainer (cem) and the userspace maintainer (andrey, now cc'd).
--D
Quoted 40 lines
Fixes 94a69db2367ef ("xfs: use __GFP_NOLOCKDEP instead of GFP_NOFS")Fixes 384f3ced07efd ("[XFS] Return case-insensitive match for dentry cache")Fixes 2451337dd0439 ("xfs: global error sign conversion")Cc Carlos Maiolino <[email protected]>Cc "Darrick J. Wong" <[email protected]>Cc Chandan Babu R <[email protected]>Cc Dave Chinner <[email protected]>Signed-off-by Mirsad Todorovac <[email protected]>---
v1:
initial version.fs/xfs/libxfs/xfs_dir2.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)fs/xfs/libxfs/xfs_dir2.c +1
-2@@ -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 ; }Signature · 1 line
2.43.0
Re: [PATCH v1 2/3] xfs/libxfs: replace kmalloc() and memcpy() with kmemdup()
Quoted 31 lines · Darrick J. Wong
Quoted 13 lines · Mirsad Todorovac
The source static analysis tool gave the following advice:
./fs/xfs/libxfs/xfs_dir2.c:382:15-22: WARNING opportunity for kmemdup
→ 382
args->value= kmalloc(len,383 GFP_KERNEL | __GFP_NOLOCKDEP | __GFP_RETRY_MAYFAIL); 384 if (!args->value) 385 return -ENOMEM; 386 → 387 memcpy(args->value, name, len); 388 args->valuelen = len; 389 return -EEXIST;Quoted 2 lines
Replacing
kmalloc()+memcpy()withkmemdump()doesn't change semantics. Original code works without fault, so this is not a bug fix but proposed improvement.I guess this is all right, but seeing as this code is shared with userspace ("libxfs"), making this change will just add to the wrappers that we have to have:
void *kmemdup_noprof(const void *src,
size_tlen,gfp_tgfp){ void *p; p = kmalloc_node_track_caller_noprof(len, gfp, NUMA_NO_NODE, _RET_IP_); if (p) memcpy(p, src, len); return p; }
Quoted 4 lines
Is this sufficiently better? That's a question for the kernel maintainer (cem) and the userspace maintainer (andrey, now cc'd).
--D
There's still possibility to set wrong length in args->valuelen, which I suppose what this change tries to prevent.
But otherwise wrapper looks good to me
Quoted 42 lines
Quoted 41 lines
Fixes 94a69db2367ef ("xfs: use __GFP_NOLOCKDEP instead of GFP_NOFS")Fixes 384f3ced07efd ("[XFS] Return case-insensitive match for dentry cache")Fixes 2451337dd0439 ("xfs: global error sign conversion")Cc Carlos Maiolino <[email protected]>Cc "Darrick J. Wong" <[email protected]>Cc Chandan Babu R <[email protected]>Cc Dave Chinner <[email protected]>Signed-off-by Mirsad Todorovac <[email protected]>---
v1:
initial version.fs/xfs/libxfs/xfs_dir2.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)fs/xfs/libxfs/xfs_dir2.c +1
-2@@ -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 ; }Signature · 1 line
2.43.0
Signature · 1 line
- Andrey
Darrick J. Wong
Reviewed-byRe: [PATCH v1 2/3] xfs/libxfs: replace kmalloc() and memcpy() with kmemdup()
Quoted 35 lines · Andrey Albershteyn
Quoted 34 lines · Darrick J. Wong
Quoted 13 lines · Mirsad Todorovac
The source static analysis tool gave the following advice:
./fs/xfs/libxfs/xfs_dir2.c:382:15-22: WARNING opportunity for kmemdup
→ 382
args->value= kmalloc(len,383 GFP_KERNEL | __GFP_NOLOCKDEP | __GFP_RETRY_MAYFAIL); 384 if (!args->value) 385 return -ENOMEM; 386 → 387 memcpy(args->value, name, len); 388 args->valuelen = len; 389 return -EEXIST;Quoted 2 lines
Replacing
kmalloc()+memcpy()withkmemdump()doesn't change semantics. Original code works without fault, so this is not a bug fix but proposed improvement.I guess this is all right, but seeing as this code is shared with userspace ("libxfs"), making this change will just add to the wrappers that we have to have:
void *kmemdup_noprof(const void *src,
size_tlen,gfp_tgfp){ void *p; p = kmalloc_node_track_caller_noprof(len, gfp, NUMA_NO_NODE, _RET_IP_); if (p) memcpy(p, src, len); return p; }Is this sufficiently better? That's a question for the kernel maintainer (cem) and the userspace maintainer (andrey, now cc'd).
Quoted 6 lines
Quoted 1 line
--D
There's still possibility to set wrong length in
args->valuelen, which I suppose what this change tries to prevent.But otherwise wrapper looks good to me
Ok, proceed then.
--D
Quoted 47 lines
Quoted 42 lines
Quoted 41 lines
Fixes 94a69db2367ef ("xfs: use __GFP_NOLOCKDEP instead of GFP_NOFS")Fixes 384f3ced07efd ("[XFS] Return case-insensitive match for dentry cache")Fixes 2451337dd0439 ("xfs: global error sign conversion")Cc Carlos Maiolino <[email protected]>Cc "Darrick J. Wong" <[email protected]>Cc Chandan Babu R <[email protected]>Cc Dave Chinner <[email protected]>Signed-off-by Mirsad Todorovac <[email protected]>---
v1:
initial version.fs/xfs/libxfs/xfs_dir2.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)fs/xfs/libxfs/xfs_dir2.c +1
-2@@ -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 ; }Signature · 1 line
2.43.0Signature · 1 line
- Andrey
Carlos Maiolino
maintainerRe: [PATCH v1 2/3] xfs/libxfs: replace kmalloc() and memcpy() with kmemdup()
In reply to Mirsad TodorovacHi Mirsad.
Did you send only this patch, or did I miss patch 1 and 3 of the series? I can't find them anywhere.
Carlos
Quoted 56 lines · Mirsad Todorovac
The source static analysis tool gave the following advice:
./fs/xfs/libxfs/xfs_dir2.c:382:15-22: WARNING opportunity for kmemdup
→ 382
args->value= kmalloc(len,383 GFP_KERNEL | __GFP_NOLOCKDEP | __GFP_RETRY_MAYFAIL); 384 if (!args->value) 385 return -ENOMEM; 386 → 387 memcpy(args->value, name, len); 388 args->valuelen = len; 389 return -EEXIST;Replacing
kmalloc()+memcpy()withkmemdump()doesn't change semantics. Original code works without fault, so this is not a bug fix but proposed improvement.Fixes 94a69db2367ef ("xfs: use __GFP_NOLOCKDEP instead of GFP_NOFS")Fixes 384f3ced07efd ("[XFS] Return case-insensitive match for dentry cache")Fixes 2451337dd0439 ("xfs: global error sign conversion")Cc Carlos Maiolino <[email protected]>Cc "Darrick J. Wong" <[email protected]>Cc Chandan Babu R <[email protected]>Cc Dave Chinner <[email protected]>Signed-off-by Mirsad Todorovac <[email protected]>---
v1:
initial version.fs/xfs/libxfs/xfs_dir2.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)fs/xfs/libxfs/xfs_dir2.c +1
-2@@ -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 ; }Signature · 1 line
2.43.0
Re: [PATCH v1 2/3] xfs/libxfs: replace kmalloc() and memcpy() with kmemdup()
In reply to Mirsad TodorovacQuoted 13 lines · Mirsad Todorovac
The source static analysis tool gave the following advice:
./fs/xfs/libxfs/xfs_dir2.c:382:15-22: WARNING opportunity for kmemdup
→ 382
args->value= kmalloc(len,383 GFP_KERNEL | __GFP_NOLOCKDEP | __GFP_RETRY_MAYFAIL); 384 if (!args->value) 385 return -ENOMEM; 386 → 387 memcpy(args->value, name, len); 388 args->valuelen = len; 389 return -EEXIST;
Quoted 1 line
[...]
Applied to for-next, thanks!
[2/3] xfs/libxfs: replace kmalloc() and memcpy() with kmemdup()
commit: 9d9b72472631262b35157f1a650f066c0e11c2bb
Best regards,
Signature · 1 line
Carlos Maiolino <[email protected]>
PATCH 3/3 btrfs: replace kmalloc() and memcpy() with kmemdup()
In reply to Mirsad TodorovacThe static analyser tool gave the following advice:
./fs/btrfs/ioctl.c:4987:9-16: WARNING opportunity for kmemdup
4986 if (!iov) {
→ 4987 iov = kmalloc(sizeof(struct iovec) * args.iovcnt, GFP_NOFS);
4988 if (!iov) {
4989 unlock_extent(io_tree, start, lockend, &cached_state); 4990 btrfs_inode_unlock(inode, BTRFS_ILOCK_SHARED); 4991 ret = -ENOMEM; 4992 goto out_acct;
4993 }
4994
→ 4995 memcpy(iov, iovstack, sizeof(struct iovec) * args.iovcnt);
4996 }
Replacing kmalloc() + memcpy() with kmemdump() doesn't change semantics. Original code works without fault, so this is not a bug fix but proposed improvement.
---
v1:
initial version.
fs/btrfs/ioctl.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
fs/btrfs/ioctl.c +1 -3
@@ -4984,15 +4984,13 @@ static int btrfs_uring_encoded_read(struct io_uring_cmd *cmd, unsigned int issue* undo this. */ if (!iov) { - iov =kmalloc (sizeof (struct iovec ) * args.iovcnt,GFP_NOFS ); + iov =kmemdup (iovstack,sizeof (struct iovec ) * args.iovcnt,GFP_NOFS );if (!iov) {unlock_extent (io_tree, start, lockend, &cached_state);btrfs_inode_unlock (inode,BTRFS_ILOCK_SHARED ); ret = -ENOMEM ; goto out_acct; } - -memcpy (iov, iovstack,sizeof (struct iovec ) * args.iovcnt); } count =min_t (u64,iov_iter_count (&iter), disk_io_size);
Signature · 1 line
2.43.0
Re: [PATCH v1 3/3] btrfs: replace kmalloc() and memcpy() with kmemdup()
There's a fix for this already in the for-next branch:
https://github.com/btrfs/linux/commit/1a287050962c6847fa4918d6b2a0f4cee35c6943
Quoted 56 lines · Mirsad Todorovac
Quoted 1 line
The static analyser tool gave the following advice:
./fs/btrfs/ioctl.c:4987:9-16: WARNING opportunity for kmemdup
4986 if (!iov) { → 4987 iov = kmalloc(sizeof(struct iovec) * args.iovcnt, GFP_NOFS); 4988 if (!iov) { 4989 unlock_extent(io_tree, start, lockend, &cached_state); 4990 btrfs_inode_unlock(inode, BTRFS_ILOCK_SHARED); 4991 ret = -ENOMEM; 4992 goto out_acct; 4993 } 4994 → 4995 memcpy(iov, iovstack, sizeof(struct iovec) * args.iovcnt); 4996 }Replacing
kmalloc()+memcpy()withkmemdump()doesn't change semantics. Original code works without fault, so this is not a bug fix but proposed improvement.Fixes 34310c442e175 ("btrfs: add io_uring command for encoded reads (ENCODED_READ ioctl)")Cc Chris Mason <[email protected]>Cc Josef Bacik <[email protected]>Cc David Sterba <[email protected]>Signed-off-by Mirsad Todorovac <[email protected]>---
v1:
initial version.fs/btrfs/ioctl.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)fs/btrfs/ioctl.c +1
-3@@ -4984,15 +4984,13 @@ static int btrfs_uring_encoded_read(struct io_uring_cmd *cmd, unsigned int issue* undo this. */ if (!iov) { - iov =kmalloc (sizeof (struct iovec ) * args.iovcnt,GFP_NOFS ); + iov =kmemdup (iovstack,sizeof (struct iovec ) * args.iovcnt,GFP_NOFS );if (!iov) {unlock_extent (io_tree, start, lockend, &cached_state);btrfs_inode_unlock (inode,BTRFS_ILOCK_SHARED ); ret = -ENOMEM ; goto out_acct; } - -memcpy (iov, iovstack,sizeof (struct iovec ) * args.iovcnt); } count =min_t (u64,iov_iter_count (&iter), disk_io_size);
Re: [PATCH v1 3/3] btrfs: replace kmalloc() and memcpy() with kmemdup()
Hi,
Yes, I see you have the prior work and I have duplicated your work.
Apology for the inconvenience.
Best regards,
Mirsad Todorovac
Quoted 61 lines · Mark Harmstone
There's a fix for this already in the for-next branch:
https://github.com/btrfs/linux/commit/1a287050962c6847fa4918d6b2a0f4cee35c6943Quoted 56 lines · Mirsad Todorovac
Quoted 1 line
The static analyser tool gave the following advice:
./fs/btrfs/ioctl.c:4987:9-16: WARNING opportunity for kmemdup
4986 if (!iov) { → 4987 iov = kmalloc(sizeof(struct iovec) * args.iovcnt, GFP_NOFS); 4988 if (!iov) { 4989 unlock_extent(io_tree, start, lockend, &cached_state); 4990 btrfs_inode_unlock(inode, BTRFS_ILOCK_SHARED); 4991 ret = -ENOMEM; 4992 goto out_acct; 4993 } 4994 → 4995 memcpy(iov, iovstack, sizeof(struct iovec) * args.iovcnt); 4996 }Replacing
kmalloc()+memcpy()withkmemdump()doesn't change semantics. Original code works without fault, so this is not a bug fix but proposed improvement.Fixes 34310c442e175 ("btrfs: add io_uring command for encoded reads (ENCODED_READ ioctl)")Cc Chris Mason <[email protected]>Cc Josef Bacik <[email protected]>Cc David Sterba <[email protected]>Signed-off-by Mirsad Todorovac <[email protected]>---
v1:
initial version.fs/btrfs/ioctl.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)fs/btrfs/ioctl.c +1
-3@@ -4984,15 +4984,13 @@ static int btrfs_uring_encoded_read(struct io_uring_cmd *cmd, unsigned int issue* undo this. */ if (!iov) { - iov =kmalloc (sizeof (struct iovec ) * args.iovcnt,GFP_NOFS ); + iov =kmemdup (iovstack,sizeof (struct iovec ) * args.iovcnt,GFP_NOFS );if (!iov) {unlock_extent (io_tree, start, lockend, &cached_state);btrfs_inode_unlock (inode,BTRFS_ILOCK_SHARED ); ret = -ENOMEM ; goto out_acct; } - -memcpy (iov, iovstack,sizeof (struct iovec ) * args.iovcnt); } count =min_t (u64,iov_iter_count (&iter), disk_io_size);
Quoted 24 lines · Mirsad Todorovac
The static analyser tool gave the following advice:
./drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c:1266:7-14: WARNING opportunity for kmemdup
→ 1266 tmp = kmalloc(used_size, GFP_KERNEL); 1267 if (!tmp) 1268 return -ENOMEM; 1269→ 1270
memcpy(tmp, &host_telemetry->body.error_count, used_size);Replacing
kmalloc()+memcpy()withkmemdump()doesn't change semantics. Original code works without fault, so this is not a bug fix but proposed improvement.Fixes 84a2947ecc85c ("drm/amdgpu: Implement virt req_ras_err_count")Cc Alex Deucher <[email protected]>Cc "Christian König" <[email protected]>Cc Xinhui Pan <[email protected]>Cc David Airlie <[email protected]>Cc Simona Vetter <[email protected]>Cc Zhigang Luo <[email protected]>Cc Victor Skvortsov <[email protected]>Cc Hawking Zhang <[email protected]>Cc Lijo Lazar <[email protected]>
Quoted 8 lines
Cc Yunxiang Li <[email protected]>Cc Jack Xiao <[email protected]>Cc Vignesh Chander <[email protected]>Cc Danijel Slivka <[email protected]>Signed-off-by Mirsad Todorovac <[email protected]>
Thanks,
Lijo
Quoted 25 lines
---
v1:
initial version.drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c +1
-3@@ -1263,12 +1263,10 @@ static int amdgpu_virt_cache_host_error_counts(struct amdgpu_device *adev,if (used_size > (AMD_SRIOV_RAS_TELEMETRY_SIZE_KB <<10 ))return 0 ; - tmp =kmalloc (used_size,GFP_KERNEL ); + tmp =kmemdup (&host_telemetry->body.error_count, used_size,GFP_KERNEL );if (!tmp)return -ENOMEM ; -memcpy (tmp, &host_telemetry->body.error_count, used_size); -if (checksum !=amd_sriov_msg_checksum (tmp, used_size,0 ,0 )) goto out;
Alex Deucher
AppliedApplied. Thanks!
Alex
Quoted 68 lines · Lijo
Quoted 24 lines · Mirsad Todorovac
The static analyser tool gave the following advice:
./drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c:1266:7-14: WARNING opportunity for kmemdup
→ 1266 tmp = kmalloc(used_size, GFP_KERNEL); 1267 if (!tmp) 1268 return -ENOMEM; 1269→ 1270
memcpy(tmp, &host_telemetry->body.error_count, used_size);Replacing
kmalloc()+memcpy()withkmemdump()doesn't change semantics. Original code works without fault, so this is not a bug fix but proposed improvement.Fixes 84a2947ecc85c ("drm/amdgpu: Implement virt req_ras_err_count")Cc Alex Deucher <[email protected]>Cc "Christian König" <[email protected]>Cc Xinhui Pan <[email protected]>Cc David Airlie <[email protected]>Cc Simona Vetter <[email protected]>Cc Zhigang Luo <[email protected]>Cc Victor Skvortsov <[email protected]>Cc Hawking Zhang <[email protected]>Cc Lijo Lazar <[email protected]>Quoted 8 lines
Cc Yunxiang Li <[email protected]>Cc Jack Xiao <[email protected]>Cc Vignesh Chander <[email protected]>Cc Danijel Slivka <[email protected]>Signed-off-by Mirsad Todorovac <[email protected]>Reviewed-by Lijo Lazar <[email protected]>Thanks,
LijoQuoted 25 lines
---
v1:
initial version.drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c +1
-3@@ -1263,12 +1263,10 @@ static int amdgpu_virt_cache_host_error_counts(struct amdgpu_device *adev,if (used_size > (AMD_SRIOV_RAS_TELEMETRY_SIZE_KB <<10 ))return 0 ; - tmp =kmalloc (used_size,GFP_KERNEL ); + tmp =kmemdup (&host_telemetry->body.error_count, used_size,GFP_KERNEL );if (!tmp)return -ENOMEM ; -memcpy (tmp, &host_telemetry->body.error_count, used_size); -if (checksum !=amd_sriov_msg_checksum (tmp, used_size,0 ,0 )) goto out;
Quoted 11 lines · Mirsad Todorovac
The static analyser tool gave the following advice:
./drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c:1266:7-14: WARNING opportunity for kmemdup
→ 1266 tmp = kmalloc(used_size, GFP_KERNEL); 1267 if (!tmp) 1268 return -ENOMEM; 1269→ 1270
memcpy(tmp, &host_telemetry->body.error_count, used_size);[...]
Applied to for-next, thanks!
[1/3] drm/admgpu: replace kmalloc() and memcpy() with kmemdup()
(no commit info)
[2/3] xfs/libxfs: replace kmalloc() and memcpy() with kmemdup()
commit: 9d9b72472631262b35157f1a650f066c0e11c2bb
[3/3] btrfs: replace kmalloc() and memcpy() with kmemdup()
(no commit info)
Best regards,
Signature · 1 line
Carlos Maiolino <[email protected]>
Quoted 12 lines · Carlos Maiolino
Quoted 10 lines · Mirsad Todorovac
The static analyser tool gave the following advice:
./drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c:1266:7-14: WARNING opportunity for kmemdup
→ 1266 tmp = kmalloc(used_size, GFP_KERNEL); 1267 if (!tmp) 1268 return -ENOMEM; 1269→ 1270
memcpy(tmp, &host_telemetry->body.error_count, used_size);
Quoted 3 lines
Quoted 1 line
[...]
Applied to for-next, thanks!
FWIW, I already picked up the amdgpu patch for drm-next on Dec 18th.
Alex
Quoted 12 lines
[1/3] drm/admgpu: replace
kmalloc()andmemcpy()withkmemdup()
(no commit info)
[2/3] xfs/libxfs: replacekmalloc()andmemcpy()withkmemdup()commit: 9d9b72472631262b35157f1a650f066c0e11c2bb[3/3] btrfs: replace
kmalloc()andmemcpy()withkmemdup()
(no commit info)Best regards,
--
Carlos Maiolino <[email protected]>
Carlos Maiolino
maintainerQuoted 13 lines · Alex Deucher
Quoted 12 lines · Carlos Maiolino
Quoted 10 lines · Mirsad Todorovac
The static analyser tool gave the following advice:
./drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c:1266:7-14: WARNING opportunity for kmemdup
→ 1266 tmp = kmalloc(used_size, GFP_KERNEL); 1267 if (!tmp) 1268 return -ENOMEM; 1269→ 1270
memcpy(tmp, &host_telemetry->body.error_count, used_size);
Quoted 6 lines
Quoted 3 lines
Quoted 1 line
[...]
Applied to for-next, thanks!
FWIW, I already picked up the amdgpu patch for drm-next on Dec 18th.
b4 seems to have ignored that I pulled only the xfs bits :)
Thanks for the heads up Alex.
Quoted 14 lines
Alex
Quoted 12 lines
[1/3] drm/admgpu: replace
kmalloc()andmemcpy()withkmemdup()
(no commit info)
[2/3] xfs/libxfs: replacekmalloc()andmemcpy()withkmemdup()commit: 9d9b72472631262b35157f1a650f066c0e11c2bb[3/3] btrfs: replace
kmalloc()andmemcpy()withkmemdup()
(no commit info)Best regards,
--
Carlos Maiolino <[email protected]>