Skip to contentSkip to conversation

iio: light: apds9999: register standby action after enabling device

PATCH In review [email protected] 2 participants 3 messages Jul 24 – Aug 23

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

PATCH 1/1 iio: light: apds9999: register standby action after enabling device

From: Surendra Singh Chouhan <[email protected]>

apds9999_init() called devm_add_action_or_reset() at the start of the function, before register configuration and before enabling the device via APDS9999_MAIN_CTRL_LS_EN.

If register initialization failed during apds9999_init() (e.g. SMBus write failures on LS_MEAS_RATE or LS_GAIN), devm_add_action_or_reset() immediately triggered apds9999_standby(), writing to the control register on a device that failed initialization and was never enabled.

Fix this by registering devm_add_action_or_reset() only after APDS9999_MAIN_CTRL_LS_EN is successfully written to the control register.

Fixes 5f9363e52300 ("iio: light: add support for APDS9999 sensor")
---
 drivers/iio/light/apds9999.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
drivers/iio/light/apds9999.c +6 -6
index 43fa9992c9c2..62620c4a2fbc 100644
@@ -100,10 +100,6 @@ static int apds9999_init(struct apds9999_data *data)
 	u8 regval;
 	int ret;
 
-	ret = devm_add_action_or_reset(dev, apds9999_standby, client);
-	if (ret)
-		return ret;
-
 	guard(mutex)(&data->lock);
 
 	regval = FIELD_PREP(APDS9999_LS_RES_MASK, APDS9999_RES_18BIT) |
@@ -121,8 +117,12 @@ static int apds9999_init(struct apds9999_data *data)
 		return ret;
 	data->als_gain_idx = APDS9999_GAIN_3X;
 
-	return i2c_smbus_write_byte_data(client, APDS9999_REG_MAIN_CTRL,
-					 APDS9999_MAIN_CTRL_LS_EN);
+	ret = i2c_smbus_write_byte_data(client, APDS9999_REG_MAIN_CTRL,
+					APDS9999_MAIN_CTRL_LS_EN);
+	if (ret)
+		return ret;
+
+	return devm_add_action_or_reset(dev, apds9999_standby, client);
 }
 
 static int apds9999_read_channel(struct apds9999_data *data, u8 reg,
Signature · 1 line
2.55.0
maintainer
#1 lore raw
Quoted 11 lines · On Fri, 24 Jul 2026 08:28:02 +0530 [email protected] wrote:

From: Surendra Singh Chouhan <[email protected]>

apds9999_init() called devm_add_action_or_reset() at the start of the function, before register configuration and before enabling the device via APDS9999_MAIN_CTRL_LS_EN.

If register initialization failed during apds9999_init() (e.g. SMBus write failures on LS_MEAS_RATE or LS_GAIN), devm_add_action_or_reset() immediately triggered apds9999_standby(), writing to the control register on a device that failed initialization and was never enabled.

Quoted 5 lines

Fix this by registering devm_add_action_or_reset() only after APDS9999_MAIN_CTRL_LS_EN is successfully written to the control register.

Fixes 5f9363e52300 ("iio: light: add support for APDS9999 sensor")

Given the side effect of this is write that is harmless, I don't think the fixes tag is justified.

Having said that this is a logical improvement.

I would like Jose to have taken a look though before I consider picking it up so let us leave it on list for now.

Thanks,

Jonathan

Quoted 35 lines
---
 drivers/iio/light/apds9999.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
drivers/iio/light/apds9999.c +6 -6
index 43fa9992c9c2..62620c4a2fbc 100644
@@ -100,10 +100,6 @@ static int apds9999_init(struct apds9999_data *data)
 	u8 regval;
 	int ret;
 
-	ret = devm_add_action_or_reset(dev, apds9999_standby, client);
-	if (ret)
-		return ret;
-
 	guard(mutex)(&data->lock);
 
 	regval = FIELD_PREP(APDS9999_LS_RES_MASK, APDS9999_RES_18BIT) |
@@ -121,8 +117,12 @@ static int apds9999_init(struct apds9999_data *data)
 		return ret;
 	data->als_gain_idx = APDS9999_GAIN_3X;
 
-	return i2c_smbus_write_byte_data(client, APDS9999_REG_MAIN_CTRL,
-					 APDS9999_MAIN_CTRL_LS_EN);
+	ret = i2c_smbus_write_byte_data(client, APDS9999_REG_MAIN_CTRL,
+					APDS9999_MAIN_CTRL_LS_EN);
+	if (ret)
+		return ret;
+
+	return devm_add_action_or_reset(dev, apds9999_standby, client);
 }
 
 static int apds9999_read_channel(struct apds9999_data *data, u8 reg,
maintainer
#2 lore raw
Quoted 20 lines · On Sun, 26 Jul 2026 20:50:30 +0100 Jonathan Cameron <[email protected]> wrote:
Quoted 11 lines · On Fri, 24 Jul 2026 08:28:02 +0530 [email protected] wrote:

From: Surendra Singh Chouhan <[email protected]>

apds9999_init() called devm_add_action_or_reset() at the start of the function, before register configuration and before enabling the device via APDS9999_MAIN_CTRL_LS_EN.

If register initialization failed during apds9999_init() (e.g. SMBus write failures on LS_MEAS_RATE or LS_GAIN), devm_add_action_or_reset() immediately triggered apds9999_standby(), writing to the control register on a device that failed initialization and was never enabled.

Quoted 5 lines

Fix this by registering devm_add_action_or_reset() only after APDS9999_MAIN_CTRL_LS_EN is successfully written to the control register.

Fixes 5f9363e52300 ("iio: light: add support for APDS9999 sensor")
Quoted 8 lines

Given the side effect of this is write that is harmless, I don't think the fixes tag is justified.

Having said that this is a logical improvement.

I would like Jose to have taken a look though before I consider picking it up so let us leave it on list for now.

Seems they are busy or missed this. So let me gamble...

Applied to the testing branch of iio.git which I will be rebasing on rc1 once available. Note that in the meantime I am happy to rebase so late comments or tags are fine.

thanks

Jonathan

Quoted 41 lines

Thanks,

Jonathan

Quoted 35 lines
---
 drivers/iio/light/apds9999.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
drivers/iio/light/apds9999.c +6 -6
index 43fa9992c9c2..62620c4a2fbc 100644
@@ -100,10 +100,6 @@ static int apds9999_init(struct apds9999_data *data)
 	u8 regval;
 	int ret;
 
-	ret = devm_add_action_or_reset(dev, apds9999_standby, client);
-	if (ret)
-		return ret;
-
 	guard(mutex)(&data->lock);
 
 	regval = FIELD_PREP(APDS9999_LS_RES_MASK, APDS9999_RES_18BIT) |
@@ -121,8 +117,12 @@ static int apds9999_init(struct apds9999_data *data)
 		return ret;
 	data->als_gain_idx = APDS9999_GAIN_3X;
 
-	return i2c_smbus_write_byte_data(client, APDS9999_REG_MAIN_CTRL,
-					 APDS9999_MAIN_CTRL_LS_EN);
+	ret = i2c_smbus_write_byte_data(client, APDS9999_REG_MAIN_CTRL,
+					APDS9999_MAIN_CTRL_LS_EN);
+	if (ret)
+		return ret;
+
+	return devm_add_action_or_reset(dev, apds9999_standby, client);
 }
 
 static int apds9999_read_channel(struct apds9999_data *data, u8 reg,