Devicetree
 help / color / mirror / Atom feed
From: Jacopo Mondi <jacopo.mondi@ideasonboard.com>
To: Jai Luthra <jai.luthra@ideasonboard.com>
Cc: Jacopo Mondi <jacopo.mondi@ideasonboard.com>,
	 sashiko-reviews@lists.linux.dev, conor+dt@kernel.org,
	robh@kernel.org, devicetree@vger.kernel.org,
	 media-ci@linuxtv.org,
	Philippe Baetens <philippebaetens@gmail.com>,
	 kieran bingham <kieran.bingham@ideasonboard.com>
Subject: Re: [PATCH v5 2/2] media: i2c: Add driver for AMSOSRMA Mira220
Date: Tue, 21 Jul 2026 22:03:07 +0200	[thread overview]
Message-ID: <al_Ptq4ICRLhsXb_@zed> (raw)
In-Reply-To: <178465132119.3005206.14389356633093852393@freya>

Hi Jai

On Tue, Jul 21, 2026 at 09:58:41PM +0530, Jai Luthra wrote:
> Hi Jacopo,
>
> Quoting Jacopo Mondi (2026-07-21 21:37:59)
> > Hi Sashiko
> >
> > On Tue, Jul 21, 2026 at 02:36:14PM +0000, sashiko-bot@kernel.org wrote:
> > > Thank you for your contribution! Sashiko AI review found 11 potential issue(s) to consider:
> > > - [High] Dereferencing `mira220->vblank` without checking for NULL in `mira220_init_controls()`.
> > > - [High] Missing `v4l2_subdev_cleanup()` in the driver's remove function causes an active state memory leak.
> > > - [Medium] The uninitialized stack variable `id` is evaluated and logged without checking if the I2C read succeeded.
> > > - [Medium] The active state format code is not updated when `V4L2_CID_HFLIP` or `V4L2_CID_VFLIP` are modified.
> > > - [Medium] Exposure control maximum limit exceeds the 16-bit hardware register width, leading to silent truncation.
> > > - [Medium] Hardware exposure register is not updated when `V4L2_CID_EXPOSURE` is clamped due to a `V4L2_CID_VBLANK` change.
> > > - [Medium] `mira220_power_on()` discards the actual error code when `clk_prepare_enable()` fails.
> > > - [Medium] Missing runtime PM reference hold during probe exposes the device to concurrent suspend.
> > > - [Medium] The error path in probe unconditionally powers off the device without checking its runtime PM state.
> > > - [Medium] V4L2_CID_HBLANK reports an incorrect static value when using a 1-lane MIPI CSI-2 configuration, breaking user-space framerate and exposure calculations.
> > > - [Low] Typo in user-facing control menu item: 'Vertial Gradient' instead of 'Vertical Gradient'.
> > > --
>
> [...]
>
> > > @@ -1936,6 +1936,6 @@ static int mira220_probe(struct i2c_client *client)
> > > [ ... ]
> > > > +   /* Enable runtime PM and turn off the device */
> > > > +   pm_runtime_set_autosuspend_delay(dev, 1000);
> > > > +   pm_runtime_use_autosuspend(dev);
> > > > +   pm_runtime_set_active(dev);
> > > > +   pm_runtime_enable(dev);
> > > > +
> > > > +   ret = mira220_identify_module(mira220);
> > >
> > > [Severity: Medium]
> > > Is it possible for the device to be concurrently suspended while probe
> > > continues?
> > >
> > > The device is marked active with a usage count of 0 after pm_runtime_enable().
> > > If the PM subsystem or userspace triggers a suspend (e.g. by setting
> > > autosuspend_delay_ms=0), the device could be powered down while probe executes
> > > mira220_identify_module().
> > >
> > > This could lead to I2C timeouts or bus crashes. Taking a pm_runtime reference
> > > hold could prevent this.
> > >
> >
> > By calling pm_runtime_get_noresume() (as the device is powered up
> > already) ?
> >
> >
> > > @@ -1985,5 +1985,5 @@ static int mira220_probe(struct i2c_client *client)
> > > [ ... ]
> > > > +error_power_off:
> > > > +   pm_runtime_disable(dev);
> > > > +   mira220_power_off(dev);
> > > > +   pm_runtime_set_suspended(dev);
> > > > +   return ret;
> > > > +}
> > >
> > > [Severity: Medium]
> > > Should this error path check the runtime PM state before unconditionally
> > > powering off the device?
> > >
> > > The PM core might have already suspended the device due to the zero usage count.
> > >
> > > Calling mira220_power_off() unconditionally could redundantly disable clocks
> > > and regulators that are already disabled, potentially causing double-disable
> > > warnings.
> > >
> >
> > Only in the case some suspend went on during probe. Even if unlikely,
> > guarding the call with
> >
> >         if (!pm_runtime_status_suspended(&client->dev))
> >                 mira220_power_off(&client->dev);
> >
> > costs nothing
> >
>
> For the above two issues it would be simpler to move the autosuspend just
> before you return from probe:
>
>     pm_runtime_set_active(dev)
>     pm_runtime_enable(dev)
>
>     ... rest of probe ..
>
>     pm_runtime_idle(dev)
>     pm_runtime_set_autosuspend_delay(dev, 1000);
>     pm_runtime_use_autosuspend(dev);
>
>     return 0;
>
> I saw this pattern in imx219/imx708 (sashiko was happy with this part in
>                                      the imx708 series I posted last week)
>

This is a good suggestion.

To be honest the comment

--------------------------------------------------------------------------------
@ -1936,6 +1936,6 @@ static int mira220_probe(struct i2c_client *client)
[ ... ]
> +     /* Enable runtime PM and turn off the device */
> +     pm_runtime_set_autosuspend_delay(dev, 1000);
> +     pm_runtime_use_autosuspend(dev);
> +     pm_runtime_set_active(dev);
> +     pm_runtime_enable(dev);
> +
> +     ret = mira220_identify_module(mira220);

[Severity: Medium]
Is it possible for the device to be concurrently suspended while probe
continues?

The device is marked active with a usage count of 0 after pm_runtime_enable().
If the PM subsystem or userspace triggers a suspend (e.g. by setting
autosuspend_delay_ms=0), the device could be powered down while probe executes
mira220_identify_module().
--------------------------------------------------------------------------------

Does mention "userspace triggering a suspend" (a system suspend?)
which seem to imply might happen concurrently to the driver probing
even if the device doesn't use autosuspend..

I feel like I should take your suggestion in and ignore the case of
system-suspend-while-probing ?


> Thanks,
>     Jai

      reply	other threads:[~2026-07-21 20:03 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-21 14:18 [PATCH v5 0/2] media: i2c: Add driver for Mira220 Jacopo Mondi
2026-07-21 14:18 ` [PATCH v5 1/2] dt-bindings: media: i2c: Add mira220 image sensor Jacopo Mondi
2026-07-21 14:25   ` sashiko-bot
2026-07-21 14:18 ` [PATCH v5 2/2] media: i2c: Add driver for AMSOSRMA Mira220 Jacopo Mondi
2026-07-21 14:36   ` sashiko-bot
2026-07-21 16:07     ` Jacopo Mondi
2026-07-21 16:28       ` Jai Luthra
2026-07-21 20:03         ` Jacopo Mondi [this message]

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=al_Ptq4ICRLhsXb_@zed \
    --to=jacopo.mondi@ideasonboard.com \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=jai.luthra@ideasonboard.com \
    --cc=kieran.bingham@ideasonboard.com \
    --cc=media-ci@linuxtv.org \
    --cc=philippebaetens@gmail.com \
    --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