Skip to contentSkip to conversation

iio: ccs811: Deassert WAKE GPIO on error paths

PATCH Superseded Nikhil Gautam 2 participants 3 messages Oct 14 – Oct 15 IIO

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 iio: ccs811: Deassert WAKE GPIO on error paths

Ensure the WAKE GPIO is deasserted when status polling fails or the data-ready timeout expires. Early returns could leave WAKE asserted, preventing the sensor from returning to its low-power state and potentially disrupting subsequent I2C transactions.

Route error paths through a common cleanup label to ensure WAKE is deasserted before returning.

---
 drivers/iio/chemical/ccs811.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
drivers/iio/chemical/ccs811.c +6 -4
index 998c9239c4c7..94c83937d1d7 100644
@@ -198,20 +198,22 @@ static int ccs811_get_measurement(struct ccs811_data *data)
 	while (tries-- > 0) {
 		ret = i2c_smbus_read_byte_data(data->client, CCS811_STATUS);
 		if (ret < 0)
-			return ret;
+			goto out;
 
 		if ((ret & CCS811_STATUS_DATA_READY) || tries == 0)
 			break;
 		msleep(100);
 	}
-	if (!(ret & CCS811_STATUS_DATA_READY))
-		return -EIO;
+	if (!(ret & CCS811_STATUS_DATA_READY)) {
+		ret = -EIO;
+		goto out;
+	}
 
 	ret = i2c_smbus_read_i2c_block_data(data->client,
 					    CCS811_ALG_RESULT_DATA, 8,
 					    (char *)&data->buffer);
+out:
 	ccs811_set_wakeup(data, false);
-
 	return ret;
 }
 
Signature · 1 line
2.39.5
Reviewed-by on v1 1/1
#1 lore raw
Quoted 9 lines · On Wed, 14 Oct 2026 20:52:50 +0530 Nikhil Gautam <[email protected]> wrote:

Ensure the WAKE GPIO is deasserted when status polling fails or the data-ready timeout expires. Early returns could leave WAKE asserted, preventing the sensor from returning to its low-power state and potentially disrupting subsequent I2C transactions.

Route error paths through a common cleanup label to ensure WAKE is deasserted before returning.

Please add a Fixes tag.

...

drivers/iio/chemical/ccs811.c static int ccs811_get_measurement(struct ccs811_data *data) · line 214

Quoted 6 lines
drivers/iio/chemical/ccs811.c +1 -1
 	ret = i2c_smbus_read_i2c_block_data(data->client,
 					    CCS811_ALG_RESULT_DATA, 8,
 					    (char *)&data->buffer);
+out:
 	ccs811_set_wakeup(data, false);
-

Keep the blank line.

Quoted 3 lines

return ret;
}

Otherwise,

Signature · 2 lines
Kind regards,
Joshua Crofts
#2 lore raw

Hi Joshua,

Thanks for the review.

Quoted 3 lines

Please add a Fixes tag.

...

Sure, will add Fixes tag in next version

Quoted 7 lines

drivers/iio/chemical/ccs811.c static int ccs811_get_measurement(struct ccs811_data *data) · line 214

Quoted 6 lines
  	ret = i2c_smbus_read_i2c_block_data(data->client,
  					    CCS811_ALG_RESULT_DATA, 8,
  					    (char *)&data->buffer);
drivers/iio/chemical/ccs811.c +1 -1
+out:
  	ccs811_set_wakeup(data, false);
-

Keep the blank line.

Noted.

Quoted 3 lines

Otherwise,

Regards,
Nikhil