public inbox for linux-media@vger.kernel.org
 help / color / mirror / Atom feed
From: Alexander Stein <alexander.stein@ew.tq-group.com>
To: linux-media@vger.kernel.org,
	Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Cc: Sakari Ailus <sakari.ailus@iki.fi>,
	Manivannan Sadhasivam <mani@kernel.org>,
	Dave Stevenson <dave.stevenson@raspberrypi.com>
Subject: Re: [PATCH v2 18/20] media: i2c: imx290: Factor out format retrieval to separate function
Date: Mon, 17 Oct 2022 07:55:28 +0200	[thread overview]
Message-ID: <5869053.lOV4Wx5bFT@steina-w> (raw)
In-Reply-To: <20221016061523.30127-19-laurent.pinchart@ideasonboard.com>

Hello Laurent,

thanks for the updated patch.

Am Sonntag, 16. Oktober 2022, 08:15:21 CEST schrieb Laurent Pinchart:
> The driver duplicates the same pattern to access the try or active
> format in multiple locations. Factor it out to a separate function.
> 
> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
> ---
> Changes since v1:
> 
> - Avoid returning NULL from imx290_get_pad_format()
> ---
>  drivers/media/i2c/imx290.c | 24 ++++++++++++++----------
>  1 file changed, 14 insertions(+), 10 deletions(-)
> 
> diff --git a/drivers/media/i2c/imx290.c b/drivers/media/i2c/imx290.c
> index 0b34d60f8ce2..b0ff0e8ed45a 100644
> --- a/drivers/media/i2c/imx290.c
> +++ b/drivers/media/i2c/imx290.c
> @@ -519,6 +519,16 @@ static const struct v4l2_ctrl_ops imx290_ctrl_ops = {
>  	.s_ctrl = imx290_set_ctrl,
>  };
> 
> +static struct v4l2_mbus_framefmt *
> +imx290_get_pad_format(struct imx290 *imx290, struct v4l2_subdev_state
> *state, +		      u32 which)
> +{
> +	if (which == V4L2_SUBDEV_FORMAT_ACTIVE)
> +		return &imx290->current_format;
> +	else
> +		return v4l2_subdev_get_try_format(&imx290->sd, state, 
0);
> +}
> +

v4l2_subdev_get_try_format can return NULL, which would be dereferenced later 
on. But this happens only if state is NULL itself, which will raise a WARN_ON 
anyway. So i guess this is fine.

Acked-by: Alexander Stein <alexander.stein@ew.tq-group.com>

