[PATCH v4 2/2] iio: adc: Add Nuvoton MA35D1 EADC driver
Chi-Wen Weng
cwweng.linux at gmail.com
Wed Nov 11 17:26:00 PST 2026
Andy Shevchenko 於 2026/11/11 下午 10:05 寫道:
> On Tue, Nov 10, 2026 at 08:08:03PM -0600, Victor Chernyakin wrote:
>
> ...
>
>>> + if (!num_channels)
>>> + return dev_err_probe(dev, -ENOENT, "no ADC channels configured\n");
>>> +
>>> + if (num_channels > MA35D1_EADC_MAX_EXT_CHANNELS)
>>> + return dev_err_probe(dev, -ENOSPC, "too many ADC channels\n");
>>> +
>>> + channels = devm_kcalloc(dev, size_add(num_channels, 1),
>>> + sizeof(*channels), GFP_KERNEL);
>>
>> Couldn't size_add() just be regular +?
>> (Question to Andy who originally suggested it)
>> We've just checked that num_channels is small and won't overflow.
>
> While that's true, the other aspect(s) of this is in play. Namely we want to
> have the same pattern over the kernel that makes code robust (tomorrow some
> cases can be modified unnoticed with opening such an issue again) along with
> the potential of finding those patterns and update in case of mass-updates
> of low-level API, and I have heard for the matter of fact that devm_*alloc*()
> are in the plans to move to something like k*alloc_obj*() or k*alloc_flex().
>
Thanks Victor and Andy for the discussion.
I'll keep size_add() for consistency and future-proofing, as Andy suggested.
Thanks,
Chi-Wen
More information about the linux-arm-kernel
mailing list