[PATCH] drm/omap: fix memory leak when FB init fails

Tomi Valkeinen tomi.valkeinen at ti.com
Mon Aug 7 11:50:31 UTC 2017


On 07/08/17 14:29, Laurent Pinchart wrote:
> Hi Tomi,
> 
> Thank you for the patch.
> 
> On Friday 04 Aug 2017 12:24:10 Tomi Valkeinen wrote:
>> omap_framebuffer_create() fails to unref all the gem objects if creating
>> the FB fails, leading to a memory leak.
>>
>> Fix the loop so that it goes through all the reffed gem objects.
>>
>> Signed-off-by: Tomi Valkeinen <tomi.valkeinen at ti.com>
>> ---
>>  drivers/gpu/drm/omapdrm/omap_fb.c | 2 +-
>>  1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/drivers/gpu/drm/omapdrm/omap_fb.c
>> b/drivers/gpu/drm/omapdrm/omap_fb.c index ddf7a457951b..b1a762b70cbf 100644
>> --- a/drivers/gpu/drm/omapdrm/omap_fb.c
>> +++ b/drivers/gpu/drm/omapdrm/omap_fb.c
>> @@ -379,7 +379,7 @@ struct drm_framebuffer *omap_framebuffer_create(struct
>> drm_device *dev, return fb;
>>
>>  error:
>> -	while (--i > 0)
>> +	while (--i >= 0)
> 
> How about i-- > 0 ? That way we could make i an unsigned int as it should be, 
> given that a negative array index doesn't make sense here.

I tried that too, but I think it's a bit confusing. It's nice to see the
limit of the iteration directly from the comparison, and with i--, we
decrease i after the comparison. So "> 0" actually means ">= 0 inside
the body of the while loop"...

 Tomi

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: OpenPGP digital signature
URL: <https://lists.freedesktop.org/archives/dri-devel/attachments/20170807/b71f342c/attachment.sig>


More information about the dri-devel mailing list