* [PATCH v4] iio: adc: mt6359: fix unchecked return value in mt6358_read_imp
@ 2026-04-27 20:12 Salah Triki
2026-04-28 16:09 ` Jonathan Cameron
0 siblings, 1 reply; 2+ messages in thread
From: Salah Triki @ 2026-04-27 20:12 UTC (permalink / raw)
To: Jonathan Cameron, David Lechner, Nuno Sá, Andy Shevchenko,
Matthias Brugger, AngeloGioacchino Del Regno
Cc: linux-iio, linux-kernel, linux-arm-kernel, linux-mediatek,
Salah Triki
In mt6358_read_imp(), the variable val_v is passed to regmap_read()
but the return value is not checked. If the read fails, val_v remains
uninitialized and its random stack content is subsequently reported
as a measurement result.
Initialize val_v to zero to ensure a predictable value is reported
in case of bus failure and to prevent potential stack data leakage.
This also satisfies static analyzers that might otherwise flag the
variable as used uninitialized.
Fixes: 3587914bf61 ("iio: adc: Add support for MediaTek MT6357/8/9 Auxiliary ADC")
Signed-off-by: Salah Triki <salah.triki@gmail.com>
---
Changes in v4:
- Move val_v initialization just before regmap_read() call as suggested
by Andy Shevchenko to improve maintainability.
Changes in v3:
- Initialize val_v to zero at declaration instead of checking regmap_read()
return value, as suggested by Jonathan Cameron and Andy Shevchenko.
- Update commit message to reflect this new approach
Changes in v2:
- Added Fixes tag.
- Re-examined the entire driver for unchecked regmap operations.
While several regmap_write() and regmap_set_bits() calls also ignore
return values, I focused on this specific regmap_read() in
mt6358_read_imp() because it leads to an uninitialized variable usage
(val_v). This makes this fix critical for reporting correct data
to userspace
drivers/iio/adc/mt6359-auxadc.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/drivers/iio/adc/mt6359-auxadc.c b/drivers/iio/adc/mt6359-auxadc.c
index 6b9ed9b1fde2..1d9724ef0983 100644
--- a/drivers/iio/adc/mt6359-auxadc.c
+++ b/drivers/iio/adc/mt6359-auxadc.c
@@ -497,6 +497,7 @@ static int mt6358_read_imp(struct mt6359_auxadc *adc_dev,
return ret;
/* Read the params before stopping */
+ val_v = 0;
regmap_read(regmap, reg_adc0 + (cinfo->imp_adc_num << 1), &val_v);
mt6358_stop_imp_conv(adc_dev);
--
2.43.0
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [PATCH v4] iio: adc: mt6359: fix unchecked return value in mt6358_read_imp
2026-04-27 20:12 [PATCH v4] iio: adc: mt6359: fix unchecked return value in mt6358_read_imp Salah Triki
@ 2026-04-28 16:09 ` Jonathan Cameron
0 siblings, 0 replies; 2+ messages in thread
From: Jonathan Cameron @ 2026-04-28 16:09 UTC (permalink / raw)
To: Salah Triki
Cc: David Lechner, Nuno Sá, Andy Shevchenko, Matthias Brugger,
AngeloGioacchino Del Regno, linux-iio, linux-kernel,
linux-arm-kernel, linux-mediatek
On Mon, 27 Apr 2026 21:12:38 +0100
Salah Triki <salah.triki@gmail.com> wrote:
> In mt6358_read_imp(), the variable val_v is passed to regmap_read()
> but the return value is not checked. If the read fails, val_v remains
> uninitialized and its random stack content is subsequently reported
> as a measurement result.
>
> Initialize val_v to zero to ensure a predictable value is reported
> in case of bus failure and to prevent potential stack data leakage.
> This also satisfies static analyzers that might otherwise flag the
> variable as used uninitialized.
>
> Fixes: 3587914bf61 ("iio: adc: Add support for MediaTek MT6357/8/9 Auxiliary ADC")
> Signed-off-by: Salah Triki <salah.triki@gmail.com>
Applied and marked for stable. Risk of this occurring is very low, but
the risk of the patch causing trouble is effectively zero so I'm fine
with this being backported.
Thanks
Jonathan
> ---
> Changes in v4:
> - Move val_v initialization just before regmap_read() call as suggested
> by Andy Shevchenko to improve maintainability.
>
> Changes in v3:
> - Initialize val_v to zero at declaration instead of checking regmap_read()
> return value, as suggested by Jonathan Cameron and Andy Shevchenko.
> - Update commit message to reflect this new approach
>
> Changes in v2:
> - Added Fixes tag.
> - Re-examined the entire driver for unchecked regmap operations.
> While several regmap_write() and regmap_set_bits() calls also ignore
> return values, I focused on this specific regmap_read() in
> mt6358_read_imp() because it leads to an uninitialized variable usage
> (val_v). This makes this fix critical for reporting correct data
> to userspace
>
> drivers/iio/adc/mt6359-auxadc.c | 1 +
> 1 file changed, 1 insertion(+)
>
> diff --git a/drivers/iio/adc/mt6359-auxadc.c b/drivers/iio/adc/mt6359-auxadc.c
> index 6b9ed9b1fde2..1d9724ef0983 100644
> --- a/drivers/iio/adc/mt6359-auxadc.c
> +++ b/drivers/iio/adc/mt6359-auxadc.c
> @@ -497,6 +497,7 @@ static int mt6358_read_imp(struct mt6359_auxadc *adc_dev,
> return ret;
>
> /* Read the params before stopping */
> + val_v = 0;
> regmap_read(regmap, reg_adc0 + (cinfo->imp_adc_num << 1), &val_v);
>
> mt6358_stop_imp_conv(adc_dev);
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-04-28 16:09 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-04-27 20:12 [PATCH v4] iio: adc: mt6359: fix unchecked return value in mt6358_read_imp Salah Triki
2026-04-28 16:09 ` Jonathan Cameron
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox