AMD-GFX Archive on lore.kernel.org
 help / color / mirror / Atom feed
* drm/amdkfd: Use memdup_user() rather than duplicating its
@ 2023-08-08 20:57 Atul Raut
  2023-08-08 22:47 ` Felix Kuehling
  0 siblings, 1 reply; 3+ messages in thread
From: Atul Raut @ 2023-08-08 20:57 UTC (permalink / raw)
  To: Felix.Kuehling; +Cc: linux-kernel-mentees, amd-gfx

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

Signed-off-by: Atul Raut <rauji.raut@gmail.com>
---
 drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c b/drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c
index 2df153828ff4..51740e007e89 100644
--- a/drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c
+++ b/drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c
@@ -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;
 
-	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;
 }
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: drm/amdkfd: Use memdup_user() rather than duplicating its
  2023-08-08 20:57 drm/amdkfd: Use memdup_user() rather than duplicating its Atul Raut
@ 2023-08-08 22:47 ` Felix Kuehling
  2023-08-08 23:51   ` Atul Raut
  0 siblings, 1 reply; 3+ messages in thread
From: Felix Kuehling @ 2023-08-08 22:47 UTC (permalink / raw)
  To: Atul Raut; +Cc: linux-kernel-mentees, amd-gfx

On 2023-08-08 16:57, Atul Raut wrote:
> 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
>
> Signed-off-by: Atul Raut <rauji.raut@gmail.com>
> ---
>   drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c | 9 +++------
>   1 file changed, 3 insertions(+), 6 deletions(-)
>
> diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c b/drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c
> index 2df153828ff4..51740e007e89 100644
> --- a/drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c
> +++ b/drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c
> @@ -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;
>   
> -	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?


> +		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


>   
>   	return queue_ids;
>   }

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: drm/amdkfd: Use memdup_user() rather than duplicating its
  2023-08-08 22:47 ` Felix Kuehling
@ 2023-08-08 23:51   ` Atul Raut
  0 siblings, 0 replies; 3+ messages in thread
From: Atul Raut @ 2023-08-08 23:51 UTC (permalink / raw)
  To: Felix Kuehling; +Cc: linux-kernel-mentees, amd-gfx

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

On 8/8/23 15:47, Felix Kuehling wrote:
> On 2023-08-08 16:57, Atul Raut wrote:
>> 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
>>
>> Signed-off-by: Atul Raut <rauji.raut@gmail.com>
>> ---
>>   drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c | 9 +++------
>>   1 file changed, 3 insertions(+), 6 deletions(-)
>>
>> diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c 
>> b/drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c
>> index 2df153828ff4..51740e007e89 100644
>> --- a/drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c
>> +++ b/drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c
>> @@ -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;
>>   -    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?
>
>
>> +        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
>
>
>>         return queue_ids;
>>   }

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2023-08-09  1:36 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-08-08 20:57 drm/amdkfd: Use memdup_user() rather than duplicating its Atul Raut
2023-08-08 22:47 ` Felix Kuehling
2023-08-08 23:51   ` Atul Raut

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox