linux-iio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] iio: adc: Revoke valid channel for error path
@ 2025-04-15 18:20 Gabriel Shahrouzi
  2025-04-17 10:06 ` Nuno Sá
  0 siblings, 1 reply; 7+ messages in thread
From: Gabriel Shahrouzi @ 2025-04-15 18:20 UTC (permalink / raw)
  To: gregkh, jic23, lars, linux-iio, linux-kernel, linux-staging,
	Michael.Hennerich, sonic.zhang, vapier
  Cc: gshahrouzi, skhan, kernelmentees, stable

According to the datasheet on page 9 under the channel selection table,
all devices (AD7816/7/8) are able to use the channel marked as 7. This
channel is used for diagnostic purposes by routing the internal 1.23V
bandgap source through the MUX to the input of the ADC.

Replace checking for string equality with checking for the same chip ID
to reduce time complexity.

Group invalid channels for all devices together because they are
processed the same way.

Fixes: 7924425db04a ("staging: iio: adc: new driver for AD7816 devices")
Cc: stable@vger.kernel.org
Signed-off-by: Gabriel Shahrouzi <gshahrouzi@gmail.com>
---
 drivers/staging/iio/adc/ad7816.c | 15 +++++----------
 1 file changed, 5 insertions(+), 10 deletions(-)

diff --git a/drivers/staging/iio/adc/ad7816.c b/drivers/staging/iio/adc/ad7816.c
index 6c14d7bcdd675..d880fe0257697 100644
--- a/drivers/staging/iio/adc/ad7816.c
+++ b/drivers/staging/iio/adc/ad7816.c
@@ -186,17 +186,12 @@ static ssize_t ad7816_store_channel(struct device *dev,
 	if (ret)
 		return ret;
 
-	if (data > AD7816_CS_MAX && data != AD7816_CS_MASK) {
-		dev_err(&chip->spi_dev->dev, "Invalid channel id %lu for %s.\n",
-			data, indio_dev->name);
-		return -EINVAL;
-	} else if (strcmp(indio_dev->name, "ad7818") == 0 && data > 1) {
-		dev_err(&chip->spi_dev->dev,
-			"Invalid channel id %lu for ad7818.\n", data);
-		return -EINVAL;
-	} else if (strcmp(indio_dev->name, "ad7816") == 0 && data > 0) {
+	if (data != AD7816_CS_MASK &&
+	    (data > AD7816_CS_MAX ||
+	    (chip->id == ID_AD7818 && data > 1) ||
+	    (chip->id == ID_AD7816 && data > 0))) {
 		dev_err(&chip->spi_dev->dev,
-			"Invalid channel id %lu for ad7816.\n", data);
+			"Invalid channel id %lu for %s.\n", data, indio_dev->name);
 		return -EINVAL;
 	}
 
-- 
2.43.0


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

end of thread, other threads:[~2025-04-18 13:28 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-04-15 18:20 [PATCH] iio: adc: Revoke valid channel for error path Gabriel Shahrouzi
2025-04-17 10:06 ` Nuno Sá
2025-04-17 12:53   ` Gabriel Shahrouzi
2025-04-17 14:02     ` Nuno Sá
2025-04-17 17:08       ` Gabriel Shahrouzi
2025-04-18  8:46         ` Nuno Sá
2025-04-18 13:28           ` Gabriel Shahrouzi

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).