[PATCH v4 2/2] iio: adc: Add Nuvoton MA35D1 EADC driver
Victor Chernyakin
chernyakin.victor.j at outlook.com
Tue Nov 10 18:08:03 PST 2026
> +static void ma35d1_adc_trigger_capture(struct iio_poll_func *pf)
> +{
> + struct iio_dev *indio_dev = pf->indio_dev;
> + struct ma35d1_adc *adc = iio_priv(indio_dev);
> + struct {
> + u16 channel;
> + aligned_s64 timestamp;
> + } scan = { };
> + u16 raw;
> + int ret;
> +
> + guard(mutex)(&adc->lock);
> +
> + if (adc->suspended || !adc->scan_chan)
> + return;
> +
> + ret = ma35d1_adc_read_conversion(adc, adc->scan_chan, &raw);
> + if (ret)
> + return;
> +
> + scan.channel = raw;
> + iio_push_to_buffers_with_ts(indio_dev, &scan, sizeof(scan), pf->timestamp);
> +}
Do you need 'raw'? Seems like you could read into scan.channel directly:
ret = ma35d1_adc_read_conversion(adc, adc->scan_chan, &scan.channel);
> + num_channels = device_get_child_node_count(dev);
> + 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.
More information about the linux-arm-kernel
mailing list