Skip to contentSkip to conversation

iio: fix write_raw() return values and remove pm helpers

PATCH In review Sang-Heon Jeon 4 participants 17 messages Jul 27 – Aug 1

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

cover iio: fix write_raw() return values and remove pm helpers

Hello,

This series fixes write_raw() return values and removes pm runtime helpers in iio drivers, as Jonathan suggested when reviewing the original iio patch [1].

Patches 1-2 fix write_raw() in isl29028 and tsl2583 to always return zero on success. write_raw() returns the value of pm_runtime_put_autosuspend(), which is 1 if the device is already runtime suspended. In that case write() on the sysfs attribute returns 1 instead of the number of bytes written.

Patches 3-7 remove the pm runtime helpers in isl29028, tsl2583, vcnl4035, vcnl4000 and rcar-gyroadc. Each helper just calls pm_runtime_resume_and_get() or pm_runtime_put_autosuspend() depending on its bool argument and adds no value.

Patches 8-9 are the remaining conditional return cleanups from the original patch, generated by the Coccinelle script.

[1] https://lore.kernel.org/all/[email protected]/

---

Sang-Heon Jeon (9):
iio: light: isl29028: return zero in write_raw() on success
iio: light: tsl2583: return zero in write_raw() on success
iio: light: isl29028: remove isl29028_set_pm_runtime_busy() helper
iio: light: tsl2583: remove tsl2583_set_pm_runtime_busy() helper
iio: light: vcnl4035: remove vcnl4035_set_pm_runtime_state() helper
iio: light: vcnl4000: remove vcnl4000_set_pm_runtime_state() helper
iio: adc: rcar-gyroadc: remove rcar_gyroadc_set_power() helper
iio: light: tsl2583: remove conditional return with no effect
iio: magnetometer: ak8974: remove conditional return with no effect

 drivers/iio/adc/rcar-gyroadc.c    | 14 ++------------
 drivers/iio/light/isl29028.c      | 22 ++++++---------------
 drivers/iio/light/tsl2583.c       | 32 ++++++++++---------------------
 drivers/iio/light/vcnl4000.c      | 14 ++------------
 drivers/iio/light/vcnl4035.c      | 18 ++++-------------
 drivers/iio/magnetometer/ak8974.c |  6 +-----
 6 files changed, 25 insertions(+), 81 deletions(-)
Signature · 1 line
2.43.0
#1 lore raw

PATCH 1/9 iio: light: isl29028: return zero in write_raw() on success

isl29028_write_raw() returns the value of pm_runtime_put_autosuspend(), which is 1 if the device is already runtime suspended.

In that case write() on the sysfs attribute returns 1 instead of the number of bytes written. Make isl29028_write_raw() always return zero on success.

Fixes 2db5054ac28d ("staging: iio: isl29028: add runtime power management support")
---
 drivers/iio/light/isl29028.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/iio/light/isl29028.c +1 -1
index b88e7c4eae3e..6d5dd17e7a7d 100644
@@ -409,7 +409,7 @@ static int isl29028_write_raw(struct iio_dev *indio_dev,
 	if (ret < 0)
 		return ret;
 
-	return ret;
+	return 0;
 }
 
 static int isl29028_read_raw(struct iio_dev *indio_dev,
Signature · 1 line
2.43.0
Reviewed-by on v1 1/9
#2 lore raw

Re: [PATCH 1/9] iio: light: isl29028: return zero in write_raw() on success

Quoted 9 lines · Sang-Heon Jeon

isl29028_write_raw() returns the value of pm_runtime_put_autosuspend(), which is 1 if the device is already runtime suspended.

In that case write() on the sysfs attribute returns 1 instead of the number of bytes written. Make isl29028_write_raw() always return zero on success.

Fixes 2db5054ac28d ("staging: iio: isl29028: add runtime power management support")
#3 lore raw

PATCH 2/9 iio: light: tsl2583: return zero in write_raw() on success

In reply to Sang-Heon Jeon

tsl2583_write_raw() returns the value of pm_runtime_put_autosuspend(), which is 1 if the device is already runtime suspended.

In that case write() on the sysfs attribute returns 1 instead of the number of bytes written. Make tsl2583_write_raw() always return zero on success.

Fixes 371894f5d1a0 ("iio: tsl2583: add runtime power management support")
---
 drivers/iio/light/tsl2583.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/iio/light/tsl2583.c +1 -1
index a210d87a1519..54fa426c5755 100644
@@ -794,7 +794,7 @@ static int tsl2583_write_raw(struct iio_dev *indio_dev,
 	if (ret < 0)
 		return ret;
 
-	return ret;
+	return 0;
 }
 
 static const struct iio_info tsl2583_info = {
Signature · 1 line
2.43.0
Reviewed-by on v1 2/9
#4 lore raw

Re: [PATCH 2/9] iio: light: tsl2583: return zero in write_raw() on success

Quoted 9 lines · Sang-Heon Jeon

tsl2583_write_raw() returns the value of pm_runtime_put_autosuspend(), which is 1 if the device is already runtime suspended.

In that case write() on the sysfs attribute returns 1 instead of the number of bytes written. Make tsl2583_write_raw() always return zero on success.

Fixes 371894f5d1a0 ("iio: tsl2583: add runtime power management support")
#5 lore raw

PATCH 3/9 iio: light: isl29028: remove isl29028_set_pm_runtime_busy() helper

In reply to Sang-Heon Jeon

isl29028_set_pm_runtime_busy() just calls pm_runtime_resume_and_get() or pm_runtime_put_autosuspend() depending on its bool argument. Call them directly and remove the helper.

No functional change.

---
 drivers/iio/light/isl29028.c | 20 +++++---------------
 1 file changed, 5 insertions(+), 15 deletions(-)
drivers/iio/light/isl29028.c +5 -15
index 6d5dd17e7a7d..33deb1726689 100644
@@ -333,16 +333,6 @@ static int isl29028_ir_get(struct isl29028_chip *chip, int *ir_data)
 	return isl29028_read_als_ir(chip, ir_data);
 }
 
-static int isl29028_set_pm_runtime_busy(struct isl29028_chip *chip, bool on)
-{
-	struct device *dev = regmap_get_device(chip->regmap);
-
-	if (on)
-		return pm_runtime_resume_and_get(dev);
-
-	return pm_runtime_put_autosuspend(dev);
-}
-
 /* Channel IO */
 static int isl29028_write_raw(struct iio_dev *indio_dev,
 			      struct iio_chan_spec const *chan,
@@ -352,7 +342,7 @@ static int isl29028_write_raw(struct iio_dev *indio_dev,
 	struct device *dev = regmap_get_device(chip->regmap);
 	int ret;
 
-	ret = isl29028_set_pm_runtime_busy(chip, true);
+	ret = pm_runtime_resume_and_get(dev);
 	if (ret < 0)
 		return ret;
 
@@ -405,7 +395,7 @@ static int isl29028_write_raw(struct iio_dev *indio_dev,
 	if (ret < 0)
 		return ret;
 
-	ret = isl29028_set_pm_runtime_busy(chip, false);
+	ret = pm_runtime_put_autosuspend(dev);
 	if (ret < 0)
 		return ret;
 
@@ -420,7 +410,7 @@ static int isl29028_read_raw(struct iio_dev *indio_dev,
 	struct device *dev = regmap_get_device(chip->regmap);
 	int ret, pm_ret;
 
-	ret = isl29028_set_pm_runtime_busy(chip, true);
+	ret = pm_runtime_resume_and_get(dev);
 	if (ret < 0)
 		return ret;
 
@@ -476,10 +466,10 @@ static int isl29028_read_raw(struct iio_dev *indio_dev,
 
 	/**
 	 * Preserve the ret variable if the call to
-	 * isl29028_set_pm_runtime_busy() is successful so the reading
+	 * pm_runtime_put_autosuspend() is successful so the reading
 	 * (if applicable) is returned to user space.
 	 */
-	pm_ret = isl29028_set_pm_runtime_busy(chip, false);
+	pm_ret = pm_runtime_put_autosuspend(dev);
 	if (pm_ret < 0)
 		return pm_ret;
 
Signature · 1 line
2.43.0
Reviewed-by on v1 3/9
#6 lore raw

Re: [PATCH 3/9] iio: light: isl29028: remove isl29028_set_pm_runtime_busy() helper

Quoted 8 lines · Sang-Heon Jeon

isl29028_set_pm_runtime_busy() just calls pm_runtime_resume_and_get() or pm_runtime_put_autosuspend() depending on its bool argument. Call them directly and remove the helper.

No functional change.

#7 lore raw

PATCH 4/9 iio: light: tsl2583: remove tsl2583_set_pm_runtime_busy() helper

In reply to Sang-Heon Jeon

tsl2583_set_pm_runtime_busy() just calls pm_runtime_resume_and_get() or pm_runtime_put_autosuspend() depending on its bool argument. Call them directly and remove the helper.

No functional change.

---
 drivers/iio/light/tsl2583.c | 22 +++++++---------------
 1 file changed, 7 insertions(+), 15 deletions(-)
drivers/iio/light/tsl2583.c +7 -15
index 54fa426c5755..06da145569f7 100644
@@ -639,14 +639,6 @@ static const struct iio_chan_spec tsl2583_channels[] = {
 	},
 };
 
-static int tsl2583_set_pm_runtime_busy(struct tsl2583_chip *chip, bool on)
-{
-	if (on)
-		return pm_runtime_resume_and_get(&chip->client->dev);
-
-	return pm_runtime_put_autosuspend(&chip->client->dev);
-}
-
 static int tsl2583_read_raw(struct iio_dev *indio_dev,
 			    struct iio_chan_spec const *chan,
 			    int *val, int *val2, long mask)
@@ -654,7 +646,7 @@ static int tsl2583_read_raw(struct iio_dev *indio_dev,
 	struct tsl2583_chip *chip = iio_priv(indio_dev);
 	int ret, pm_ret;
 
-	ret = tsl2583_set_pm_runtime_busy(chip, true);
+	ret = pm_runtime_resume_and_get(&chip->client->dev);
 	if (ret < 0)
 		return ret;
 
@@ -722,16 +714,16 @@ static int tsl2583_read_raw(struct iio_dev *indio_dev,
 	mutex_unlock(&chip->als_mutex);
 
 	if (ret < 0) {
-		tsl2583_set_pm_runtime_busy(chip, false);
+		pm_runtime_put_autosuspend(&chip->client->dev);
 		return ret;
 	}
 
 	/*
 	 * Preserve the ret variable if the call to
-	 * tsl2583_set_pm_runtime_busy() is successful so the reading
+	 * pm_runtime_put_autosuspend() is successful so the reading
 	 * (if applicable) is returned to user space.
 	 */
-	pm_ret = tsl2583_set_pm_runtime_busy(chip, false);
+	pm_ret = pm_runtime_put_autosuspend(&chip->client->dev);
 	if (pm_ret < 0)
 		return pm_ret;
 
@@ -745,7 +737,7 @@ static int tsl2583_write_raw(struct iio_dev *indio_dev,
 	struct tsl2583_chip *chip = iio_priv(indio_dev);
 	int ret;
 
-	ret = tsl2583_set_pm_runtime_busy(chip, true);
+	ret = pm_runtime_resume_and_get(&chip->client->dev);
 	if (ret < 0)
 		return ret;
 
@@ -786,11 +778,11 @@ static int tsl2583_write_raw(struct iio_dev *indio_dev,
 	mutex_unlock(&chip->als_mutex);
 
 	if (ret < 0) {
-		tsl2583_set_pm_runtime_busy(chip, false);
+		pm_runtime_put_autosuspend(&chip->client->dev);
 		return ret;
 	}
 
-	ret = tsl2583_set_pm_runtime_busy(chip, false);
+	ret = pm_runtime_put_autosuspend(&chip->client->dev);
 	if (ret < 0)
 		return ret;
 
Signature · 1 line
2.43.0
Reviewed-by on v1 4/9
#8 lore raw

Re: [PATCH 4/9] iio: light: tsl2583: remove tsl2583_set_pm_runtime_busy() helper

Quoted 8 lines · Sang-Heon Jeon

tsl2583_set_pm_runtime_busy() just calls pm_runtime_resume_and_get() or pm_runtime_put_autosuspend() depending on its bool argument. Call them directly and remove the helper.

No functional change.

#9 lore raw

PATCH 5/9 iio: light: vcnl4035: remove vcnl4035_set_pm_runtime_state() helper

In reply to Sang-Heon Jeon

vcnl4035_set_pm_runtime_state() just calls pm_runtime_resume_and_get() or pm_runtime_put_autosuspend() depending on its bool argument. Call them directly and remove the helper.

No functional change.

---
 drivers/iio/light/vcnl4035.c | 18 ++++--------------
 1 file changed, 4 insertions(+), 14 deletions(-)
drivers/iio/light/vcnl4035.c +4 -14
index d13c5ff33e07..ce1bd42b0c7c 100644
@@ -145,16 +145,6 @@ static const struct iio_trigger_ops vcnl4035_trigger_ops = {
 	.set_trigger_state = vcnl4035_als_drdy_set_state,
 };
 
-static int vcnl4035_set_pm_runtime_state(struct vcnl4035_data *data, bool on)
-{
-	struct device *dev = &data->client->dev;
-
-	if (on)
-		return pm_runtime_resume_and_get(dev);
-
-	return pm_runtime_put_autosuspend(dev);
-}
-
 static int vcnl4035_read_info_raw(struct iio_dev *indio_dev,
 				  struct iio_chan_spec const *chan, int *val)
 {
@@ -202,11 +192,11 @@ static int vcnl4035_read_raw(struct iio_dev *indio_dev,
 
 	switch (mask) {
 	case IIO_CHAN_INFO_RAW:
-		ret = vcnl4035_set_pm_runtime_state(data, true);
+		ret = pm_runtime_resume_and_get(&data->client->dev);
 		if  (ret < 0)
 			return ret;
 		ret = vcnl4035_read_info_raw(indio_dev, chan, val);
-		vcnl4035_set_pm_runtime_state(data, false);
+		pm_runtime_put_autosuspend(&data->client->dev);
 		return ret;
 	case IIO_CHAN_INFO_INT_TIME:
 		*val = 50;
@@ -237,7 +227,7 @@ static int vcnl4035_write_raw(struct iio_dev *indio_dev,
 		if (val <= 0 || val > 800)
 			return -EINVAL;
 
-		ret = vcnl4035_set_pm_runtime_state(data, true);
+		ret = pm_runtime_resume_and_get(&data->client->dev);
 		if  (ret < 0)
 			return ret;
 
@@ -247,7 +237,7 @@ static int vcnl4035_write_raw(struct iio_dev *indio_dev,
 		if (!ret)
 			data->als_it_val = val / 100;
 
-		vcnl4035_set_pm_runtime_state(data, false);
+		pm_runtime_put_autosuspend(&data->client->dev);
 		return ret;
 	default:
 		return -EINVAL;
Signature · 1 line
2.43.0
#10 lore raw

PATCH 6/9 iio: light: vcnl4000: remove vcnl4000_set_pm_runtime_state() helper

In reply to Sang-Heon Jeon

vcnl4000_set_pm_runtime_state() just calls pm_runtime_resume_and_get() or pm_runtime_put_autosuspend() depending on its bool argument. Call them directly and remove the helper.

No functional change.

---
 drivers/iio/light/vcnl4000.c | 14 ++------------
 1 file changed, 2 insertions(+), 12 deletions(-)
drivers/iio/light/vcnl4000.c +2 -12
index b8ac156ad5c9..336468d59ea7 100644
@@ -537,16 +537,6 @@ static bool vcnl4010_is_in_periodic_mode(struct vcnl4000_data *data)
 	return !!(ret & VCNL4000_SELF_TIMED_EN);
 }
 
-static int vcnl4000_set_pm_runtime_state(struct vcnl4000_data *data, bool on)
-{
-	struct device *dev = &data->client->dev;
-
-	if (on)
-		return pm_runtime_resume_and_get(dev);
-
-	return pm_runtime_put_autosuspend(dev);
-}
-
 static int vcnl4040_read_als_it(struct vcnl4000_data *data, int *val, int *val2)
 {
 	int ret;
@@ -850,7 +840,7 @@ static int vcnl4000_read_raw(struct iio_dev *indio_dev,
 
 	switch (mask) {
 	case IIO_CHAN_INFO_RAW:
-		ret = vcnl4000_set_pm_runtime_state(data, true);
+		ret = pm_runtime_resume_and_get(&data->client->dev);
 		if  (ret < 0)
 			return ret;
 
@@ -869,7 +859,7 @@ static int vcnl4000_read_raw(struct iio_dev *indio_dev,
 		default:
 			ret = -EINVAL;
 		}
-		vcnl4000_set_pm_runtime_state(data, false);
+		pm_runtime_put_autosuspend(&data->client->dev);
 		return ret;
 	case IIO_CHAN_INFO_SCALE:
 		if (chan->type != IIO_LIGHT)
Signature · 1 line
2.43.0
#11 lore raw

PATCH 7/9 iio: adc: rcar-gyroadc: remove rcar_gyroadc_set_power() helper

In reply to Sang-Heon Jeon

rcar_gyroadc_set_power() just calls pm_runtime_resume_and_get() or pm_runtime_put_autosuspend() depending on its bool argument. Call them directly and remove the helper.

No functional change.

---
 drivers/iio/adc/rcar-gyroadc.c | 14 ++------------
 1 file changed, 2 insertions(+), 12 deletions(-)
drivers/iio/adc/rcar-gyroadc.c +2 -12
index 3a17b3898bf6..d38cf3caeae0 100644
@@ -159,16 +159,6 @@ static const struct iio_chan_spec rcar_gyroadc_iio_channels_3[] = {
 	RCAR_GYROADC_CHAN(7),
 };
 
-static int rcar_gyroadc_set_power(struct rcar_gyroadc *priv, bool on)
-{
-	struct device *dev = priv->dev;
-
-	if (on)
-		return pm_runtime_resume_and_get(dev);
-
-	return pm_runtime_put_autosuspend(dev);
-}
-
 static int rcar_gyroadc_read_raw(struct iio_dev *indio_dev,
 				 struct iio_chan_spec const *chan,
 				 int *val, int *val2, long mask)
@@ -200,7 +190,7 @@ static int rcar_gyroadc_read_raw(struct iio_dev *indio_dev,
 		if (!iio_device_claim_direct(indio_dev))
 			return -EBUSY;
 
-		ret = rcar_gyroadc_set_power(priv, true);
+		ret = pm_runtime_resume_and_get(priv->dev);
 		if (ret < 0) {
 			iio_device_release_direct(indio_dev);
 			return ret;
@@ -209,7 +199,7 @@ static int rcar_gyroadc_read_raw(struct iio_dev *indio_dev,
 		*val = readl(priv->regs + datareg);
 		*val &= BIT(priv->sample_width) - 1;
 
-		ret = rcar_gyroadc_set_power(priv, false);
+		ret = pm_runtime_put_autosuspend(priv->dev);
 		iio_device_release_direct(indio_dev);
 		if (ret < 0)
 			return ret;
Signature · 1 line
2.43.0
Reviewed-by on v1 7/9
#12 lore raw

Re: [PATCH 7/9] iio: adc: rcar-gyroadc: remove rcar_gyroadc_set_power() helper

Quoted 7 lines · Sang-Heon Jeon

rcar_gyroadc_set_power() just calls pm_runtime_resume_and_get() or pm_runtime_put_autosuspend() depending on its bool argument. Call them directly and remove the helper.

No functional change.

#13 lore raw

PATCH 8/9 iio: light: tsl2583: remove conditional return with no effect

In reply to Sang-Heon Jeon

Both branches of the check return the same value, so the check has no effect. Remove it and return the value directly.

This is the result of running the Coccinelle script from scripts/coccinelle/misc/cond_return_no_effect.cocci.

---
 drivers/iio/light/tsl2583.c | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)
drivers/iio/light/tsl2583.c +2 -6
index 06da145569f7..53fd423aa7ae 100644
@@ -456,12 +456,8 @@ static int tsl2583_chip_init_and_power_on(struct iio_dev *indio_dev)
 
 	usleep_range(3000, 3500);
 
-	ret = tsl2583_set_power_state(chip, TSL2583_CNTL_PWR_ON |
-					    TSL2583_CNTL_ADC_ENBL);
-	if (ret < 0)
-		return ret;
-
-	return ret;
+	return tsl2583_set_power_state(chip,
+				       TSL2583_CNTL_PWR_ON | TSL2583_CNTL_ADC_ENBL);
 }
 
 /* Sysfs Interface Functions */
Signature · 1 line
2.43.0
Reviewed-by on v1 8/9
#14 lore raw

Re: [PATCH 8/9] iio: light: tsl2583: remove conditional return with no effect

Quoted 8 lines · Sang-Heon Jeon

Both branches of the check return the same value, so the check has no effect. Remove it and return the value directly.

This is the result of running the Coccinelle script from scripts/coccinelle/misc/cond_return_no_effect.cocci.

#15 lore raw

PATCH 9/9 iio: magnetometer: ak8974: remove conditional return with no effect

In reply to Sang-Heon Jeon

Both branches of the check return the same value, so the check has no effect. Remove it and return the value directly.

This is the result of running the Coccinelle script from scripts/coccinelle/misc/cond_return_no_effect.cocci.

---
 drivers/iio/magnetometer/ak8974.c | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)
drivers/iio/magnetometer/ak8974.c +1 -5
index c7fdb7c2f543..c988d0e40cea 100644
@@ -379,11 +379,7 @@ static int ak8974_getresult(struct ak8974 *ak8974, __le16 *result)
 		return -ERANGE;
 	}
 
-	ret = regmap_bulk_read(ak8974->map, AK8974_DATA_X, result, 6);
-	if (ret)
-		return ret;
-
-	return ret;
+	return regmap_bulk_read(ak8974->map, AK8974_DATA_X, result, 6);
 }
 
 static irqreturn_t ak8974_drdy_irq(int irq, void *d)
Signature · 1 line
2.43.0
maintainer
#16 lore raw
In reply to Sang-Heon Jeon
Quoted 2 lines · On Tue, 28 Jul 2026 03:47:37 +0900 Sang-Heon Jeon <[email protected]> wrote:

Hello,

Nice series - thanks for doing this.

Applied to the testing branch of iio.git to get some build testing before I push it out for linux-next to pick up.

Thanks,

Jonathan