Re: [PATCH 04/10] iio: adc: stm32-adc: Validate channel index before writing chan_name

From: Andy Shevchenko

Date: Thu Nov 19 2026 - 12:24:46 EST


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.

> + "Invalid channel %u\n", val);
> +
> ret = fwnode_property_read_string(child, "label", &name);

--
With Best Regards,
Andy Shevchenko