[PATCH 1/3] drm: property: One function call less in drm_property_create() after error detection
Markus Elfring
Markus.Elfring at web.de
Wed Jan 3 16:24:53 UTC 2024
>> The kfree() function was called in one case by the
>> drm_property_create() function during error handling
>> even if the passed data structure member contained a null pointer.
>> This issue was detected by using the Coccinelle software.
>>
>> Thus use another label.
…
>> +++ b/drivers/gpu/drm/drm_property.c
>> @@ -117,7 +117,7 @@ struct drm_property *drm_property_create(struct drm_device *dev,
>> property->values = kcalloc(num_values, sizeof(uint64_t),
>> GFP_KERNEL);
>> if (!property->values)
>> - goto fail;
>> + goto free_property;
>> }
>>
>> ret = drm_mode_object_add(dev, &property->base, DRM_MODE_OBJECT_PROPERTY);
>> @@ -135,6 +135,7 @@ struct drm_property *drm_property_create(struct drm_device *dev,
>> return property;
>> fail:
>> kfree(property->values);
>> +free_property:
>> kfree(property);
>> return NULL;
>> }
…
> This change is pointless at best, kfree(NULL) works fine.
* Would you interpret such a special function call as redundant?
* Do you find advices applicable from another information source
also for this function implementation?
https://wiki.sei.cmu.edu/confluence/display/c/MEM12-C.+Consider+using+a+goto+chain+when+leaving+a+function+on+error+when+using+and+releasing+resources
> Out of curiosity, what exactly did Coccinelle report?
Some SmPL scripts from my own selection tend to point questionable implementation details out.
Regards,
Markus
More information about the dri-devel
mailing list