drm/amdkfd: Use memdup_user() rather than duplicating its
Subsystems (3)
To prevent its redundant implementation and streamline code, use memdup_user.
This fixes warnings reported by Coccinelle:
./drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c:2811:13-20: WARNING opportunity for memdup_user
--- drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-)
drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c +3 -6
@@ -2808,12 +2808,9 @@ static uint32_t *get_queue_ids(uint32_t num_queues, uint32_t *usr_queue_id_arrayif (!usr_queue_id_array)return NULL ; - queue_ids =kzalloc (array_size,GFP_KERNEL ); -if (!queue_ids) -return ERR_PTR (-ENOMEM ); - -if (copy_from_user (queue_ids, usr_queue_id_array, array_size)) -return ERR_PTR (-EFAULT ); + queue_ids =memdup_user (usr_queue_id_array, array_size); +if (IS_ERR (Iqueue_ids)) +return ERR_PTR (queue_ids);return queue_ids; }
Signature · 6 lines
2.34.1 _______________________________________________ Linux-kernel-mentees mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees
Felix Kuehling
maintainerQuoted 17 lines · Atul Raut
To prevent its redundant implementation and streamline code, use
memdup_user.This fixes warnings reported by Coccinelle:
./drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c:2811:13-20: WARNING opportunity formemdup_userSigned-off-by Atul Raut <[email protected]>--- drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-)drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c +0
-0@@ -2808,12 +2808,9 @@ static uint32_t *get_queue_ids(uint32_t num_queues, uint32_t *usr_queue_id_arrayif (!usr_queue_id_array)
drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c static uint32_t *get_queue_ids(uint32_t num_queues, uint32_t *usr_queue_id_array · line 2812
Quoted 10 lines
drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c +2
-6return NULL ; - queue_ids =kzalloc (array_size,GFP_KERNEL ); -if (!queue_ids) -return ERR_PTR (-ENOMEM ); - -if (copy_from_user (queue_ids, usr_queue_id_array, array_size)) -return ERR_PTR (-EFAULT ); + queue_ids =memdup_user (usr_queue_id_array, array_size); +if (IS_ERR (Iqueue_ids))
You have a typo in the variable name here. Did you at least compile-test the patch?
drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c static uint32_t *get_queue_ids(uint32_t num_queues, uint32_t *usr_queue_id_array · line 2813
Quoted 1 line
drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c +1
-0+return ERR_PTR (queue_ids);
I think it should just return queue_ids here. That's already an ERR_PTR in case of errors. So you don't even need the "if". Just this should do the job:
return memdup_user(usr_queue_id_array, array_size);
The error checking is done by the caller.
Regards,
Felix
Quoted 3 lines
drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c +0
-0return queue_ids; }
Hello Felix,
I appreciate the code review.
Will correct the typo (seems to have appeared during patch creation following compilation). Shortly as the compilation is successful, V2 will be sent.
-Atul
Quoted 34 lines · Felix Kuehling
Quoted 19 lines · Atul Raut
To prevent its redundant implementation and streamline code, use
memdup_user.This fixes warnings reported by Coccinelle:
./drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c:2811:13-20: WARNING opportunity formemdup_userSigned-off-by Atul Raut <[email protected]>---
drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c| 9 +++------1 file changed, 3 insertions(+), 6 deletions(-)drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c +0
-0@@ -2808,12 +2808,9 @@ static uint32_t *get_queue_ids(uint32_t
num_queues,uint32_t*usr_queue_id_array
if (!usr_queue_id_array)
return NULL;Quoted 8 lines
-
queue_ids=kzalloc(array_size, GFP_KERNEL);
- if (!queue_ids)
- returnERR_PTR(-ENOMEM);
-
- if (copy_from_user(queue_ids, usr_queue_id_array, array_size)) - returnERR_PTR(-EFAULT);
+queue_ids=memdup_user(usr_queue_id_array, array_size); + if (IS_ERR(Iqueue_ids))You have a typo in the variable name here. Did you at least compile-test the patch?
Quoted 1 line
+ return
ERR_PTR(queue_ids);
Quoted 12 lines
I think it should just return
queue_idshere. That's already anERR_PTRin case of errors. So you don't even need the "if". Just this should do the job:return
memdup_user(usr_queue_id_array, array_size);The error checking is done by the caller.
Regards,
FelixQuoted 2 lines
return
queue_ids;
}
_______________________________________________
Linux-kernel-mentees mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees