Skip to contentSkip to conversation

staging: iio: addac: adt7316: error code and probe cleanups

PATCH In review Raffaele Tranfaglia 2 participants 5 messages Oct 18 – Oct 21

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

cover staging: iio: addac: adt7316: error code and probe cleanups

Two small cleanups for the adt7316 driver.

Patch 1 makes the driver return the error codes reported by the bus helpers instead of replacing them with -EIO, so callers see the actual cause of a failure.

Patch 2 removes the dev_info() printed on successful probe, as drivers that are working properly should be quiet (see Documentation/process/coding-style.rst).

Tested on arm64 QEMU, with i2c-stub providing the device:

insmod i2c-stub.ko chip_addr=0x48
i2cset -y 0 0x48 0x4d 0x01
echo adt7316 0x48 > /sys/bus/i2c/devices/i2c-0/new_device

- probe succeeds and no longer prints a message
- device_id reads back the stub register value
- writing 0/1 to "enabled" updates CONFIG1 (0x18)

Error path, instantiating the device where no stub chip exists:

echo adt7316 0x49 > /sys/bus/i2c/devices/i2c-0/new_device

before: probe with driver adt7316 failed with error -5
after: probe with driver adt7316 rejects match -19

---
Raffaele Tranfaglia (2):
staging: iio: addac: adt7316: propagate bus error codes
staging: iio: addac: adt7316: drop informational message in probe

 drivers/staging/iio/addac/adt7316.c | 91 ++++++++++++++++++-------------------
 1 file changed, 43 insertions(+), 48 deletions(-)

---
base-commit: 6a27f3a7d1063aec5aa3d9370161e850fc3a85dd
change-id: 20261018-adt7316-error-codes-48500bb0b1cb

Best regards,

Signature · 1 line
Raffaele Tranfaglia <[email protected]>
#1 lore raw

PATCH 1/2 staging: iio: addac: adt7316: propagate bus error codes

Many register accesses replace the error returned by the bus read and write helpers with -EIO, hiding the actual cause of a failure such as -ENXIO or -ETIMEDOUT from the I2C or SPI core.

The bus helpers already return a negative errno on failure and 0 on success, so return their error code unchanged instead. Do the same for the result of _adt7316_store_enabled() in adt7316_store_enabled().

Assisted-by LLM
---
 drivers/staging/iio/addac/adt7316.c | 84 +++++++++++++++++++------------------
 1 file changed, 43 insertions(+), 41 deletions(-)
