Skip to contentSkip to conversation

iio: chemical: ccs811: Fix trigger reference leak in ccs811_probe()

PATCH In review Wentao Liang 2 participants 3 messages Sep 16 – Nov 6

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

PATCH 1/1 iio: chemical: ccs811: Fix trigger reference leak in ccs811_probe()

The reference taken with iio_trigger_get() is only dropped by iio_dev_release() when INDIO_BUFFER_TRIGGERED is set. If iio_triggered_buffer_setup() fails before setting that mode, the reference acquired for indio_dev->trig leaks. Move the iio_trigger_get() after the buffer setup succeeds.

Fixes f1f065d7ac30 ("iio: chemical: ccs811: Add support for data ready trigger")
---
 drivers/iio/chemical/ccs811.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/iio/chemical/ccs811.c +3 -2
index 998c9239c4c7..bbc8284316ab 100644
@@ -503,8 +503,6 @@ static int ccs811_probe(struct i2c_client *client)
 		ret = iio_trigger_register(data->drdy_trig);
 		if (ret)
 			goto err_poweroff;
-
-		indio_dev->trig = iio_trigger_get(data->drdy_trig);
 	}
 
 	ret = iio_triggered_buffer_setup(indio_dev, NULL,
@@ -515,6 +513,9 @@ static int ccs811_probe(struct i2c_client *client)
 		goto err_trigger_unregister;
 	}
 
+	if (data->drdy_trig)
+		indio_dev->trig = iio_trigger_get(data->drdy_trig);
+
 	ret = iio_device_register(indio_dev);
 	if (ret < 0) {
 		dev_err(&client->dev, "unable to register iio device\n");
Signature · 1 line
2.34.1
maintainer
#1 lore raw
Quoted 9 lines · On Wed, 16 Sep 2026 16:25:34 +0000 Wentao Liang <[email protected]> wrote:

The reference taken with iio_trigger_get() is only dropped by iio_dev_release() when INDIO_BUFFER_TRIGGERED is set. If iio_triggered_buffer_setup() fails before setting that mode, the reference acquired for indio_dev->trig leaks. Move the iio_trigger_get() after the buffer setup succeeds.

Fixes f1f065d7ac30 ("iio: chemical: ccs811: Add support for data ready trigger")

Not this solution. See bma220 and other similar replies.

#2 lore raw

Hi Jonathan,

Sorry for the very late reply.

I understand your feedback: this fix should not depend on a subtle ordering constraint in the driver. Trigger lifetime handling needs a broader solution in the IIO core, as you explained in the bma220 thread.

Please disregard this patch; I will not resend this approach as v2. Thank you for the review.

For transparency, we use static analysis tools to identify candidates, then DeepSeek and GPT-6.1 Sol to assist with auditing and preparing fixes. I am responsible for verifying the findings and changes before submission.

Best regards,
Wentao