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

Markus Elfring Markus.Elfring at web.de
Wed Sep 18 09:38:57 UTC 2024


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


More information about the dri-devel mailing list