Re: [PATCH 04/10] iio: adc: stm32-adc: Validate channel index before writing chan_name
From: Fabrice Gasnier
Date: Fri Nov 20 2026 - 12:24:22 EST
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>
Best Regards,
Thanks,
Fabrice
>
>> + "Invalid channel %u\n", val);
>> +
>> ret = fwnode_property_read_string(child, "label", &name);
>