Skip to contentSkip to conversation

iio: adc: ad7816: propagate SPI error codes

PATCH In review Hungyu Lin 2 participants 3 messages May 9

Subsystems (4)
lore
Share & tools
lore

Hungyu Lin

author
#0 lore raw

PATCH 1/1 iio: adc: ad7816: propagate SPI error codes

The driver currently returns -EIO for SPI read/write failures, which hides the actual error code returned by the SPI subsystem.

Return the original error code instead to allow better diagnostics and error handling by callers.

---
 drivers/staging/iio/adc/ad7816.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/staging/iio/adc/ad7816.c +2 -2
index 0e32a2295990..9052203eb4f3 100644
@@ -222,7 +222,7 @@ static ssize_t ad7816_show_value(struct device *dev,
 
 	ret = ad7816_spi_read(chip, &data);
 	if (ret)
-		return -EIO;
+		return ret;
 
 	data >>= AD7816_VALUE_OFFSET;
 
@@ -320,7 +320,7 @@ static inline ssize_t ad7816_set_oti(struct device *dev,
 
 	ret = ad7816_spi_write(chip, data);
 	if (ret)
-		return -EIO;
+		return ret;
 
 	chip->oti_data[chip->channel_id] = data;
 
Signature · 1 line
2.34.1
#1 lore raw
Quoted 5 lines · Hungyu Lin

The driver currently returns -EIO for SPI read/write failures, which hides the actual error code returned by the SPI subsystem.

Return the original error code instead to allow better diagnostics and error handling by callers.

...

drivers/staging/iio/adc/ad7816.c static ssize_t ad7816_show_value(struct device *dev, · line 225

Quoted 6 lines

static ssize_t ad7816_show_value(struct device *dev,

drivers/staging/iio/adc/ad7816.c +1 -1
 	ret = ad7816_spi_read(chip, &data);
 	if (ret)
-		return -EIO;
+		return ret;

At least this is an ABI change and should have been mentioned in the commit message and justified.

Yes, error code is an ABI and infamous case is already known when similar change badly broke user space.

https://lkml.org/lkml/2012/12/23/75

...

drivers/staging/iio/adc/ad7816.c static inline ssize_t ad7816_set_oti(struct device *dev, · line 323

Quoted 6 lines

static inline ssize_t ad7816_set_oti(struct device *dev,

drivers/staging/iio/adc/ad7816.c +1 -1
 	ret = ad7816_spi_write(chip, data);
 	if (ret)
-		return -EIO;
+		return ret;

Haven't checked this one, though.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
author
#2 lore raw

Hi Andy,

Thanks for pointing this out.

You're right that this changes the userspace-visible error codes and can be considered an ABI change. I don't think this is worth the risk, so I'll drop this change.

Thanks,
Hungyu

Quoted 41 lines · Andy Shevchenko
Quoted 5 lines · Hungyu Lin

The driver currently returns -EIO for SPI read/write failures, which hides the actual error code returned by the SPI subsystem.

Return the original error code instead to allow better diagnostics and error handling by callers.

...

Review

Quoted 6 lines

static ssize_t ad7816_show_value(struct device *dev,

      ret = ad7816_spi_read(chip, &data);
      if (ret)
(quoted diff) +1 -1
-             return -EIO;
+             return ret;

At least this is an ABI change and should have been mentioned in the commit message and justified.

Yes, error code is an ABI and infamous case is already known when similar change badly broke user space.

https://lkml.org/lkml/2012/12/23/75

...

Review

Quoted 6 lines

static inline ssize_t ad7816_set_oti(struct device *dev,

      ret = ad7816_spi_write(chip, data);
      if (ret)
(quoted diff) +1 -1
-             return -EIO;
+             return ret;

Haven't checked this one, though.

--
With Best Regards,
Andy Shevchenko