>  static int imx290_enum_mbus_code(struct v4l2_subdev *sd,
>  				 struct v4l2_subdev_state 
*sd_state,
>  				 struct v4l2_subdev_mbus_code_enum 
*code)
> @@ -562,12 +572,7 @@ static int imx290_get_fmt(struct v4l2_subdev *sd,
> 
>  	mutex_lock(&imx290->lock);
> 
> -	if (fmt->which == V4L2_SUBDEV_FORMAT_TRY)
> -		framefmt = v4l2_subdev_get_try_format(&imx290->sd, 
sd_state,
> -						      fmt-
>pad);
> -	else
> -		framefmt = &imx290->current_format;
> -
> +	framefmt = imx290_get_pad_format(imx290, sd_state, fmt->which);
>  	fmt->format = *framefmt;
> 
>  	mutex_unlock(&imx290->lock);
> @@ -627,10 +632,9 @@ static int imx290_set_fmt(struct v4l2_subdev *sd,
>  	fmt->format.code = imx290_formats[i].code;
>  	fmt->format.field = V4L2_FIELD_NONE;
> 
> -	if (fmt->which == V4L2_SUBDEV_FORMAT_TRY) {
> -		format = v4l2_subdev_get_try_format(sd, sd_state, fmt-
>pad);
> -	} else {
> -		format = &imx290->current_format;
> +	format = imx290_get_pad_format(imx290, sd_state, fmt->which);
> +
> +	if (fmt->which == V4L2_SUBDEV_FORMAT_ACTIVE) {
>  		imx290->current_mode = mode;
>  		imx290->bpp = imx290_formats[i].bpp;





  reply	other threads:[~2022-10-17  5:55 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-16  6:15 [PATCH v2 00/20] media: i2c: imx290: Miscellaneous improvements Laurent Pinchart
2022-10-16  6:15 ` [PATCH v2 01/20] media: dt-bindings: Convert imx290.txt to YAML Laurent Pinchart
2022-10-16 15:05   ` Krzysztof Kozlowski
2022-10-17 13:57   ` Dave Stevenson
2022-10-25 14:12     ` Sakari Ailus
2022-10-16  6:15 ` [PATCH v2 02/20] media: i2c: imx290: Use device lock for the control handler Laurent Pinchart
2022-10-16  6:15 ` [PATCH v2 03/20] media: i2c: imx290: Print error code when I2C transfer fails Laurent Pinchart
2022-10-16  6:15 ` [PATCH v2 04/20] media: i2c: imx290: Replace macro with explicit ARRAY_SIZE() Laurent Pinchart
2022-10-16  6:15 ` [PATCH v2 05/20] media: i2c: imx290: Drop imx290_write_buffered_reg() Laurent Pinchart
2022-10-16  6:15 ` [PATCH v2 06/20] media: i2c: imx290: Drop regmap cache Laurent Pinchart
2022-10-16  6:15 ` [PATCH v2 07/20] media: i2c: imx290: Specify HMAX values in decimal Laurent Pinchart
2022-10-16  6:15 ` [PATCH v2 08/20] media: i2c: imx290: Support variable-sized registers Laurent Pinchart
2022-10-16  6:15 ` [PATCH v2 09/20] media: i2c: imx290: Correct register sizes Laurent Pinchart
2022-10-16  6:15 ` [PATCH v2 10/20] media: i2c: imx290: Simplify error handling when writing registers Laurent Pinchart
2022-10-16  6:15 ` [PATCH v2 11/20] media: i2c: imx290: Define more register macros Laurent Pinchart
2022-10-17  6:07   ` Alexander Stein
2022-10-17  8:35   ` [PATCH v2.1 " Laurent Pinchart
2022-10-16  6:15 ` [PATCH v2 12/20] media: i2c: imx290: Add exposure time control Laurent Pinchart
2022-10-16  6:15 ` [PATCH v2 13/20] media: i2c: imx290: Fix max gain value Laurent Pinchart
2022-10-16  6:15 ` [PATCH v2 14/20] media: i2c: imx290: Split control initialization to separate function Laurent Pinchart
2022-10-16  6:15 ` [PATCH v2 15/20] media: i2c: imx290: Implement HBLANK and VBLANK controls Laurent Pinchart
2022-10-16  6:15 ` [PATCH v2 16/20] media: i2c: imx290: Create controls for fwnode properties Laurent Pinchart
2022-10-16  6:15 ` [PATCH v2 17/20] media: i2c: imx290: Move registers with fixed value to init array Laurent Pinchart
2022-10-17  5:52   ` Alexander Stein
2022-10-16  6:15 ` [PATCH v2 18/20] media: i2c: imx290: Factor out format retrieval to separate function Laurent Pinchart
2022-10-17  5:55   ` Alexander Stein [this message]
2022-10-17  8:37     ` Laurent Pinchart
2022-10-16  6:15 ` [PATCH v2 19/20] media: i2c: imx290: Add crop selection targets support Laurent Pinchart
2022-10-16  6:15 ` [PATCH v2 20/20] media: i2c: imx290: Replace GAIN control with ANALOGUE_GAIN Laurent Pinchart

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=5869053.lOV4Wx5bFT@steina-w \
    --to=alexander.stein@ew.tq-group.com \
    --cc=dave.stevenson@raspberrypi.com \
    --cc=laurent.pinchart@ideasonboard.com \
    --cc=linux-media@vger.kernel.org \
    --cc=mani@kernel.org \
    --cc=sakari.ailus@iki.fi \
    /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