public inbox for linux-media@vger.kernel.org
 help / color / mirror / Atom feed
From: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
To: Michael Riesch <michael.riesch@collabora.com>
Cc: Dan Carpenter <dan.carpenter@linaro.org>,
	Paul Elder <paul.elder@ideasonboard.com>,
	Mehdi Djait <mehdi.djait@linux.intel.com>,
	Mauro Carvalho Chehab <mchehab@kernel.org>,
	Heiko Stuebner <heiko@sntech.de>,
	Sakari Ailus <sakari.ailus@linux.intel.com>,
	Hans Verkuil <hverkuil+cisco@kernel.org>,
	Bryan O'Donoghue <bryan.odonoghue@linaro.org>,
	Collabora Kernel Team <kernel@collabora.com>,
	stable@kernel.org, linux-media@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org,
	linux-rockchip@lists.infradead.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 2/2] media: rockchip: rkcif: comply with minimum number of buffers requirement
Date: Thu, 19 Feb 2026 18:00:46 +0100	[thread overview]
Message-ID: <20260219170046.GA626936@killaraus.ideasonboard.com> (raw)
In-Reply-To: <d701a97d-6051-4a32-ada6-bf014e385c68@collabora.com>

On Thu, Feb 19, 2026 at 05:19:46PM +0100, Michael Riesch wrote:
> On 2/19/26 10:13, Laurent Pinchart wrote:
> > On Mon, Feb 16, 2026 at 02:49:57PM +0100, Michael Riesch via B4 Relay wrote:
> >> From: Michael Riesch <michael.riesch@collabora.com>
> >>
> >> Each stream requires CIF_REQ_BUFS_MIN=1 buffers to enable streaming.
> >> However, it failed with only one buffer provided.
> >>
> >> Comply with the minimum number of buffers requirement and accept
> >> exactly one buffer.
> >>
> >> Fixes: 501802e2ad51 ("media: rockchip: rkcif: add abstraction for dma blocks")
> >> Cc: stable@kernel.org
> >> Signed-off-by: Michael Riesch <michael.riesch@collabora.com>
> >> ---
> >>  .../media/platform/rockchip/rkcif/rkcif-stream.c   | 41 +++++++++++-----------
> >>  1 file changed, 21 insertions(+), 20 deletions(-)
> >>
> >> diff --git a/drivers/media/platform/rockchip/rkcif/rkcif-stream.c b/drivers/media/platform/rockchip/rkcif/rkcif-stream.c
> >> index e00010a91e8b..5a5ab9e7e86e 100644
> >> --- a/drivers/media/platform/rockchip/rkcif/rkcif-stream.c
> >> +++ b/drivers/media/platform/rockchip/rkcif/rkcif-stream.c
> >> @@ -106,19 +106,6 @@ static int rkcif_stream_init_buffers(struct rkcif_stream *stream)
> >>  {
> >>  	struct v4l2_pix_format_mplane *pix = &stream->pix;
> >>  
> >> -	stream->buffers[0] = rkcif_stream_pop_buffer(stream);
> >> -	if (!stream->buffers[0])
> >> -		goto err_buff_0;
> >> -
> >> -	stream->buffers[1] = rkcif_stream_pop_buffer(stream);
> >> -	if (!stream->buffers[1])
> >> -		goto err_buff_1;
> >> -
> >> -	if (stream->queue_buffer) {
> >> -		stream->queue_buffer(stream, 0);
> >> -		stream->queue_buffer(stream, 1);
> >> -	}
> >> -
> >>  	stream->dummy.size = pix->num_planes * pix->plane_fmt[0].sizeimage;
> >>  	stream->dummy.vaddr =
> >>  		dma_alloc_attrs(stream->rkcif->dev, stream->dummy.size,
> >> @@ -132,16 +119,30 @@ static int rkcif_stream_init_buffers(struct rkcif_stream *stream)
> >>  			stream->dummy.buffer.buff_addr[i - 1] +
> >>  			pix->plane_fmt[i - 1].bytesperline * pix->height;
> >>  
> >> -	return 0;
> >> +	stream->buffers[0] = rkcif_stream_pop_buffer(stream);
> >> +	if (!stream->buffers[0])
> >> +		goto err_buff_0;
> > 
> > Why do you move this after allocation of the dummy buffer, to then add
> > dma_free_attrs() in the err_buff_0 error path ?
> 
> To keep the two rkcif_stream_pop_buffer calls together. We need to
> allocate the dummy in any case, but in case the second pop fails we use
> it -- this was not the case before.

I suppose it's easier than returning buffers[0] in the dummy buffer
allocate error path. Works for me.

> >> -err_dummy:
> >> -	rkcif_stream_return_buffer(stream->buffers[1], VB2_BUF_STATE_QUEUED);
> >> -	stream->buffers[1] = NULL;
> >> +	stream->buffers[1] = rkcif_stream_pop_buffer(stream);
> >> +	if (!stream->buffers[1]) {
> >> +		stream->buffers[stream->frame_phase] = &stream->dummy.buffer;
> >> +		stream->buffers[stream->frame_phase]->is_dummy = true;
> >> +	}
> >> +
> >> +	if (stream->queue_buffer) {
> >> +		stream->queue_buffer(stream, 0);
> >> +		stream->queue_buffer(stream, 1);
> >> +	}
> >> +
> >> +	return 0;
> >>  
> >> -err_buff_1:
> >> -	rkcif_stream_return_buffer(stream->buffers[0], VB2_BUF_STATE_QUEUED);
> >> -	stream->buffers[0] = NULL;
> >>  err_buff_0:
> >> +	dma_free_attrs(stream->rkcif->dev, stream->dummy.size,
> >> +		       stream->dummy.vaddr,
> >> +		       stream->dummy.buffer.buff_addr[0],
> >> +		       DMA_ATTR_NO_KERNEL_MAPPING);
> >> +	stream->dummy.vaddr = NULL;
> >> +err_dummy:
> >>  	return -EINVAL;
> > 
> > You can drop the err_dummy label and return -EINVAL directly. Except you
> > should probably return -ENOMEM as the failure comes from
> > dma_alloc_attrs().
> 
> Makes sense, will fix.
> 
> >>  }
> >>  

-- 
Regards,

Laurent Pinchart

  reply	other threads:[~2026-02-19 17:00 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-02-16 13:49 [PATCH 0/2] media: rockchip: rkcif: various fixes Michael Riesch via B4 Relay
2026-02-16 13:49 ` [PATCH 1/2] media: rockchip: rkcif: fix off by one bugs Michael Riesch via B4 Relay
2026-02-18  2:54   ` Paul Elder
2026-02-19  8:59   ` Laurent Pinchart
2026-02-16 13:49 ` [PATCH 2/2] media: rockchip: rkcif: comply with minimum number of buffers requirement Michael Riesch via B4 Relay
2026-02-17 12:25   ` Michael Riesch
2026-02-18  3:23     ` Paul Elder
2026-02-19  9:13   ` Laurent Pinchart
2026-02-19 16:19     ` Michael Riesch
2026-02-19 17:00       ` Laurent Pinchart [this message]
2026-02-18  7:51 ` [PATCH 0/2] media: rockchip: rkcif: various fixes Chen-Yu Tsai

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=20260219170046.GA626936@killaraus.ideasonboard.com \
    --to=laurent.pinchart@ideasonboard.com \
    --cc=bryan.odonoghue@linaro.org \
    --cc=dan.carpenter@linaro.org \
    --cc=heiko@sntech.de \
    --cc=hverkuil+cisco@kernel.org \
    --cc=kernel@collabora.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=linux-rockchip@lists.infradead.org \
    --cc=mchehab@kernel.org \
    --cc=mehdi.djait@linux.intel.com \
    --cc=michael.riesch@collabora.com \
    --cc=paul.elder@ideasonboard.com \
    --cc=sakari.ailus@linux.intel.com \
    --cc=stable@kernel.org \
    /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