diff mbox series

media: platform: allegro-dvt: Fix possible memory leak in allocate_buffers_internal()

Message ID 20241009082802.1587618-1-cuigaosheng1@huawei.com (mailing list archive)
State New
Headers show
Series media: platform: allegro-dvt: Fix possible memory leak in allocate_buffers_internal() | expand

Commit Message

cuigaosheng Oct. 9, 2024, 8:28 a.m. UTC
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")
Signed-off-by: Gaosheng Cui <cuigaosheng1@huawei.com>
---
 drivers/media/platform/allegro-dvt/allegro-core.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

Comments

Michael Tretter Oct. 22, 2024, 3:10 p.m. UTC | #1
On Wed, 09 Oct 2024 16:28:02 +0800, Gaosheng Cui wrote:
> 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")
> Signed-off-by: Gaosheng Cui <cuigaosheng1@huawei.com>

Reviewed-by: Michael Tretter <m.tretter@pengutronix.de>

> ---
>  drivers/media/platform/allegro-dvt/allegro-core.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/media/platform/allegro-dvt/allegro-core.c b/drivers/media/platform/allegro-dvt/allegro-core.c
> index 73606cee586e..88c36eb6174a 100644
> --- a/drivers/media/platform/allegro-dvt/allegro-core.c
> +++ b/drivers/media/platform/allegro-dvt/allegro-core.c
> @@ -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);
>  	}
>  
> -- 
> 2.25.1
> 
>
diff mbox series

Patch

diff --git a/drivers/media/platform/allegro-dvt/allegro-core.c b/drivers/media/platform/allegro-dvt/allegro-core.c
index 73606cee586e..88c36eb6174a 100644
--- a/drivers/media/platform/allegro-dvt/allegro-core.c
+++ b/drivers/media/platform/allegro-dvt/allegro-core.c
@@ -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);
 	}