Devicetree
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Pengyu Luo" <mitltlatltl@gmail.com>
Cc: imx@lists.linux.dev, Frank.Li@kernel.org, krzk+dt@kernel.org,
	conor+dt@kernel.org, devicetree@vger.kernel.org, robh@kernel.org
Subject: Re: [PATCH v4 1/5] media: hi846: fix hi846_write_reg_16 handling
Date: Tue, 12 May 2026 03:38:00 +0000	[thread overview]
Message-ID: <20260512033801.055CAC2BD05@smtp.kernel.org> (raw)
In-Reply-To: <20260511103927.279550-2-mitltlatltl@gmail.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] Runtime PM usage count underflow and torn hardware state due to unhandled negative return values.
--

commit a7e288159f9d9020f112e24280a1cf27c80c8fca
Author: Pengyu Luo <mitltlatltl@gmail.com>

media: hi846: fix hi846_write_reg_16 handling

This commit attempts to fix error propagation by resetting the error
variable to 0 when it is positive. It clears the positive return value
from pm_runtime_get_if_in_use() before performing I2C writes.

> diff --git a/drivers/media/i2c/hi846.c b/drivers/media/i2c/hi846.c
> index a3f77b8434ca7..7f069aca0fce5 100644
> --- a/drivers/media/i2c/hi846.c
> +++ b/drivers/media/i2c/hi846.c
> @@ -1271,6 +1271,8 @@ static void hi846_write_reg_16(struct hi846 *hi846, u16 reg, u16 val, int *err)
>  	if (*err < 0)
>  		return;
>  
> +	*err = 0;
> +

While this clears the positive return values from pm_runtime_get_if_in_use(),
does this leave negative return values unhandled in the caller?

If pm_runtime_get_if_in_use() in hi846_set_ctrl() returns a negative error
like -EINVAL when Runtime PM is disabled, the usage count is not incremented.
The check for (!ret || ret == -EAGAIN) fails, so execution falls through with
a negative value.

Because this negative value is passed into hi846_write_reg_16(), the check
just above this change will cause I2C writes to be silently skipped for
controls like V4L2_CID_EXPOSURE. Other controls like V4L2_CID_ANALOGUE_GAIN
might ignore the error and execute unconditionally, leaving the hardware in a
torn state.

Finally, since execution continues, pm_runtime_put() is called unconditionally
at the end of hi846_set_ctrl().

Because the usage count was never incremented for the negative error case,
will this cause a PM usage count underflow?

Would it be better to correctly validate the PM return value directly in
hi846_set_ctrl() with a check like if (ret <= 0) return 0; instead of
clearing the positive error here?

>  	put_unaligned_be16(reg, buf);
>  	put_unaligned_be16(val, buf + 2);

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260511103927.279550-1-mitltlatltl@gmail.com?part=1

  reply	other threads:[~2026-05-12  3:38 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-11 10:39 [PATCH v4 0/5] fix and improve for Hi846 Pengyu Luo
2026-05-11 10:39 ` [PATCH v4 1/5] media: hi846: fix hi846_write_reg_16 handling Pengyu Luo
2026-05-12  3:38   ` sashiko-bot [this message]
2026-05-11 10:39 ` [PATCH v4 2/5] media: hi846: fix link frequency handling Pengyu Luo
2026-05-12  4:08   ` sashiko-bot
2026-05-11 10:39 ` [PATCH v4 3/5] media: hi846: fix modes handling for different lane cases Pengyu Luo
2026-05-12  4:43   ` sashiko-bot
2026-05-11 10:39 ` [PATCH v4 4/5] media: hi846: Add 6MP and 8MP modes support Pengyu Luo
2026-05-12  5:13   ` sashiko-bot
2026-05-11 10:39 ` [PATCH v4 5/5] arm64: dts: imx8mq-librem5: Correct link frequency list Pengyu Luo
2026-05-12  5:45   ` 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=20260512033801.055CAC2BD05@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=Frank.Li@kernel.org \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=imx@lists.linux.dev \
    --cc=krzk+dt@kernel.org \
    --cc=mitltlatltl@gmail.com \
    --cc=robh@kernel.org \
    --cc=sashiko@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