From: Andy Shevchenko <andriy.shevchenko@intel.com>
To: Jonathan Cameron <jic23@kernel.org>
Cc: "Salah Triki" <salah.triki@gmail.com>,
"David Lechner" <dlechner@baylibre.com>,
"Nuno Sá" <nuno.sa@analog.com>,
"Andy Shevchenko" <andy@kernel.org>,
"Matthias Brugger" <matthias.bgg@gmail.com>,
"AngeloGioacchino Del Regno"
<angelogioacchino.delregno@collabora.com>,
linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-arm-kernel@lists.infradead.org,
linux-mediatek@lists.infradead.org
Subject: Re: [PATCH v2] iio: adc: mt6359: fix unchecked return value in mt6358_read_imp
Date: Mon, 27 Apr 2026 21:38:04 +0300 [thread overview]
Message-ID: <ae-tDFwxxTgTPayu@ashevche-desk.local> (raw)
In-Reply-To: <20260427181856.613a22ee@jic23-huawei>
On Mon, Apr 27, 2026 at 06:18:56PM +0100, Jonathan Cameron wrote:
> On Mon, 27 Apr 2026 17:57:59 +0100
> Salah Triki <salah.triki@gmail.com> wrote:
>
> > In mt6358_read_imp(), the return value of regmap_read() is currently
> > ignored. This is problematic because if the bus read fails the variable
> > val_v remains uninitialized.
> >
> > The function subsequently assigns this uninitialized stack value to
> > *vbat, leading to incorrect measurement results being reported to
> > the IIO subsystem without any error indication.
> >
> > Update the function to check the return value of regmap_read(). Ensure
> > that mt6358_stop_imp_conv() is still called to clean up the hardware
> > state before returning the error code.
> I'd be more concerned about what it might otherwise report.. Will expose
> something random that was on the stack previously.
>
> Ok on this one having a fixes tag given the uninitialized, though as I mentioned
> I'd have been tempted to take the approach of just initialising it.
>
> Even with the code as you have it here a static analyzer may not be able
> to see far enough to tell it is initialized and so throw false positive warnings.
True.
> Still, let's see what Andy thinks before you change anything.
...
> > /* Read the params before stopping */
> > - regmap_read(regmap, reg_adc0 + (cinfo->imp_adc_num << 1), &val_v);
> > + ret = regmap_read(regmap, reg_adc0 + (cinfo->imp_adc_num << 1), &val_v);
> > mt6358_stop_imp_conv(adc_dev);
This still uses unchecked IO.
> > + if (ret)
> > + return ret;
So, assume we got it right and error code is 0, but failed to stop conversion.
What would be the consequences?
As I said, the whole driver needs to be re-think of. If you going to check this
you need to add checks into _stop_imp_conv() which may lead to adding checks to
the complementary functions and it will go as a rabbit hole.
I agree with Jonathan that quick fix of initialising it explicitly with
a comment will be better approach taking into account the state of affairs
of this driver as a whole.
--
With Best Regards,
Andy Shevchenko
prev parent reply other threads:[~2026-04-27 18:38 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-27 16:57 [PATCH v2] iio: adc: mt6359: fix unchecked return value in mt6358_read_imp Salah Triki
2026-04-27 17:18 ` Jonathan Cameron
2026-04-27 18:38 ` Andy Shevchenko [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=ae-tDFwxxTgTPayu@ashevche-desk.local \
--to=andriy.shevchenko@intel.com \
--cc=andy@kernel.org \
--cc=angelogioacchino.delregno@collabora.com \
--cc=dlechner@baylibre.com \
--cc=jic23@kernel.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mediatek@lists.infradead.org \
--cc=matthias.bgg@gmail.com \
--cc=nuno.sa@analog.com \
--cc=salah.triki@gmail.com \
/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