Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

iio: adc: stm32-adc: skip adc-diff-channels setup if none is present

If no adc differential channels are defined driver will fail with EINVAL:
stm32-adc: probe of 48003000.adc:adc@0 failed with error -22

Fix this by skipping the initialization if no channels are defined.

This applies only to the legacy way of initializing adc channels.

Fixes: d7705f35448a ("iio: adc: stm32-adc: convert to device properties")
Signed-off-by: Sean Nyekjaer <sean@geanix.com>
Link: https://lore.kernel.org/r/20230503162029.3654093-1-sean@geanix.com
Cc: <Stable@vger.kernel.org>
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>

authored by

Sean Nyekjaer and committed by
Jonathan Cameron
9c0d6ccd e55245d1

+9 -10
+9 -10
drivers/iio/adc/stm32-adc.c
··· 2006 2006 * to get the *real* number of channels. 2007 2007 */ 2008 2008 ret = device_property_count_u32(dev, "st,adc-diff-channels"); 2009 - if (ret < 0) 2010 - return ret; 2011 - 2012 - ret /= (int)(sizeof(struct stm32_adc_diff_channel) / sizeof(u32)); 2013 - if (ret > adc_info->max_channels) { 2014 - dev_err(&indio_dev->dev, "Bad st,adc-diff-channels?\n"); 2015 - return -EINVAL; 2016 - } else if (ret > 0) { 2017 - adc->num_diff = ret; 2018 - num_channels += ret; 2009 + if (ret > 0) { 2010 + ret /= (int)(sizeof(struct stm32_adc_diff_channel) / sizeof(u32)); 2011 + if (ret > adc_info->max_channels) { 2012 + dev_err(&indio_dev->dev, "Bad st,adc-diff-channels?\n"); 2013 + return -EINVAL; 2014 + } else if (ret > 0) { 2015 + adc->num_diff = ret; 2016 + num_channels += ret; 2017 + } 2019 2018 } 2020 2019 2021 2020 /* Optional sample time is provided either for each, or all channels */