All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Guoniu Zhou" <guoniu.zhou@oss.nxp.com>
Cc: robh@kernel.org, conor+dt@kernel.org, Frank.Li@kernel.org,
	imx@lists.linux.dev, devicetree@vger.kernel.org
Subject: Re: [PATCH v4 1/6] media: synopsys: Fix IPI using hardcoded datatype
Date: Tue, 19 May 2026 02:42:23 +0000	[thread overview]
Message-ID: <20260519024223.B45A4C2BCB7@smtp.kernel.org> (raw)
In-Reply-To: <20260519-csi2_imx95-v4-1-84ea4bb78a88@oss.nxp.com>

Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
- [High] If userspace starts streaming without explicitly calling `VIDIOC_SUBDEV_S_FMT`, the driver will use an incorrect hardware datatype due to a mismatch between the probe-time pointer and the V4L2 default state.
- [High] Caching the active format in a device-global pointer (`csi2->formats`) during `set_fmt` circumvents the V4L2 subdev state API, causing state corruption and hardware misconfiguration when multiple streams are used.
- [Medium] The patch confusingly repurposes an array pointer (`csi2->formats`) into a single active state pointer, while retaining its paired array-bounds variable.
--

commit ac0f1e2d8d5a5aefaf04a50efcbfbc4c7693090d
Author: Guoniu Zhou <guoniu.zhou@oss.nxp.com>

media: synopsys: Fix IPI using hardcoded datatype

This commit updates the set_fmt callback to reflect the negotiated active
format by storing it in csi2->formats. This ensures the IPI configuration
matches the runtime datatype instead of the probe-time default.

> diff --git a/drivers/media/platform/synopsys/dw-mipi-csi2rx.c b/drivers/media/platform/synopsys/dw-mipi-csi2rx.c
> index 02eb4a6cafade..0b80e84983f9e 100644
> --- a/drivers/media/platform/synopsys/dw-mipi-csi2rx.c
> +++ b/drivers/media/platform/synopsys/dw-mipi-csi2rx.c
> @@ -311,7 +311,7 @@ dw_mipi_csi2rx_find_format(struct dw_mipi_csi2rx_device *csi2, u32 mbus_code)
>  	WARN_ON(csi2->formats_num == 0);
>  
>  	for (unsigned int i = 0; i < csi2->formats_num; i++) {
> -		const struct dw_mipi_csi2rx_format *format = &csi2->formats[i];
> +		const struct dw_mipi_csi2rx_format *format = &formats[i];

Does this repurpose the csi2->formats array pointer to store a single active
format, while leaving csi2->formats_num as the array length?

This decouples the pointer from its length variable. Iterating over a global
formats array instead of the instance fields might also bypass device
encapsulation and create a semantic mismatch.

[ ... ]

> @@ -470,6 +470,17 @@ static int dw_mipi_csi2rx_set_fmt(struct v4l2_subdev *sd,
>  
>  	*src = *sink;
>  
> +	/* Store the CSIS format descriptor for active formats. */
> +	if (format->which == V4L2_SUBDEV_FORMAT_ACTIVE) {
> +		csi2->formats = fmt ? :
> +			dw_mipi_csi2rx_find_format(csi2, default_format.code);

Does caching the active format in a device-global pointer (csi2->formats)
circumvent the V4L2 subdev state API?

If multiple streams are configured via V4L2_SUBDEV_FL_STREAMS, it appears this
single pointer would be repeatedly overwritten, storing only the format of the
last configured stream.

Could this create a regression when the streams are enabled? The hardware would
be programmed with this last format, which could cause issues for any streams
that negotiated a different format. Would it be better to retrieve the active
format dynamically from sd->active_state via v4l2_subdev_state_get_format()
during stream enablement?

Additionally, does this introduce a regression if userspace starts streaming
without explicitly calling VIDIOC_SUBDEV_S_FMT?

During probe, csi2->formats is initialized to the base of the formats array,
pointing to the first element (MEDIA_BUS_FMT_YUYV8_1X16). The V4L2 subdev
active state is initialized to default_format (MEDIA_BUS_FMT_SRGGB10_1X10).

If set_fmt(ACTIVE) is never called, csi2->formats is never updated. The
hardware would then be configured for YUV422_8B instead of the expected RAW10,
causing a mismatch between the active V4L2 state and the actual hardware
configuration.

> +		if (!csi2->formats) {
> +			dev_err(csi2->dev, "Failed to find valid format\n");
> +			return -EINVAL;
> +		}
> +	}
> +
>  	return 0;
>  }

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260519-csi2_imx95-v4-0-84ea4bb78a88@oss.nxp.com?part=1

  reply	other threads:[~2026-05-19  2:42 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-19  2:07 [PATCH v4 0/6] media: synopsys: enhancements and i.MX95 support Guoniu Zhou
2026-05-19  2:07 ` Guoniu Zhou
2026-05-19  2:07 ` [PATCH v4 1/6] media: synopsys: Fix IPI using hardcoded datatype Guoniu Zhou
2026-05-19  2:07   ` Guoniu Zhou
2026-05-19  2:42   ` sashiko-bot [this message]
2026-05-19  2:07 ` [PATCH v4 2/6] media: synopsys: Add support for RAW16 Bayer formats Guoniu Zhou
2026-05-19  2:07   ` Guoniu Zhou
2026-05-19  2:07 ` [PATCH v4 3/6] media: synopsys: Add support for multiple streams Guoniu Zhou
2026-05-19  2:07   ` Guoniu Zhou
2026-05-19  3:37   ` sashiko-bot
2026-05-19  2:07 ` [PATCH v4 4/6] media: synopsys: Add PHY stopstate wait for i.MX93 Guoniu Zhou
2026-05-19  2:07   ` Guoniu Zhou
2026-05-19  4:01   ` sashiko-bot
2026-05-20 11:12   ` Alexander Stein
2026-05-20 11:12     ` Alexander Stein
2026-05-21  9:29     ` G.N. Zhou (OSS)
2026-05-21  9:29       ` G.N. Zhou (OSS)
2026-05-21 11:52       ` Alexander Stein
2026-05-21 11:52         ` Alexander Stein
2026-05-22  1:58         ` G.N. Zhou (OSS)
2026-05-22  1:58           ` G.N. Zhou (OSS)
2026-05-22 12:02           ` Alexander Stein
2026-05-22 12:02             ` Alexander Stein
2026-05-19  2:07 ` [PATCH v4 5/6] media: dt-bindings: add NXP i.MX95 compatible string Guoniu Zhou
2026-05-19  2:07   ` Guoniu Zhou
2026-05-19  2:07 ` [PATCH v4 6/6] media: synopsys: Add support for i.MX95 Guoniu Zhou
2026-05-19  2:07   ` Guoniu Zhou

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=20260519024223.B45A4C2BCB7@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=Frank.Li@kernel.org \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=guoniu.zhou@oss.nxp.com \
    --cc=imx@lists.linux.dev \
    --cc=robh@kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.