[PATCH 03/10] Input: applespi - cancel touchpad registration work on removal
From: Lee Jones
Date: Mon Nov 23 2026 - 13:32:45 EST
applespi_probe() allocates its driver state with devm_kzalloc_obj() and
initiates an asynchronous touchpad information query whose completion
schedules applespi->work to allocate and register the managed touchpad
input device in applespi_worker().
applespi_remove() disables the ACPI GPE and drains in-flight SPI writes
and reads, but never cancels applespi->work. If a touchpad info
response scheduled applespi->work just before applespi_drain_reads()
completed, applespi_worker() can run during or after devres teardown,
corrupting the device resource list via devm_input_allocate_device() and
dereferencing freed driver data.
Cancel applespi->work synchronously after applespi_drain_reads(), once
no further SPI responses can schedule it.
Fixes: 038b1a05eae6 ("Input: add Apple SPI keyboard and trackpad driver")
Closes: https://sashiko.dev/#/bug/linux-bb2fd773-6c20-468c-a092-6814f008077f
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: Lee Jones <lee@xxxxxxxxxx>
---
drivers/input/keyboard/applespi.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/drivers/input/keyboard/applespi.c b/drivers/input/keyboard/applespi.c
index 96c504f28495..d964cd3ee5af 100644
--- a/drivers/input/keyboard/applespi.c
+++ b/drivers/input/keyboard/applespi.c
@@ -1819,6 +1819,7 @@ static void applespi_remove(struct spi_device *spi)
device_wakeup_disable(&spi->dev);
applespi_drain_reads(applespi);
+ cancel_work_sync(&applespi->work);
debugfs_remove_recursive(applespi->debugfs_root);
}
--
2.56.1.750.gf70dc682cf-goog