[PATCH 1/3] media: rockchip: Introduce the rkvdec2 driver

Detlev Casanova detlev.casanova at collabora.com
Mon Jun 17 07:23:02 PDT 2024


On Monday, June 17, 2024 8:02:56 A.M. EDT Dan Carpenter wrote:
> On Fri, Jun 14, 2024 at 09:56:27PM -0400, Detlev Casanova wrote:
> > +static int rkvdec2_start_streaming(struct vb2_queue *q, unsigned int
> > count) +{
> > +	struct rkvdec2_ctx *ctx = vb2_get_drv_priv(q);
> > +	const struct rkvdec2_coded_fmt_desc *desc;
> > +	int ret, i;
> > +	u32 width, height;
> > +
> > +	if (V4L2_TYPE_IS_CAPTURE(q->type))
> > +		return 0;
> > +
> > +	desc = ctx->coded_fmt_desc;
> > +	if (WARN_ON(!desc))
> > +		return -EINVAL;
> > +
> > +	width = ctx->decoded_fmt.fmt.pix_mp.width;
> > +	height = ctx->decoded_fmt.fmt.pix_mp.height;
> > +	for (i = 0; i < RKVDEC2_RCB_COUNT; i++) {
> > +		ctx->rcb_bufs[i].cpu =
> > +			dma_alloc_coherent(ctx->dev->dev,
> > +					   RCB_SIZE(i),
> > +					   &ctx-
>rcb_bufs[i].dma,
> > +					   GFP_KERNEL);
> > +		if (!ctx->rcb_bufs[i].cpu) {
> > +			ret = -ENOMEM;
> > +			goto err_rcb;
> > +		}
> > +	}
> > +
> > +	if (desc->ops->start) {
> > +		ret = desc->ops->start(ctx);
> > +		if (ret)
> > +			goto err_ops_start;
> > +	}
> > +
> > +	return 0;
> > +
> > +err_ops_start:
> > +err_rcb:
> > +	i--;
> > +	while (i) {
> > +		dma_free_coherent(ctx->dev->dev,
> > +				  RCB_SIZE(i),
> > +				  ctx->rcb_bufs[i].cpu,
> > +				  ctx->rcb_bufs[i].dma);
> > +		i--;
> > +	}
> 
> This will leak the first element of the ctx->rcb_bufs[i] array.  The
> traditional way to write this is either while (--i >= 0) or for unsigned
> int i iterators it would be while (i--).

Yes, I was thinking that an even better solution would be to allocate 1 dma 
buffer and use offsets in it when configuring the hw. But this is only one 
allocation per streamon, not per frame, so this might just be good enough as 
is.

I'll fix the freeing code part

> > +
> > +	return ret;
> > +}
> 
> regards,
> dan carpenter

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 488 bytes
Desc: This is a digitally signed message part.
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20240617/90550e0d/attachment.sig>


More information about the linux-arm-kernel mailing list