[PATCH 12/12] pinctrl: sx150x: Register threaded IRQ after adding GPIO chip
From: Lee Jones
Date: Wed Dec 02 2026 - 04:33:21 EST
sx150x_probe() calls devm_request_threaded_irq() with IRQF_SHARED before
devm_gpiochip_add_data(). If a shared or pending interrupt fires before
the GPIO chip is registered, sx150x_irq_thread_fn() passes a NULL
pctl->gpio.irq.domain to irq_find_mapping(). Because devres tears down
resources in LIFO order, this ordering also removes the GPIO chip and
its IRQ domain while the threaded IRQ handler is still active during
probe failure or device unbind, causing a use-after-free.
Move devm_request_threaded_irq() after devm_gpiochip_add_data() so the
IRQ domain is created before the handler can run and torn down after the
IRQ is freed.
Fixes: 0a04d767af8c ("pinctrl: sx150x: Use irqchip template")
Closes: https://sashiko.dev/#/bug/linux-a189ae4f-4985-46ad-acce-6092c69d60e0
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: Lee Jones <lee@xxxxxxxxxx>
---
drivers/pinctrl/pinctrl-sx150x.c | 12 +++++++-----
1 file changed, 7 insertions(+), 5 deletions(-)
diff --git a/drivers/pinctrl/pinctrl-sx150x.c b/drivers/pinctrl/pinctrl-sx150x.c
index 0cf68fe22f89..bbc8c4f1f44a 100644
--- a/drivers/pinctrl/pinctrl-sx150x.c
+++ b/drivers/pinctrl/pinctrl-sx150x.c
@@ -1164,7 +1164,7 @@ static int sx150x_probe(struct i2c_client *client)
I2C_FUNC_SMBUS_WRITE_WORD_DATA;
struct device *dev = &client->dev;
struct sx150x_pinctrl *pctl;
- u32 irq_type;
+ u32 irq_type = 0;
int ret;
if (!i2c_check_functionality(client->adapter, i2c_funcs))
@@ -1288,7 +1288,13 @@ static int sx150x_probe(struct i2c_client *client)
"unsupported irq trigger type %x\n",
irq_type);
}
+ }
+ ret = devm_gpiochip_add_data(dev, &pctl->gpio, pctl);
+ if (ret)
+ return ret;
+
+ if (client->irq > 0) {
ret = devm_request_threaded_irq(dev, client->irq, NULL,
sx150x_irq_thread_fn,
IRQF_ONESHOT | IRQF_SHARED |
@@ -1298,10 +1304,6 @@ static int sx150x_probe(struct i2c_client *client)
return ret;
}
- ret = devm_gpiochip_add_data(dev, &pctl->gpio, pctl);
- if (ret)
- return ret;
-
/*
* Pin control functions need to be enabled AFTER registering the
* GPIO chip because sx150x_pinconf_set() calls
--
2.56.1.911.g883d8bcb20-goog