drivers/staging/iio/addac/adt7316.c +43 -41
index 8ca6def84584..d495032786db 100644
@@ -232,7 +232,7 @@ static ssize_t _adt7316_store_enabled(struct adt7316_chip_info *chip,
 
 	ret = chip->bus.write(chip->bus.client, ADT7316_CONFIG1, config1);
 	if (ret)
-		return -EIO;
+		return ret;
 
 	chip->config1 = config1;
 
@@ -247,14 +247,16 @@ static ssize_t adt7316_store_enabled(struct device *dev,
 	struct iio_dev *dev_info = dev_to_iio_dev(dev);
 	struct adt7316_chip_info *chip = iio_priv(dev_info);
 	int enable;
+	int ret;
 
 	if (buf[0] == '1')
 		enable = 1;
 	else
 		enable = 0;
 
-	if (_adt7316_store_enabled(chip, enable) < 0)
-		return -EIO;
+	ret = _adt7316_store_enabled(chip, enable);
+	if (ret < 0)
+		return ret;
 
 	return len;
 }
@@ -296,7 +298,7 @@ static ssize_t adt7316_store_select_ex_temp(struct device *dev,
 
 	ret = chip->bus.write(chip->bus.client, ADT7316_CONFIG1, config1);
 	if (ret)
-		return -EIO;
+		return ret;
 
 	chip->config1 = config1;
 
@@ -337,7 +339,7 @@ static ssize_t adt7316_store_mode(struct device *dev,
 
 	ret = chip->bus.write(chip->bus.client, ADT7316_CONFIG2, config2);
 	if (ret)
-		return -EIO;
+		return ret;
 
 	chip->config2 = config2;
 
@@ -430,7 +432,7 @@ static ssize_t adt7316_store_ad_channel(struct device *dev,
 
 	ret = chip->bus.write(chip->bus.client, ADT7316_CONFIG2, config2);
 	if (ret)
-		return -EIO;
+		return ret;
 
 	chip->config2 = config2;
 
@@ -490,7 +492,7 @@ static ssize_t adt7316_store_disable_averaging(struct device *dev,
 
 	ret = chip->bus.write(chip->bus.client, ADT7316_CONFIG2, config2);
 	if (ret)
-		return -EIO;
+		return ret;
 
 	chip->config2 = config2;
 
@@ -529,7 +531,7 @@ static ssize_t adt7316_store_enable_smbus_timeout(struct device *dev,
 
 	ret = chip->bus.write(chip->bus.client, ADT7316_CONFIG2, config2);
 	if (ret)
-		return -EIO;
+		return ret;
 
 	chip->config2 = config2;
 
@@ -567,7 +569,7 @@ static ssize_t adt7316_store_powerdown(struct device *dev,
 
 	ret = chip->bus.write(chip->bus.client, ADT7316_CONFIG1, config1);
 	if (ret)
-		return -EIO;
+		return ret;
 
 	chip->config1 = config1;
 
@@ -605,7 +607,7 @@ static ssize_t adt7316_store_fast_ad_clock(struct device *dev,
 
 	ret = chip->bus.write(chip->bus.client, ADT7316_CONFIG3, config3);
 	if (ret)
-		return -EIO;
+		return ret;
 
 	chip->config3 = config3;
 
@@ -651,7 +653,7 @@ static ssize_t adt7316_store_da_high_resolution(struct device *dev,
 
 	ret = chip->bus.write(chip->bus.client, ADT7316_CONFIG3, config3);
 	if (ret)
-		return -EIO;
+		return ret;
 
 	chip->config3 = config3;
 
@@ -697,7 +699,7 @@ static ssize_t adt7316_store_AIN_internal_Vref(struct device *dev,
 
 	ret = chip->bus.write(chip->bus.client, ADT7316_CONFIG3, config3);
 	if (ret)
-		return -EIO;
+		return ret;
 
 	chip->config3 = config3;
 
@@ -736,7 +738,7 @@ static ssize_t adt7316_store_enable_prop_DACA(struct device *dev,
 
 	ret = chip->bus.write(chip->bus.client, ADT7316_CONFIG3, config3);
 	if (ret)
-		return -EIO;
+		return ret;
 
 	chip->config3 = config3;
 
@@ -775,7 +777,7 @@ static ssize_t adt7316_store_enable_prop_DACB(struct device *dev,
 
 	ret = chip->bus.write(chip->bus.client, ADT7316_CONFIG3, config3);
 	if (ret)
-		return -EIO;
+		return ret;
 
 	chip->config3 = config3;
 
@@ -818,7 +820,7 @@ static ssize_t adt7316_store_DAC_2Vref_ch_mask(struct device *dev,
 
 	ret = chip->bus.write(chip->bus.client, ADT7316_DAC_CONFIG, dac_config);
 	if (ret)
-		return -EIO;
+		return ret;
 
 	chip->dac_config = dac_config;
 
@@ -878,7 +880,7 @@ static ssize_t adt7316_store_DAC_update_mode(struct device *dev,
 
 	ret = chip->bus.write(chip->bus.client, ADT7316_DAC_CONFIG, dac_config);
 	if (ret)
-		return -EIO;
+		return ret;
 
 	chip->dac_config = dac_config;
 
@@ -934,7 +936,7 @@ static ssize_t adt7316_store_update_DAC(struct device *dev,
 		ret = chip->bus.write(chip->bus.client, ADT7316_LDAC_CONFIG,
 			ldac_config);
 		if (ret)
-			return -EIO;
+			return ret;
 	} else {
 		gpiod_set_value(chip->ldac_pin, 0);
 		gpiod_set_value(chip->ldac_pin, 1);
@@ -975,7 +977,7 @@ static ssize_t adt7316_store_DA_AB_Vref_bypass(struct device *dev,
 
 	ret = chip->bus.write(chip->bus.client, ADT7316_DAC_CONFIG, dac_config);
 	if (ret)
-		return -EIO;
+		return ret;
 
 	chip->dac_config = dac_config;
 
@@ -1014,7 +1016,7 @@ static ssize_t adt7316_store_DA_CD_Vref_bypass(struct device *dev,
 
 	ret = chip->bus.write(chip->bus.client, ADT7316_DAC_CONFIG, dac_config);
 	if (ret)
-		return -EIO;
+		return ret;
 
 	chip->dac_config = dac_config;
 
@@ -1075,7 +1077,7 @@ static ssize_t adt7316_store_DAC_internal_Vref(struct device *dev,
 	ret = chip->bus.write(chip->bus.client, ADT7316_LDAC_CONFIG,
 			ldac_config);
 	if (ret)
-		return -EIO;
+		return ret;
 
 	chip->ldac_config = ldac_config;
 
@@ -1104,12 +1106,12 @@ static ssize_t adt7316_show_ad(struct adt7316_chip_info *chip,
 		ret = chip->bus.read(chip->bus.client,
 			ADT7316_LSB_IN_TEMP_VDD, &lsb);
 		if (ret)
-			return -EIO;
+			return ret;
 
 		ret = chip->bus.read(chip->bus.client,
 			ADT7316_AD_MSB_DATA_BASE + channel, &msb);
 		if (ret)
-			return -EIO;
+			return ret;
 
 		data = msb << ADT7316_T_VALUE_FLOAT_OFFSET;
 		data |= lsb & ADT7316_LSB_IN_TEMP_MASK;
@@ -1118,13 +1120,13 @@ static ssize_t adt7316_show_ad(struct adt7316_chip_info *chip,
 		ret = chip->bus.read(chip->bus.client,
 			ADT7316_LSB_IN_TEMP_VDD, &lsb);
 		if (ret)
-			return -EIO;
+			return ret;
 
 		ret = chip->bus.read(chip->bus.client,
 
 			ADT7316_AD_MSB_DATA_BASE + channel, &msb);
 		if (ret)
-			return -EIO;
+			return ret;
 
 		data = msb << ADT7316_T_VALUE_FLOAT_OFFSET;
 		data |= (lsb & ADT7316_LSB_VDD_MASK) >> ADT7316_LSB_VDD_OFFSET;
@@ -1133,12 +1135,12 @@ static ssize_t adt7316_show_ad(struct adt7316_chip_info *chip,
 		ret = chip->bus.read(chip->bus.client,
 			ADT7316_LSB_EX_TEMP_AIN, &lsb);
 		if (ret)
-			return -EIO;
+			return ret;
 
 		ret = chip->bus.read(chip->bus.client,
 			ADT7316_AD_MSB_DATA_BASE + channel, &msb);
 		if (ret)
-			return -EIO;
+			return ret;
 
 		data = msb << ADT7316_T_VALUE_FLOAT_OFFSET;
 		data |= lsb & (ADT7316_LSB_EX_TEMP_MASK <<
@@ -1241,7 +1243,7 @@ static ssize_t adt7316_show_temp_offset(struct adt7316_chip_info *chip,
 
 	ret = chip->bus.read(chip->bus.client, offset_addr, &val);
 	if (ret)
-		return -EIO;
+		return ret;
 
 	data = (int)val;
 	if (val & 0x80)
@@ -1270,7 +1272,7 @@ static ssize_t adt7316_store_temp_offset(struct adt7316_chip_info *chip,
 
 	ret = chip->bus.write(chip->bus.client, offset_addr, val);
 	if (ret)
-		return -EIO;
+		return ret;
 
 	return len;
 }
@@ -1401,13 +1403,13 @@ static ssize_t adt7316_show_DAC(struct adt7316_chip_info *chip,
 		ret = chip->bus.read(chip->bus.client,
 			ADT7316_DA_DATA_BASE + channel * 2, &lsb);
 		if (ret)
-			return -EIO;
+			return ret;
 	}
 
 	ret = chip->bus.read(chip->bus.client,
 		ADT7316_DA_DATA_BASE + 1 + channel * 2, &msb);
 	if (ret)
-		return -EIO;
+		return ret;
 
 	if (chip->dac_bits == 12)
 		data = lsb >> ADT7316_DA_12_BIT_LSB_SHIFT;
@@ -1447,14 +1449,14 @@ static ssize_t adt7316_store_DAC(struct adt7316_chip_info *chip,
 		ret = chip->bus.write(chip->bus.client,
 			ADT7316_DA_DATA_BASE + channel * 2, lsb_reg);
 		if (ret)
-			return -EIO;
+			return ret;
 	}
 
 	msb = data >> offset;
 	ret = chip->bus.write(chip->bus.client,
 		ADT7316_DA_DATA_BASE + 1 + channel * 2, msb);
 	if (ret)
-		return -EIO;
+		return ret;
 
 	return len;
 }
@@ -1566,7 +1568,7 @@ static ssize_t adt7316_show_device_id(struct device *dev,
 
 	ret = chip->bus.read(chip->bus.client, ADT7316_DEVICE_ID, &id);
 	if (ret)
-		return -EIO;
+		return ret;
 
 	return sysfs_emit(buf, "%d\n", id);
 }
@@ -1584,7 +1586,7 @@ static ssize_t adt7316_show_manufactorer_id(struct device *dev,
 
 	ret = chip->bus.read(chip->bus.client, ADT7316_MANUFACTURE_ID, &id);
 	if (ret)
-		return -EIO;
+		return ret;
 
 	return sysfs_emit(buf, "%d\n", id);
 }
@@ -1603,7 +1605,7 @@ static ssize_t adt7316_show_device_rev(struct device *dev,
 
 	ret = chip->bus.read(chip->bus.client, ADT7316_DEVICE_REV, &rev);
 	if (ret)
-		return -EIO;
+		return ret;
 
 	return sysfs_emit(buf, "%d\n", rev);
 }
@@ -1621,7 +1623,7 @@ static ssize_t adt7316_show_bus_type(struct device *dev,
 
 	ret = chip->bus.read(chip->bus.client, ADT7316_SPI_LOCK_STAT, &stat);
 	if (ret)
-		return -EIO;
+		return ret;
 
 	if (stat)
 		return sysfs_emit(buf, "spi\n");
@@ -1897,7 +1899,7 @@ static inline ssize_t adt7316_show_ad_bound(struct device *dev,
 
 	ret = chip->bus.read(chip->bus.client, this_attr->address, &val);
 	if (ret)
-		return -EIO;
+		return ret;
 
 	data = (int)val;
 
@@ -1946,7 +1948,7 @@ static inline ssize_t adt7316_set_ad_bound(struct device *dev,
 
 	ret = chip->bus.write(chip->bus.client, this_attr->address, val);
 	if (ret)
-		return -EIO;
+		return ret;
 
 	return len;
 }
@@ -1977,7 +1979,7 @@ static ssize_t adt7316_set_int_enabled(struct device *dev,
 
 	ret = chip->bus.write(chip->bus.client, ADT7316_CONFIG1, config1);
 	if (ret)
-		return -EIO;
+		return ret;
 
 	chip->config1 = config1;
 
@@ -2170,11 +2172,11 @@ int adt7316_probe(struct device *dev, struct adt7316_bus *bus,
 
 	ret = chip->bus.write(chip->bus.client, ADT7316_CONFIG1, chip->config1);
 	if (ret)
-		return -EIO;
+		return ret;
 
 	ret = chip->bus.write(chip->bus.client, ADT7316_CONFIG3, chip->config3);
 	if (ret)
-		return -EIO;
+		return ret;
 
 	ret = devm_iio_device_register(dev, indio_dev);
 	if (ret)
Signature · 1 line
2.56.0
#2 lore raw

PATCH 2/2 staging: iio: addac: adt7316: drop informational message in probe

In reply to Raffaele Tranfaglia

A successful probe does not need to be announced in the kernel log; the device can be found in sysfs. Remove the dev_info() and return the result of devm_iio_device_register() directly.

Assisted-by LLM
---
 drivers/staging/iio/addac/adt7316.c | 9 +--------
 1 file changed, 1 insertion(+), 8 deletions(-)
drivers/staging/iio/addac/adt7316.c +1 -8
index d495032786db..9fcbb640b7a5 100644
@@ -2178,14 +2178,7 @@ int adt7316_probe(struct device *dev, struct adt7316_bus *bus,
 	if (ret)
 		return ret;
 
-	ret = devm_iio_device_register(dev, indio_dev);
-	if (ret)
-		return ret;
-
-	dev_info(dev, "%s temperature sensor, ADC and DAC registered.\n",
-		 indio_dev->name);
-
-	return 0;
+	return devm_iio_device_register(dev, indio_dev);
 }
 EXPORT_SYMBOL(adt7316_probe);
 
Signature · 1 line
2.56.0
#3 lore raw
In reply to Raffaele Tranfaglia
Quoted 24 lines · On Sun Oct 18, 2026 at 4:41 PM CDT, Raffaele Tranfaglia via B4 Relay wrote:

Two small cleanups for the adt7316 driver.

Patch 1 makes the driver return the error codes reported by the bus helpers instead of replacing them with -EIO, so callers see the actual cause of a failure.

Patch 2 removes the dev_info() printed on successful probe, as drivers that are working properly should be quiet (see Documentation/process/coding-style.rst).

Tested on arm64 QEMU, with i2c-stub providing the device:

insmod i2c-stub.ko chip_addr=0x48
i2cset -y 0 0x48 0x4d 0x01
echo adt7316 0x48 > /sys/bus/i2c/devices/i2c-0/new_device

- probe succeeds and no longer prints a message
- device_id reads back the stub register value
- writing 0/1 to "enabled" updates CONFIG1 (0x18)

Error path, instantiating the device where no stub chip exists:

echo adt7316 0x49 > /sys/bus/i2c/devices/i2c-0/new_device

Quoted 7 lines

before: probe with driver adt7316 failed with error -5
after: probe with driver adt7316 rejects match -19

---

This is the current policy regarding AI and staging [1].

Thanks,
ET

[1] https://lore.kernel.org/r/2026080354-skater-urgent-31b2@gregkh

#4 lore raw
Quoted 34 lines · Ethan Tidmore
Quoted 24 lines · On Sun Oct 18, 2026 at 4:41 PM CDT, Raffaele Tranfaglia via B4 Relay wrote:

Two small cleanups for the adt7316 driver.

Patch 1 makes the driver return the error codes reported by the bus helpers instead of replacing them with -EIO, so callers see the actual cause of a failure.

Patch 2 removes the dev_info() printed on successful probe, as drivers that are working properly should be quiet (see Documentation/process/coding-style.rst).

Tested on arm64 QEMU, with i2c-stub providing the device:

insmod i2c-stub.ko chip_addr=0x48
i2cset -y 0 0x48 0x4d 0x01
echo adt7316 0x48 > /sys/bus/i2c/devices/i2c-0/new_device

- probe succeeds and no longer prints a message
- device_id reads back the stub register value
- writing 0/1 to "enabled" updates CONFIG1 (0x18)

Error path, instantiating the device where no stub chip exists:

echo adt7316 0x49 > /sys/bus/i2c/devices/i2c-0/new_device

Quoted 7 lines

before: probe with driver adt7316 failed with error -5
after: probe with driver adt7316 rejects match -19

---

Quoted 6 lines

This is the current policy regarding AI and staging [1].

Thanks,
ET

[1] https://lore.kernel.org/r/2026080354-skater-urgent-31b2@gregkh

I see, thanks for sharing.

Thanks,
Raffaele