public inbox for linux-media@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] media: verisilicon: Free post processor buffers on error
@ 2025-04-25 19:24 Detlev Casanova
  2025-04-28 17:25 ` Nicolas Dufresne
  0 siblings, 1 reply; 3+ messages in thread
From: Detlev Casanova @ 2025-04-25 19:24 UTC (permalink / raw)
  To: linux-kernel
  Cc: Nicolas Dufresne, Benjamin Gaignard, Philipp Zabel,
	Mauro Carvalho Chehab, linux-media, linux-rockchip, kernel,
	Detlev Casanova

When initializing the post processor, it allocates the same number of
buffers as the buf queue.
As the init function is called in streamon(), if an allocation fails,
streamon will return an error and streamoff() will not be called, keeping
all post processor buffers allocated.

To avoid that, all post proc buffers are freed in case of an allocation
error.

Fixes: 26711491a807 ("media: verisilicon: Refactor postprocessor to store more buffers")
Signed-off-by: Detlev Casanova <detlev.casanova@collabora.com>
---
 drivers/media/platform/verisilicon/hantro_postproc.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/media/platform/verisilicon/hantro_postproc.c b/drivers/media/platform/verisilicon/hantro_postproc.c
index c435a393e0cb7..9f559a13d409b 100644
--- a/drivers/media/platform/verisilicon/hantro_postproc.c
+++ b/drivers/media/platform/verisilicon/hantro_postproc.c
@@ -250,8 +250,10 @@ int hantro_postproc_init(struct hantro_ctx *ctx)
 
 	for (i = 0; i < num_buffers; i++) {
 		ret = hantro_postproc_alloc(ctx, i);
-		if (ret)
+		if (ret) {
+			hantro_postproc_free(ctx);
 			return ret;
+		}
 	}
 
 	return 0;
-- 
2.49.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] media: verisilicon: Free post processor buffers on error
  2025-04-25 19:24 [PATCH] media: verisilicon: Free post processor buffers on error Detlev Casanova
@ 2025-04-28 17:25 ` Nicolas Dufresne
  2025-04-29 12:51   ` Detlev Casanova
  0 siblings, 1 reply; 3+ messages in thread
From: Nicolas Dufresne @ 2025-04-28 17:25 UTC (permalink / raw)
  To: Detlev Casanova, linux-kernel
  Cc: Benjamin Gaignard, Philipp Zabel, Mauro Carvalho Chehab,
	linux-media, linux-rockchip, kernel

Le vendredi 25 avril 2025 à 15:24 -0400, Detlev Casanova a écrit :
> When initializing the post processor, it allocates the same number of

What do you think reworking as:

  During initialization, the post processor allocates the same number of

> buffers as the buf queue.
> As the init function is called in streamon(), if an allocation fails,
> streamon will return an error and streamoff() will not be called, keeping
> all post processor buffers allocated.
> 
> To avoid that, all post proc buffers are freed in case of an allocation
> error.
> 
> Fixes: 26711491a807 ("media: verisilicon: Refactor postprocessor to store more buffers")
> Signed-off-by: Detlev Casanova <detlev.casanova@collabora.com>

Reviewed-by: Nicolas Dufresne <nicolas.dufresne@collabora.com>

If you are fine with the suggestion, I can make the changes while
applying.

> ---
>  drivers/media/platform/verisilicon/hantro_postproc.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/media/platform/verisilicon/hantro_postproc.c b/drivers/media/platform/verisilicon/hantro_postproc.c
> index c435a393e0cb7..9f559a13d409b 100644
> --- a/drivers/media/platform/verisilicon/hantro_postproc.c
> +++ b/drivers/media/platform/verisilicon/hantro_postproc.c
> @@ -250,8 +250,10 @@ int hantro_postproc_init(struct hantro_ctx *ctx)
>  
>  	for (i = 0; i < num_buffers; i++) {
>  		ret = hantro_postproc_alloc(ctx, i);
> -		if (ret)
> +		if (ret) {
> +			hantro_postproc_free(ctx);
>  			return ret;
> +		}
>  	}
>  
>  	return 0;

-- 
Nicolas Dufresne
Principal Engineer at Collabora

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] media: verisilicon: Free post processor buffers on error
  2025-04-28 17:25 ` Nicolas Dufresne
@ 2025-04-29 12:51   ` Detlev Casanova
  0 siblings, 0 replies; 3+ messages in thread
From: Detlev Casanova @ 2025-04-29 12:51 UTC (permalink / raw)
  To: linux-kernel, Nicolas Dufresne
  Cc: Benjamin Gaignard, Philipp Zabel, Mauro Carvalho Chehab,
	linux-media, linux-rockchip, kernel

On Monday, 28 April 2025 13:25:59 EDT Nicolas Dufresne wrote:
> Le vendredi 25 avril 2025 à 15:24 -0400, Detlev Casanova a écrit :
> > When initializing the post processor, it allocates the same number of
> 
> What do you think reworking as:
> 
>   During initialization, the post processor allocates the same number of
> 
> > buffers as the buf queue.
> > As the init function is called in streamon(), if an allocation fails,
> > streamon will return an error and streamoff() will not be called, keeping
> > all post processor buffers allocated.
> > 
> > To avoid that, all post proc buffers are freed in case of an allocation
> > error.
> > 
> > Fixes: 26711491a807 ("media: verisilicon: Refactor postprocessor to store
> > more buffers") Signed-off-by: Detlev Casanova
> > <detlev.casanova@collabora.com>
> 
> Reviewed-by: Nicolas Dufresne <nicolas.dufresne@collabora.com>
> 
> If you are fine with the suggestion, I can make the changes while
> applying.

Yes, that's goot for me.

Detlev.

> > ---
> >  drivers/media/platform/verisilicon/hantro_postproc.c | 4 +++-
> >  1 file changed, 3 insertions(+), 1 deletion(-)
> > 
> > diff --git a/drivers/media/platform/verisilicon/hantro_postproc.c
> > b/drivers/media/platform/verisilicon/hantro_postproc.c index
> > c435a393e0cb7..9f559a13d409b 100644
> > --- a/drivers/media/platform/verisilicon/hantro_postproc.c
> > +++ b/drivers/media/platform/verisilicon/hantro_postproc.c
> > @@ -250,8 +250,10 @@ int hantro_postproc_init(struct hantro_ctx *ctx)
> >  
> >  	for (i = 0; i < num_buffers; i++) {
> >  		ret = hantro_postproc_alloc(ctx, i);
> > -		if (ret)
> > +		if (ret) {
> > +			hantro_postproc_free(ctx);
> >  			return ret;
> > +		}
> >  	}
> >  
> >  	return 0;





^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2025-04-29 12:51 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-04-25 19:24 [PATCH] media: verisilicon: Free post processor buffers on error Detlev Casanova
2025-04-28 17:25 ` Nicolas Dufresne
2025-04-29 12:51   ` Detlev Casanova

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox