From: Philipp Zabel <p.zabel@pengutronix.de>
To: Benjamin Gaignard <benjamin.gaignard@collabora.com>,
nicolas.dufresne@collabora.com, mchehab@kernel.org
Cc: linux-media@vger.kernel.org, linux-rockchip@lists.infradead.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2 2/7] media: verisilicon: AV1: Use alloc/free helpers for auxiliary buffers
Date: Fri, 20 Nov 2026 16:56:38 +0100 [thread overview]
Message-ID: <dca17004d6cd81f66ebadc0a227548a4e558f2df.camel@pengutronix.de> (raw)
In-Reply-To: <20261120151345.88802-3-benjamin.gaignard@collabora.com>
On Fr, 2026-11-20 at 16:13 +0100, Benjamin Gaignard wrote:
> Simplify and clean up the code by using the helpers.
>
> Signed-off-by: Benjamin Gaignard <benjamin.gaignard@collabora.com>
> Reviewed-by: Nicolas Dufresne <nicolas.dufresne@collabora.com>
> ---
> .../media/platform/verisilicon/hantro_av1.c | 177 ++++--------------
> 1 file changed, 39 insertions(+), 138 deletions(-)
>
> diff --git a/drivers/media/platform/verisilicon/hantro_av1.c b/drivers/media/platform/verisilicon/hantro_av1.c
> index 2cde32f0e935..e05816c7dfa3 100644
> --- a/drivers/media/platform/verisilicon/hantro_av1.c
> +++ b/drivers/media/platform/verisilicon/hantro_av1.c
> @@ -235,40 +235,17 @@ size_t hantro_av1_chroma_size(struct hantro_ctx *ctx)
>
> static void hantro_av1_tiles_free(struct hantro_ctx *ctx)
> {
> - struct hantro_dev *vpu = ctx->dev;
> struct hantro_av1_dec_hw_ctx *av1_dec = &ctx->av1_dec;
>
> - if (av1_dec->db_data_col.cpu)
> - dma_free_coherent(vpu->dev, av1_dec->db_data_col.size,
> - av1_dec->db_data_col.cpu,
> - av1_dec->db_data_col.dma);
> - av1_dec->db_data_col.cpu = NULL;
> -
> - if (av1_dec->db_ctrl_col.cpu)
> - dma_free_coherent(vpu->dev, av1_dec->db_ctrl_col.size,
> - av1_dec->db_ctrl_col.cpu,
> - av1_dec->db_ctrl_col.dma);
> - av1_dec->db_ctrl_col.cpu = NULL;
> -
> - if (av1_dec->cdef_col.cpu)
> - dma_free_coherent(vpu->dev, av1_dec->cdef_col.size,
> - av1_dec->cdef_col.cpu, av1_dec->cdef_col.dma);
> - av1_dec->cdef_col.cpu = NULL;
> -
> - if (av1_dec->sr_col.cpu)
> - dma_free_coherent(vpu->dev, av1_dec->sr_col.size,
> - av1_dec->sr_col.cpu, av1_dec->sr_col.dma);
> - av1_dec->sr_col.cpu = NULL;
> -
> - if (av1_dec->lr_col.cpu)
> - dma_free_coherent(vpu->dev, av1_dec->lr_col.size,
> - av1_dec->lr_col.cpu, av1_dec->lr_col.dma);
> - av1_dec->lr_col.cpu = NULL;
> + hantro_free_aux_buf(ctx, &av1_dec->db_data_col);
> + hantro_free_aux_buf(ctx, &av1_dec->db_ctrl_col);
> + hantro_free_aux_buf(ctx, &av1_dec->cdef_col);
> + hantro_free_aux_buf(ctx, &av1_dec->sr_col);
> + hantro_free_aux_buf(ctx, &av1_dec->lr_col);
> }
>
> static int hantro_av1_tiles_reallocate(struct hantro_ctx *ctx)
> {
> - struct hantro_dev *vpu = ctx->dev;
> struct hantro_av1_dec_hw_ctx *av1_dec = &ctx->av1_dec;
> struct hantro_av1_dec_ctrls *ctrls = &av1_dec->ctrls;
> const struct v4l2_av1_tile_info *tile_info = &ctrls->frame->tile_info;
> @@ -277,6 +254,7 @@ static int hantro_av1_tiles_reallocate(struct hantro_ctx *ctx)
> unsigned int height_in_sb = height / 64;
> unsigned int stripe_num = ((height + 8) + 63) / 64;
> size_t size;
> + int ret;
>
> if (av1_dec->db_data_col.size >=
> ALIGN(height * 12 * ctx->bit_depth / 8, 128) * num_tile_cols)
> @@ -285,44 +263,22 @@ static int hantro_av1_tiles_reallocate(struct hantro_ctx *ctx)
> hantro_av1_tiles_free(ctx);
>
> size = ALIGN(height * 12 * ctx->bit_depth / 8, 128) * num_tile_cols;
> - av1_dec->db_data_col.cpu = dma_alloc_coherent(vpu->dev, size,
> - &av1_dec->db_data_col.dma,
> - GFP_KERNEL);
> - if (!av1_dec->db_data_col.cpu)
> - goto buffer_allocation_error;
> - av1_dec->db_data_col.size = size;
> + ret = hantro_allocate_aux_buf(ctx, &av1_dec->db_data_col, size);
>
> size = ALIGN(height * 2 * 16 / 4, 128) * num_tile_cols;
> - av1_dec->db_ctrl_col.cpu = dma_alloc_coherent(vpu->dev, size,
> - &av1_dec->db_ctrl_col.dma,
> - GFP_KERNEL);
> - if (!av1_dec->db_ctrl_col.cpu)
> - goto buffer_allocation_error;
> - av1_dec->db_ctrl_col.size = size;
> + ret |= hantro_allocate_aux_buf(ctx, &av1_dec->db_ctrl_col, size);
Please don't |= error return values. Even if it happens to work here
because hantro_allocate_aux_buf() is guaranteed to return the same
error, it may inspire others to copy this in places where it's invalid.
Further, hantro_allocate_aux_buf() looks like it can return -EINVAL and
-ENOMEM, not sure if that can happen inside reallocate. That would
combine into -ENOENT, which makes no sense to return.
regards
Philipp
next prev parent reply other threads:[~2026-11-20 15:56 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-20 15:13 [PATCH v2 0/7] media: verisilicon: simplify auxiliary buffers allocation Benjamin Gaignard
2026-11-20 15:13 ` [PATCH v2 1/7] media: verisilicon: Add helpers to allocate and free auxiliary buffers Benjamin Gaignard
2026-11-20 15:13 ` [PATCH v2 2/7] media: verisilicon: AV1: Use alloc/free helpers for " Benjamin Gaignard
2026-11-20 15:56 ` Philipp Zabel [this message]
2026-11-20 15:13 ` [PATCH v2 3/7] media: verisilicon: h264: " Benjamin Gaignard
2026-11-20 15:13 ` [PATCH v2 4/7] media: verisilicon: hevc: " Benjamin Gaignard
2026-11-20 15:13 ` [PATCH v2 5/7] media: verisilicon: vp8: " Benjamin Gaignard
2026-11-20 15:13 ` [PATCH v2 6/7] media: verisilicon: vp9: " Benjamin Gaignard
2026-11-20 15:13 ` [PATCH v2 7/7] media: verisilicon: mpeg4: " Benjamin Gaignard
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=dca17004d6cd81f66ebadc0a227548a4e558f2df.camel@pengutronix.de \
--to=p.zabel@pengutronix.de \
--cc=benjamin.gaignard@collabora.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-media@vger.kernel.org \
--cc=linux-rockchip@lists.infradead.org \
--cc=mchehab@kernel.org \
--cc=nicolas.dufresne@collabora.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®