From: Lee Jones <lee@kernel.org>
To: Pengpeng Hou <pengpeng@iscas.ac.cn>
Cc: patches@opensource.cirrus.com, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] mfd: wm8350: return an error for AUXADC timeouts
Date: Thu, 2 Jul 2026 17:00:19 +0100 [thread overview]
Message-ID: <20260702160019.GZ2108533@google.com> (raw)
In-Reply-To: <20260624144227.75230-1-pengpeng@iscas.ac.cn>
Please take this into consideration:
/* Sashiko Automation: Issues Found (3 Findings) */
On Wed, 24 Jun 2026, Pengpeng Hou wrote:
> wm8350_read_auxadc() logs when the AUXADC poll bit remains set after the
> conversion wait, but still returns result, which remains zero when no
> conversion result was read.
>
> Return -ETIMEDOUT after turning the ADC back off and releasing
> auxadc_mutex so callers do not treat a timed out conversion as a valid
> zero sample.
>
> Signed-off-by: Pengpeng Hou <pengpeng@iscas.ac.cn>
> ---
> drivers/mfd/wm8350-core.c | 10 ++++++++--
> 1 file changed, 8 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/mfd/wm8350-core.c b/drivers/mfd/wm8350-core.c
> index fbc77b218..214826e16 100644
> --- a/drivers/mfd/wm8350-core.c
> +++ b/drivers/mfd/wm8350-core.c
> @@ -188,6 +188,7 @@ EXPORT_SYMBOL_GPL(wm8350_reg_unlock);
> int wm8350_read_auxadc(struct wm8350 *wm8350, int channel, int scale, int vref)
> {
> u16 reg, result = 0;
> + int ret = 0;
>
> if (channel < WM8350_AUXADC_AUX1 || channel > WM8350_AUXADC_TEMP)
> return -EINVAL;
> @@ -221,11 +222,13 @@ int wm8350_read_auxadc(struct wm8350 *wm8350, int channel, int scale, int vref)
> wait_for_completion_timeout(&wm8350->auxadc_done, msecs_to_jiffies(5));
>
> reg = wm8350_reg_read(wm8350, WM8350_DIGITISER_CONTROL_1);
> - if (reg & WM8350_AUXADC_POLL)
> + if (reg & WM8350_AUXADC_POLL) {
> dev_err(wm8350->dev, "adc chn %d read timeout\n", channel);
> - else
> + ret = -ETIMEDOUT;
> + } else {
> result = wm8350_reg_read(wm8350,
> WM8350_AUX1_READBACK + channel);
> + }
>
> /* Turn off the ADC */
> reg = wm8350_reg_read(wm8350, WM8350_POWER_MGMT_5);
[Severity: High]
This is a pre-existing issue, but does wm8350_reg_read() return uninitialized
memory if the underlying bus read fails?
drivers/mfd/wm8350-core.c:wm8350_reg_read() {
unsigned int data;
int err;
err = regmap_read(wm8350->regmap, reg, &data);
if (err)
dev_err(wm8350->dev, "read from reg R%d failed\n", reg);
return data;
}
If regmap_read() fails, the stack variable data is returned uninitialized,
and then written back to hardware:
reg = wm8350_reg_read(wm8350, WM8350_POWER_MGMT_5);
wm8350_reg_write(wm8350, WM8350_POWER_MGMT_5,
reg & ~WM8350_AUXADC_ENA);
Can this lead to unpredictable hardware state?
> @@ -234,6 +237,9 @@ int wm8350_read_auxadc(struct wm8350 *wm8350, int channel, int scale, int vref)
>
> mutex_unlock(&wm8350->auxadc_mutex);
>
> + if (ret)
> + return ret;
> +
[Severity: High]
Does returning an error code here cause callers to propagate negative voltages?
Since callers like show_voltage() in drivers/hwmon/wm8350-hwmon.c and
wm8350_read_battery_uvolts() in drivers/power/wm8350_power.c do not check for
negative error codes, they unconditionally multiply the return value:
drivers/hwmon/wm8350-hwmon.c:show_voltage() {
...
val = wm8350_read_auxadc(wm8350, channel, 0, 0) * WM8350_AUX_COEFF;
...
}
Will this cause mathematically meaningless negative values to be returned to
userspace via the power supply and hwmon frameworks?
> return result & WM8350_AUXADC_DATA1_MASK;
> }
> EXPORT_SYMBOL_GPL(wm8350_read_auxadc);
> --
> 2.50.1 (Apple Git-155)
>
--
Lee Jones
prev parent reply other threads:[~2026-07-02 16:00 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-24 14:42 [PATCH] mfd: wm8350: return an error for AUXADC timeouts Pengpeng Hou
2026-07-02 16:00 ` Lee Jones [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=20260702160019.GZ2108533@google.com \
--to=lee@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=patches@opensource.cirrus.com \
--cc=pengpeng@iscas.ac.cn \
/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