media: platform: allegro-dvt: Fix possible memory leak in allocate_buffers_internal()
authorGaosheng Cui <cuigaosheng1@huawei.com>
Wed, 9 Oct 2024 08:28:02 +0000 (16:28 +0800)
committerHans Verkuil <hverkuil-cisco@xs4all.nl>
Sat, 12 Oct 2024 14:28:26 +0000 (16:28 +0200)
The buffer in the loop should be released under the exception path,
otherwise there may be a memory leak here.

To mitigate this, free the buffer when allegro_alloc_buffer fails.

Fixes: f20387dfd065 ("media: allegro: add Allegro DVT video IP core driver")
Cc: <stable@vger.kernel.org>
Signed-off-by: Gaosheng Cui <cuigaosheng1@huawei.com>
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
drivers/media/platform/allegro-dvt/allegro-core.c

index 76b4de1150b21d382feba40ffb1b6c18d1908a03..44e0d5512f94aee8d31b74c00790548872344f2a 100644 (file)
@@ -1509,8 +1509,10 @@ static int allocate_buffers_internal(struct allegro_channel *channel,
                INIT_LIST_HEAD(&buffer->head);
 
                err = allegro_alloc_buffer(dev, buffer, size);
-               if (err)
+               if (err) {
+                       kfree(buffer);
                        goto err;
+               }
                list_add(&buffer->head, list);
        }