Linux IIO development
 help / color / mirror / Atom feed
* [PATCH v2 1/2] iio: adc: stm32-adc: skip adc-diff-channels setup if none is present
@ 2023-04-21 11:35 Sean Nyekjaer
  2023-04-21 11:35 ` [PATCH v2 2/2] iio: adc: stm32-adc: skip adc-channels " Sean Nyekjaer
  0 siblings, 1 reply; 4+ messages in thread
From: Sean Nyekjaer @ 2023-04-21 11:35 UTC (permalink / raw)
  To: jic23, olivier.moysan, alexandre.torgue, nuno.sa
  Cc: Sean Nyekjaer, linux-iio, linux-stm32

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>
---
Changes since v1:
 - None

 drivers/iio/adc/stm32-adc.c | 19 +++++++++----------
 1 file changed, 9 insertions(+), 10 deletions(-)

diff --git a/drivers/iio/adc/stm32-adc.c b/drivers/iio/adc/stm32-adc.c
index e179b6611e4d..14524c1b5583 100644
--- a/drivers/iio/adc/stm32-adc.c
+++ b/drivers/iio/adc/stm32-adc.c
@@ -2008,16 +2008,15 @@ static int stm32_adc_get_legacy_chan_count(struct iio_dev *indio_dev, struct stm
 	 * to get the *real* number of channels.
 	 */
 	ret = device_property_count_u32(dev, "st,adc-diff-channels");
-	if (ret < 0)
-		return ret;
-
-	ret /= (int)(sizeof(struct stm32_adc_diff_channel) / sizeof(u32));
-	if (ret > adc_info->max_channels) {
-		dev_err(&indio_dev->dev, "Bad st,adc-diff-channels?\n");
-		return -EINVAL;
-	} else if (ret > 0) {
-		adc->num_diff = ret;
-		num_channels += ret;
+	if (ret > 0) {
+		ret /= (int)(sizeof(struct stm32_adc_diff_channel) / sizeof(u32));
+		if (ret > adc_info->max_channels) {
+			dev_err(&indio_dev->dev, "Bad st,adc-diff-channels?\n");
+			return -EINVAL;
+		} else if (ret > 0) {
+			adc->num_diff = ret;
+			num_channels += ret;
+		}
 	}
 
 	/* Optional sample time is provided either for each, or all channels */
-- 
2.40.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2023-05-02 14:45 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-04-21 11:35 [PATCH v2 1/2] iio: adc: stm32-adc: skip adc-diff-channels setup if none is present Sean Nyekjaer
2023-04-21 11:35 ` [PATCH v2 2/2] iio: adc: stm32-adc: skip adc-channels " Sean Nyekjaer
2023-05-01 16:09   ` Jonathan Cameron
2023-05-02 14:45   ` Olivier MOYSAN

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox