Skip to contentSkip to conversation

iio: proximity: hx9023s: Allocate trigger before requesting IRQ

PATCH Applied Myeonghun Pak 3 participants 3 messages Oct 16 – Oct 17 IIO

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 iio: proximity: hx9023s: Allocate trigger before requesting IRQ

An IRQ handler that already read trigger_enabled can poll data->trig after buffer disable. Detaching the virtual IRQ does not join this physical IRQ, and trigger deselection can drop the consumer reference. Devres may then free the trigger before joining the handler.

Allocate the trigger before requesting the IRQ so devres joins the handler before dropping the allocation reference.

This issue was identified as part of our ongoing research while reviewing kernel code.

Fixes 60df548277b7 ("iio: proximity: Add driver support for TYHX's HX9023S capacitive proximity sensor")
Assisted-by LLM

---
Compile-tested with GCC, W=1 (x86_64). No runtime testing.

 drivers/iio/proximity/hx9023s.c | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)
drivers/iio/proximity/hx9023s.c +8 -8
index 0199a63..2a6da55 100644
@@ -1133,14 +1133,6 @@ static int hx9023s_probe(struct i2c_client *client)
 		return dev_err_probe(dev, ret, "reg config failed\n");
 
 	if (client->irq) {
-		ret = devm_request_threaded_irq(dev, client->irq,
-						hx9023s_irq_handler,
-						hx9023s_irq_thread_handler,
-						IRQF_ONESHOT,
-						"hx9023s_event", indio_dev);
-		if (ret)
-			return ret;
-
 		data->trig = devm_iio_trigger_alloc(dev, "%s-dev%d",
 						    indio_dev->name,
 						    iio_device_id(indio_dev));
@@ -1150,6 +1142,14 @@ static int hx9023s_probe(struct i2c_client *client)
 		data->trig->ops = &hx9023s_trigger_ops;
 		iio_trigger_set_drvdata(data->trig, indio_dev);
 
+		ret = devm_request_threaded_irq(dev, client->irq,
+						hx9023s_irq_handler,
+						hx9023s_irq_thread_handler,
+						IRQF_ONESHOT,
+						"hx9023s_event", indio_dev);
+		if (ret)
+			return ret;
+
 		ret = devm_iio_trigger_register(dev, data->trig);
 		if (ret)
 			return dev_err_probe(dev, ret,
Reviewed-by on v1 1/1
#1 lore raw
Quoted 11 lines · On Thu, 15 Oct 2026 22:47:35 -0400 Myeonghun Pak <[email protected]> wrote:

An IRQ handler that already read trigger_enabled can poll data->trig after buffer disable. Detaching the virtual IRQ does not join this physical IRQ, and trigger deselection can drop the consumer reference. Devres may then free the trigger before joining the handler.

Allocate the trigger before requesting the IRQ so devres joins the handler before dropping the allocation reference.

This issue was identified as part of our ongoing research while reviewing kernel code.

Quoted 6 lines
Fixes 60df548277b7 ("iio: proximity: Add driver support for TYHX's HX9023S capacitive proximity sensor")
Assisted-by LLM

---

LGTM.

Signature · 2 lines
Kind regards,
Joshua Crofts
maintainer Applied
#2 lore raw
Quoted 21 lines · On Fri, 16 Oct 2026 20:25:24 +0200 Joshua Crofts <[email protected]>…
Quoted 11 lines · On Thu, 15 Oct 2026 22:47:35 -0400 Myeonghun Pak <[email protected]> wrote:

An IRQ handler that already read trigger_enabled can poll data->trig after buffer disable. Detaching the virtual IRQ does not join this physical IRQ, and trigger deselection can drop the consumer reference. Devres may then free the trigger before joining the handler.

Allocate the trigger before requesting the IRQ so devres joins the handler before dropping the allocation reference.

This issue was identified as part of our ongoing research while reviewing kernel code.

Quoted 6 lines
Fixes 60df548277b7 ("iio: proximity: Add driver support for TYHX's HX9023S capacitive proximity sensor")
Assisted-by LLM

---

Quoted 3 lines

LGTM.

Applied to the fixes-togreg branch of iio.git and marked for stable.

Thanks,

Jonathan

Quoted 1 line