Re: [PATCH 04/10] iio: adc: stm32-adc: Validate channel index before writing chan_name
From: Jonathan Cameron
Date: Sat Nov 21 2026 - 17:46:06 EST
On Fri, 20 Nov 2026 18:22:26 +0100
Fabrice Gasnier <fabrice.gasnier@xxxxxxxxxxx> wrote:
> On 11/19/26 18:24, Andy Shevchenko wrote:
> > On Thu, Nov 19, 2026 at 03:30:37PM +0000, Lee Jones wrote:
> >> stm32_adc_generic_chan_init() reads the child node's reg property into a
> >> signed int and, when the optional label property is present, writes into
> >> adc->chan_name[val] and calls stm32_adc_populate_int_ch() before
> >> checking whether val exceeds adc_info->max_channels. Because val is
> >> signed, values with the top bit set also become negative and bypass the
> >> upper-bound check altogether.
> >>
> >> Store val as a u32, matching fwnode_property_read_u32(), and move the
> >> max_channels bounds check immediately after reading reg.
> >
> > ...
> >
> >> + if (val >= adc_info->max_channels)
> >> + return dev_err_probe(dev, -EINVAL,
> >
> > -ECHRNG
> >
> > However it seems in the original code like this.
>
> Hi Lee, Andy
>
> I've no strong opinion on this remark, whether to change the error code here, and if it belongs to
> this fix ?
>
> In all case,
>
> Acked-by: Fabrice Gasnier <fabrice.gasnier@xxxxxxxxxxx>
Let us not over think it.
Applied. Given it's hardening against a bad DT, not rushing this one in.
It can wait for the next merge window.
Thanks,
Jonathan
>
> Best Regards,
> Thanks,
> Fabrice
> >
> >> + "Invalid channel %u\n", val);
> >> +
> >> ret = fwnode_property_read_string(child, "label", &name);
> >
>
>