public inbox for linux-media@vger.kernel.org
 help / color / mirror / Atom feed
From: Andrzej Pietrasiewicz <andrzej.p@collabora.com>
To: Sebastian Fricke <sebastian.fricke@collabora.com>,
	Mauro Carvalho Chehab <mchehab@kernel.org>,
	Ezequiel Garcia <ezequiel@vanguardiasur.com.ar>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org,
	linux-rockchip@lists.infradead.org,
	linux-staging@lists.linux.dev, Jonas Karlman <jonas@kwiboo.se>,
	Alex Bee <knaerzche@gmail.com>,
	Nicolas Dufresne <nicolas.dufresne@collabora.com>,
	Collabora Kernel-domain <kernel@collabora.com>,
	Robert Beckett <bob.beckett@collabora.com>,
	Laurent Pinchart <laurent.pinchart@ideasonboard.com>,
	Benjamin Gaignard <benjamin.gaignard@collabora.com>
Subject: Re: [PATCH v2 03/12] staging: media: rkvdec: Helper for buffer queue busy check
Date: Mon, 16 Jan 2023 08:54:55 +0100	[thread overview]
Message-ID: <4cbfcbfb-4d77-83e9-f5f2-d8752d8860eb@collabora.com> (raw)
In-Reply-To: <20230101-patch-series-v2-6-2-rc1-v2-3-fa1897efac14@collabora.com>

Hi Sebastian,

W dniu 12.01.2023 o 13:56, Sebastian Fricke pisze:
> Implement a helper function, wrapping around getting a vb2 queue and
> checking whether it is busy, to reduce the amount of code duplication in
> the driver.
> 
> Signed-off-by: Sebastian Fricke <sebastian.fricke@collabora.com>
> ---
>   drivers/staging/media/rkvdec/rkvdec.c | 21 ++++++++++++++-------
>   1 file changed, 14 insertions(+), 7 deletions(-)
> 
> diff --git a/drivers/staging/media/rkvdec/rkvdec.c b/drivers/staging/media/rkvdec/rkvdec.c
> index 7bab7586918c..c849f6c20279 100644
> --- a/drivers/staging/media/rkvdec/rkvdec.c
> +++ b/drivers/staging/media/rkvdec/rkvdec.c
> @@ -27,6 +27,17 @@
>   #include "rkvdec.h"
>   #include "rkvdec-regs.h"
>   
> +static int rkvdec_queue_busy(struct rkvdec_ctx *ctx, enum v4l2_buf_type buf_type)
> +{
> +	struct vb2_queue *vq;
> +
> +	vq = v4l2_m2m_get_vq(ctx->fh.m2m_ctx, buf_type);
> +	if (vb2_is_busy(vq))
> +		return -EBUSY;
> +	else
> +		return 0;

Optionally you can use the ternary operator:

return vb2_is_busy(vg) ? -EBUSY : 0;

But then this new function essentially becomes a wrapper around extracting
the vq. The wrapper then encodes its result in the return value,
which is later decoded at call site to only return -EBUSY if the wrapper
returns -EBUSY and ignore the result if 0. This makes me think that
maybe you want a macro instead:

#define rkvdec_queue_busy(ctx, type) \
	vb2_is_busy(v4l2_m2m_get_vq((ctx)->fh.m2m_ctx, (type)))

and call it like this:

if (rkvdec_queue_busy(c, t))
	return -EBUSY;

> +}
> +
>   static int rkvdec_try_ctrl(struct v4l2_ctrl *ctrl)
>   {
>   	struct rkvdec_ctx *ctx = container_of(ctrl->handler, struct rkvdec_ctx, ctrl_hdl);
> @@ -311,13 +322,10 @@ static int rkvdec_s_capture_fmt(struct file *file, void *priv,
>   				struct v4l2_format *f)
>   {
>   	struct rkvdec_ctx *ctx = fh_to_rkvdec_ctx(priv);
> -	struct vb2_queue *vq;
>   	int ret;
>   
>   	/* Change not allowed if queue is busy */
> -	vq = v4l2_m2m_get_vq(ctx->fh.m2m_ctx,
> -			     V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE);
> -	if (vb2_is_busy(vq))
> +	if (rkvdec_queue_busy(ctx, V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE) != 0)

if you keep the current version you can drop the "!= 0"

Regards,

Andrzej

>   		return -EBUSY;
>   
>   	ret = rkvdec_try_capture_fmt(file, priv, f);
> @@ -335,7 +343,7 @@ static int rkvdec_s_output_fmt(struct file *file, void *priv,
>   	struct v4l2_m2m_ctx *m2m_ctx = ctx->fh.m2m_ctx;
>   	const struct rkvdec_coded_fmt_desc *desc;
>   	struct v4l2_format *cap_fmt;
> -	struct vb2_queue *peer_vq, *vq;
> +	struct vb2_queue *vq;
>   	int ret;
>   
>   	/*
> @@ -354,8 +362,7 @@ static int rkvdec_s_output_fmt(struct file *file, void *priv,
>   	 * queue, we can't allow doing so when the CAPTURE queue has buffers
>   	 * allocated.
>   	 */
> -	peer_vq = v4l2_m2m_get_vq(m2m_ctx, V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE);
> -	if (vb2_is_busy(peer_vq))
> +	if (rkvdec_queue_busy(ctx, V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE) != 0)
>   		return -EBUSY;
>   
>   	ret = rkvdec_try_output_fmt(file, priv, f);
> 


  reply	other threads:[~2023-01-16  7:55 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-12 12:56 [PATCH v2 00/12] RkVDEC HEVC driver Sebastian Fricke
2023-01-12 12:56 ` [PATCH v2 01/12] media: v4l2: Add NV15 pixel format Sebastian Fricke
2023-01-13 12:19   ` kernel test robot
2023-02-16  8:57   ` Hsia-Jun Li
2023-02-16 17:00     ` Nicolas Dufresne
2023-02-17  2:40       ` Hsia-Jun Li
2023-01-12 12:56 ` [PATCH v2 02/12] media: v4l2-common: Add helpers to calculate bytesperline and sizeimage Sebastian Fricke
2023-01-12 12:56 ` [PATCH v2 03/12] staging: media: rkvdec: Helper for buffer queue busy check Sebastian Fricke
2023-01-16  7:54   ` Andrzej Pietrasiewicz [this message]
2023-01-12 12:56 ` [PATCH v2 04/12] staging: media: rkvdec: Block start streaming until both queues run Sebastian Fricke
2023-01-12 14:55   ` Ezequiel Garcia
2023-01-12 15:00     ` Dan Carpenter
2023-01-16  8:23   ` Andrzej Pietrasiewicz
2023-01-12 12:56 ` [PATCH v2 05/12] staging: media: rkvdec: Add SPS structure to internal context Sebastian Fricke
2023-01-12 15:02   ` Ezequiel Garcia
2023-01-16 10:00     ` Andrzej Pietrasiewicz
2023-01-12 12:56 ` [PATCH v2 06/12] staging: media: rkvdec: Add a valid pixel format check as callback Sebastian Fricke
2023-01-12 15:30   ` Ezequiel Garcia
2023-01-12 12:56 ` [PATCH v2 07/12] staging: media: rkvdec: Add a routine to fetch SPS attributes as a callback Sebastian Fricke
2023-01-16 10:27   ` Andrzej Pietrasiewicz
2023-01-12 12:56 ` [PATCH v2 08/12] staging: media: rkvdec: Add a valid SPS check " Sebastian Fricke
2023-01-12 12:56 ` [PATCH v2 09/12] staging: media: rkvdec: h264: Add callbacks for h264 Sebastian Fricke
2023-01-12 15:21   ` Ezequiel Garcia
2023-01-12 21:58     ` Nicolas Dufresne
2023-01-12 12:56 ` [PATCH v2 10/12] staging: media: rkvdec: Wrapper for pixel format preparation Sebastian Fricke
2023-01-16 10:42   ` Andrzej Pietrasiewicz
2023-01-12 12:56 ` [PATCH v2 11/12] staging: media: rkvdec: Enable S_CTRL IOCTL Sebastian Fricke
2023-01-12 15:09   ` Ezequiel Garcia
2023-01-12 22:04     ` Nicolas Dufresne
2023-01-12 12:56 ` [PATCH v2 12/12] staging: media: rkvdec: Add HEVC backend Sebastian Fricke
2023-01-12 18:27   ` kernel test robot
2023-01-16 12:44   ` Andrzej Pietrasiewicz

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=4cbfcbfb-4d77-83e9-f5f2-d8752d8860eb@collabora.com \
    --to=andrzej.p@collabora.com \
    --cc=benjamin.gaignard@collabora.com \
    --cc=bob.beckett@collabora.com \
    --cc=ezequiel@vanguardiasur.com.ar \
    --cc=gregkh@linuxfoundation.org \
    --cc=jonas@kwiboo.se \
    --cc=kernel@collabora.com \
    --cc=knaerzche@gmail.com \
    --cc=laurent.pinchart@ideasonboard.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=linux-rockchip@lists.infradead.org \
    --cc=linux-staging@lists.linux.dev \
    --cc=mchehab@kernel.org \
    --cc=nicolas.dufresne@collabora.com \
    --cc=sebastian.fricke@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