Skip to contentSkip to conversation

media: verisilicon: Free post processor buffers on error

PATCH In review Detlev Casanova 2 participants 3 messages Apr 25, 2025 – Apr 29, 2025

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 media: verisilicon: Free post processor buffers on error

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")
---
 drivers/media/platform/verisilicon/hantro_postproc.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/media/platform/verisilicon/hantro_postproc.c +3 -1
index c435a393e0cb7..9f559a13d409b 100644
@@ -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;
Signature · 1 line
2.49.0
maintainer Reviewed-by on v1 1/1
#1 lore raw

Le vendredi 25 avril 2025 à 15:24 -0400, Detlev Casanova a écrit :

Quoted 1 line

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

Quoted 10 lines

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")

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

Quoted 20 lines

---
 drivers/media/platform/verisilicon/hantro_postproc.c | 4 +++-

 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/media/platform/verisilicon/hantro_postproc.c +0 -0
index c435a393e0cb7..9f559a13d409b 100644
@@ -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);

drivers/media/platform/verisilicon/hantro_postproc.c +2 -1
-		if (ret)
+		if (ret) {
+			hantro_postproc_free(ctx);

  return ret;

drivers/media/platform/verisilicon/hantro_postproc.c +1 -0
+		}

  }

  return 0;

Signature · 2 lines
Nicolas Dufresne
Principal Engineer at Collabora
#2 lore raw
Quoted 15 lines · On Monday, 28 April 2025 13:25:59 EDT Nicolas Dufresne wrote:
Quoted 1 line · Detlev Casanova

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

Quoted 8 lines

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.

Quoted 8 lines
Quoted 3 lines
Fixes 26711491a807 ("media: verisilicon: Refactor postprocessor to store

more buffers") Signed-off-by: Detlev Casanova
<[email protected]>

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

Yes, that's goot for me.

Detlev.

Quoted 21 lines
Quoted 21 lines
---
 drivers/media/platform/verisilicon/hantro_postproc.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
(quoted diff) +0 -0

b/drivers/media/platform/verisilicon/hantro_postproc.c index c435a393e0cb7..9f559a13d409b 100644

drivers/media/platform/verisilicon/hantro_postproc.c +3 -1
@@ -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;