Re: [PATCH] drm/xe/query: Refactor copy_to_user() usage in four functions

From: Markus Elfring
Date: Wed Sep 18 2024 - 05:39:41 EST


>> Assign return values from copy_to_user() calls to additional local variables
>> so that four kfree() calls and return statements can be omitted accordingly.

>> +++ b/drivers/gpu/drm/xe/xe_query.c
>> @@ -220,13 +220,11 @@ static int query_engines(struct xe_device *xe,
>>
>> engines->num_engines = i;
>>
>> - if (copy_to_user(query_ptr, engines, size)) {
>> + {
>
> Please don't leave blocks like this behind when you remove the if.

>> + unsigned long ctu = copy_to_user(query_ptr, engines, size);
>> kfree(engines);
>> - return -EFAULT;
>> + return ctu ? -EFAULT : 0;
>> }
>> - kfree(engines);
>> -
>> - return 0;
>> }


Would you tolerate the shown variable definition without the proposed
compound statement?

Regards,
Markus