Devicetree
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Dave Stevenson" <dave.stevenson@raspberrypi.com>
Cc: devicetree@vger.kernel.org, robh@kernel.org, conor+dt@kernel.org,
	media-ci@linuxtv.org
Subject: Re: [PATCH v2 06/13] media: sony-starvis2: Allow runtime control of link frequency
Date: Tue, 13 Oct 2026 15:33:14 +0000	[thread overview]
Message-ID: <sashiko-outbox-170016@kernel.org> (raw)
In-Reply-To: <20261013-media-starvis2-v2-6-3670722d250a@raspberrypi.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] media: sony-starvis2: missing lock and NULL check for link_freq init
--

commit 54243fb94593be25be7c3f168bb8161959b863e5
Author: Dave Stevenson <dave.stevenson@raspberrypi.com>

media: sony-starvis2: Allow runtime control of link frequency

This commit connects V4L2_CID_LINK_FREQ to allow runtime configuration
of the link frequency when the sensor is not streaming.

> diff --git a/drivers/media/i2c/sony-starvis2.c b/drivers/media/i2c/sony-starvis2.c
> index 66c77c5957e32..2bb438d22ada0 100644
> --- a/drivers/media/i2c/sony-starvis2.c
> +++ b/drivers/media/i2c/sony-starvis2.c

[ ... ]

> @@ -1210,25 +1236,23 @@ static int starvis2_init_controls(struct starvis2 *starvis2)
>  
>  	starvis2->vmax = starvis2->variant->vmax_default;
>  
> -	hmax = variant->hmax_min_link_freq[__fls(starvis2->link_freq_bitmap)];
> -	if (starvis2->lane_mode == STARVIS2_LANEMODE_4L)
> -		hmax = max(hmax >> 1, variant->hmax_min_pixel_array);
> -
>  	/* PIXEL_RATE is fixed and read-only */
>  	v4l2_ctrl_new_std(ctrl_hdlr, &starvis2_ctrl_ops, V4L2_CID_PIXEL_RATE,
>  			  starvis2->variant->pixel_rate,
>  			  starvis2->variant->pixel_rate, 1,
>  			  starvis2->variant->pixel_rate);
>  
> -	/* LINK_FREQ is also read only */
> -	link_freq = v4l2_ctrl_new_int_menu(ctrl_hdlr, &starvis2_ctrl_ops,
> -					   V4L2_CID_LINK_FREQ,
> -					   ARRAY_SIZE(link_freqs) - 1,
> -					   __ffs(starvis2->link_freq_bitmap),
> -					   link_freqs);
> -
> -	if (link_freq)
> -		link_freq->flags |= V4L2_CTRL_FLAG_READ_ONLY;
> +	starvis2->link_freq =
> +		v4l2_ctrl_new_int_menu(ctrl_hdlr, &starvis2_ctrl_ops,
> +				       V4L2_CID_LINK_FREQ,
> +				       __fls(starvis2->link_freq_bitmap),
> +				       __ffs(starvis2->link_freq_bitmap),
> +				       link_freqs);
> +	__v4l2_ctrl_modify_range(starvis2->link_freq,
> +				 __ffs(starvis2->link_freq_bitmap),
> +				 __fls(starvis2->link_freq_bitmap),
> +				 ~(starvis2->link_freq_bitmap),
> +				 __ffs(starvis2->link_freq_bitmap));

[Severity: High]
Does this code pass starvis2->link_freq to __v4l2_ctrl_modify_range() without
checking if it is NULL? If v4l2_ctrl_new_int_menu() fails to allocate memory,
it returns NULL, which would cause a NULL pointer dereference when
__v4l2_ctrl_modify_range() accesses ctrl->handler.

Also, is it safe to call __v4l2_ctrl_modify_range() in starvis2_init_controls()
without holding the control handler lock? This unlocked variant expects the
handler lock to be held, which will trigger a lockdep assertion failure. Should
this code use the locked variant v4l2_ctrl_modify_range() instead?

>  	vblank = starvis2->vmax - starvis2->variant->active_area.height;
>  	max_vblank = STARVIS2_VMAX_MAX - starvis2->variant->active_area.height;
> @@ -1236,6 +1260,10 @@ static int starvis2_init_controls(struct starvis2 *starvis2)
>  					     V4L2_CID_VBLANK, vblank, max_vblank,
>  					     2, vblank);
>  
> +	hmax = variant->hmax_min_link_freq[starvis2->link_freq->val];

[Severity: High]
Can this cause a NULL pointer dereference if starvis2->link_freq is NULL?
It appears this accesses the val field without a prior check.

> +	if (starvis2->lane_mode == STARVIS2_LANEMODE_4L)
> +		hmax = max(hmax >> 1, variant->hmax_min_pixel_array);
> +

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261013-media-starvis2-v2-0-3670722d250a@raspberrypi.com?part=6

  reply	other threads:[~2026-10-13 15:33 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-13 15:16 [PATCH v2 00/13] Update imx678 to act as a common Sony Starvis 2 driver Dave Stevenson
2026-10-13 15:17 ` [PATCH v2 01/13] media: imx678: Rework into generic Starvis 2 sensor driver Dave Stevenson
2026-10-13 15:32   ` sashiko-bot
2026-10-13 15:17 ` [PATCH v2 02/13] media: sony-starvis2: Reorder link frequencies to remove lookup Dave Stevenson
2026-10-13 15:17 ` [PATCH v2 03/13] media: sony-starvis2: Always program the sensor in window mode Dave Stevenson
2026-10-13 15:17 ` [PATCH v2 04/13] media: sony-starvis2: Parameterise the configuration to allow for other models Dave Stevenson
2026-10-13 15:35   ` sashiko-bot
2026-10-13 15:17 ` [PATCH v2 05/13] media: sony-starvis2: Rework 2 lane support for higher link freqs Dave Stevenson
2026-10-13 15:17 ` [PATCH v2 06/13] media: sony-starvis2: Allow runtime control of link frequency Dave Stevenson
2026-10-13 15:33   ` sashiko-bot [this message]
2026-10-13 15:17 ` [PATCH v2 07/13] media: sony-starvis2: Correct the minimum exposure Dave Stevenson
2026-10-13 15:17 ` [PATCH v2 08/13] media: dt-bindings: sony,imx678: Add other Starvis 2 family members Dave Stevenson
2026-10-13 15:17 ` [PATCH v2 09/13] media: sony-starvis2: Add support for IMX662 Dave Stevenson
2026-10-13 15:17 ` [PATCH v2 10/13] media: sony-starvis2: Add support for IMX675 Dave Stevenson
2026-10-13 15:17 ` [PATCH v2 11/13] media: sony-starvis2: Add support for IMX832 Dave Stevenson
2026-10-13 15:17 ` [PATCH v2 12/13] media: sony-starvis2: Only update bits for window mode Dave Stevenson
2026-10-13 15:17 ` [PATCH v2 13/13] media: sony-starvis2: Add support for IMX585 Dave Stevenson
2026-10-13 15:29   ` sashiko-bot

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=sashiko-outbox-170016@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=conor+dt@kernel.org \
    --cc=dave.stevenson@raspberrypi.com \
    --cc=devicetree@vger.kernel.org \
    --cc=media-ci@linuxtv.org \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox