[PATCH net v3 1/2] nfc: trf7970a: set up lock and timeout work before requesting IRQ
Fan Wu <[email protected]> Sat, 1 Aug 2026 05:10:57 +0000
| Newsgroups | dev.linux.lists.oe-linux-nfc,org.kernel.vger.linux-kernel,org.kernel.vger.linux-wireless,org.kernel.vger.netdev,org.kernel.vger.stable |
|---|---|
| Message-ID | <[email protected]> |
trf7970a_probe() registers the threaded IRQ handler before it
initialises the lock the handler takes on entry and the delayed work it
can queue. An interrupt arriving in that window can use either object
before it has been initialised.
Set up both before registering the IRQ, and use devm_mutex_init() for
the lock. This makes the mutex teardown part of the devres lifetime: the
IRQ is released before the mutex is destroyed, and both precede freeing
trf. It also retains CONFIG_DEBUG_MUTEXES lifetime checking.
The explicit mutex_destroy() calls and the now-empty err_destroy_lock
label are removed.
This issue was found by an in-house static analysis tool.
Fixes: 165063f1dac4 ("NFC: trf7970a: Add driver with ISO/IEC 14443 Type 2 Tag Support")
Cc: [email protected]
Assisted-by: Codex:gpt-5.6
Signed-off-by: Fan Wu <[email protected]>
---
drivers/nfc/trf7970a.c | 17 ++++++++---------
1 file changed, 8 insertions(+), 9 deletions(-)
diff --git a/drivers/nfc/trf7970a.c b/drivers/nfc/trf7970a.c
index f22e091..9c6f8db 100644
--- a/drivers/nfc/trf7970a.c
+++ b/drivers/nfc/trf7970a.c
@@ -2124,6 +2124,12 @@ static int trf7970a_probe(struct spi_device *spi)
}
}
+ ret = devm_mutex_init(trf->dev, &trf->lock);
+ if (ret)
+ return ret;
+
+ INIT_DELAYED_WORK(&trf->timeout_work, trf7970a_timeout_work_handler);
+
ret = devm_request_threaded_irq(trf->dev, spi->irq, NULL,
trf7970a_irq,
IRQF_TRIGGER_RISING | IRQF_ONESHOT,
@@ -2133,20 +2139,17 @@ static int trf7970a_probe(struct spi_device *spi)
return ret;
}
- mutex_init(&trf->lock);
- INIT_DELAYED_WORK(&trf->timeout_work, trf7970a_timeout_work_handler);
-
trf->vin_regulator = devm_regulator_get(&spi->dev, "vin");
if (IS_ERR(trf->vin_regulator)) {
ret = PTR_ERR(trf->vin_regulator);
dev_err(trf->dev, "Can't get VIN regulator: %d\n", ret);
- goto err_destroy_lock;
+ return ret;
}
ret = regulator_enable(trf->vin_regulator);
if (ret) {
dev_err(trf->dev, "Can't enable VIN: %d\n", ret);
- goto err_destroy_lock;
+ return ret;
}
uvolts = regulator_get_voltage(trf->vin_regulator);
@@ -2212,8 +2215,6 @@ err_disable_vddio_regulator:
regulator_disable(trf->vddio_regulator);
err_disable_vin_regulator:
regulator_disable(trf->vin_regulator);
-err_destroy_lock:
- mutex_destroy(&trf->lock);
return ret;
}
@@ -2232,8 +2233,6 @@ static void trf7970a_remove(struct spi_device *spi)
regulator_disable(trf->vddio_regulator);
regulator_disable(trf->vin_regulator);
-
- mutex_destroy(&trf->lock);
}
#ifdef CONFIG_PM_SLEEP
--
2.34.1