[PATCH 1/4] platform: arm64: thinkpad-t14s-ec: fix IRQ race condition

Sebastian Reichel posted 4 patches 1 month, 1 week ago
There is a newer version of this series
[PATCH 1/4] platform: arm64: thinkpad-t14s-ec: fix IRQ race condition
Posted by Sebastian Reichel 1 month, 1 week ago
Fix a race condition, that an input key related interrupt might be
triggered before the input handler has been registered, which results
in a NULL pointer dereference. This can happen if the user enables
the keyboard backlight shortly before the driver is being probed.

Fixes: 60b7ab6ce030 ("platform: arm64: thinkpad-t14s-ec: new driver")
Signed-off-by: Sebastian Reichel <sre@kernel.org>
---
 drivers/platform/arm64/lenovo-thinkpad-t14s.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/drivers/platform/arm64/lenovo-thinkpad-t14s.c b/drivers/platform/arm64/lenovo-thinkpad-t14s.c
index 1d5d11adaf32..c1c01b977f2b 100644
--- a/drivers/platform/arm64/lenovo-thinkpad-t14s.c
+++ b/drivers/platform/arm64/lenovo-thinkpad-t14s.c
@@ -557,12 +557,6 @@ static int t14s_ec_probe(struct i2c_client *client)
 		return dev_err_probe(dev, PTR_ERR(ec->regmap),
 				     "Failed to init regmap\n");
 
-	ret = devm_request_threaded_irq(dev, client->irq, NULL,
-					t14s_ec_irq_handler,
-					IRQF_ONESHOT, dev_name(dev), ec);
-	if (ret < 0)
-		return dev_err_probe(dev, ret, "Failed to get IRQ\n");
-
 	ret = t14s_leds_probe(ec);
 	if (ret < 0)
 		return ret;
@@ -579,6 +573,12 @@ static int t14s_ec_probe(struct i2c_client *client)
 	if (ret < 0)
 		return ret;
 
+	ret = devm_request_threaded_irq(dev, client->irq, NULL,
+					t14s_ec_irq_handler,
+					IRQF_ONESHOT, dev_name(dev), ec);
+	if (ret < 0)
+		return dev_err_probe(dev, ret, "Failed to get IRQ\n");
+
 	/*
 	 * Disable wakeup support by default, because the driver currently does
 	 * not support masking any events and the laptop should not wake up when

-- 
2.51.0
Re: [PATCH 1/4] platform: arm64: thinkpad-t14s-ec: fix IRQ race condition
Posted by Bryan O'Donoghue 1 month, 1 week ago
On 05/11/2025 23:22, Sebastian Reichel wrote:
> Fix a race condition, that an input key related interrupt might be
> triggered before the input handler has been registered, which results
> in a NULL pointer dereference. This can happen if the user enables
> the keyboard backlight shortly before the driver is being probed.
> 
> Fixes: 60b7ab6ce030 ("platform: arm64: thinkpad-t14s-ec: new driver")
> Signed-off-by: Sebastian Reichel <sre@kernel.org>
> ---
Enabling interrupts late in probe seems like a bit of a no-brainer.

One thing though is the commit log might productively contain the 
backtrace so that people can match bug fixes to specific backtraces.

Reviewed-by: Bryan O'Donoghue <bod@kernel.org>