From: sashiko-bot@kernel.org
To: "Shih-Yuan Lee" <fourdollars@debian.org>
Cc: dmitry.torokhov@gmail.com, linux-input@vger.kernel.org
Subject: Re: [PATCH v5 1/3] Input: applespi - cancel pending work on driver remove
Date: Sat, 11 Jul 2026 13:26:37 +0000 [thread overview]
Message-ID: <20260711132638.09EBE1F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260711131140.18777-2-fourdollars@debian.org>
Thank you for your contribution! Sashiko AI review found 6 potential issue(s) to consider:
Pre-existing issues:
- [High] Repeated PACKET_DEV_INFO packets lead to unbounded devm memory leaks and duplicate input device registrations.
- [High] Unchecked access of asynchronously allocated applespi->touchpad_input_dev in the debugfs tp_dim open handler.
- [High] Unbound wait in applespi_drain_writes() can block driver unbind and suspend forever if hardware is unresponsive.
- [High] Missing async teardown in applespi_probe error path if GPE enablement fails.
- [High] Mismatched finger data reported to input subsystem due to flawed iteration logic.
- [Low] Redundant manual assignment of dev.parent on input devices allocated with devm_input_allocate_device().
--
--- Patch [1]: [PATCH v5 1/3] Input: applespi - cancel pending work on driver remove ---
commit 541134ed7dfbfee9d31126ce14257c1f72d8e7a7
Author: Shih-Yuan Lee <fourdollars@debian.org>
Input: applespi - cancel pending work on driver remove
During driver removal in applespi_remove(), the managed private data
structure is freed by devres. However, the driver does not cancel the
asynchronous work applespi->work, which registers the touchpad input
device.
> diff --git a/drivers/input/keyboard/applespi.c b/drivers/input/keyboard/applespi.c
> --- a/drivers/input/keyboard/applespi.c
> +++ b/drivers/input/keyboard/applespi.c
> @@ -1820,8 +1820,10 @@ static void applespi_remove(struct spi_device *spi)
> {
> struct applespi_data *applespi = spi_get_drvdata(spi);
>
> applespi_drain_writes(applespi);
[Severity: High]
This isn't a bug introduced by this patch, but can this wait indefinitely
and block driver unbind or system suspend?
applespi_drain_writes() waits for the hardware without a timeout:
drivers/input/keyboard/applespi.c:applespi_drain_writes() {
...
wait_event_lock_irq(applespi->drain_complete, !applespi->write_active,
applespi->cmd_msg_lock);
...
}
If the external hardware hangs and write_active remains true, would this
task become blocked forever?
>
> acpi_disable_gpe(NULL, applespi->gpe);
> acpi_remove_gpe_handler(NULL, applespi->gpe, applespi_notify);
> device_wakeup_disable(&spi->dev);
>
> applespi_drain_reads(applespi);
>
> + cancel_work_sync(&applespi->work);
> +
> debugfs_remove_recursive(applespi->debugfs_root);
> }
[Severity: Low]
This isn't a bug introduced by this patch, but does this code redundantly
assign the parent device?
drivers/input/keyboard/applespi.c:applespi_register_touchpad_device() {
...
touchpad_input_dev = devm_input_allocate_device(&applespi->spi->dev);
...
touchpad_input_dev->dev.parent = &applespi->spi->dev;
...
}
And similarly in applespi_probe():
drivers/input/keyboard/applespi.c:applespi_probe() {
...
applespi->keyboard_input_dev->dev.parent = &spi->dev;
...
}
The input subsystem guidelines state that devm_input_allocate_device()
automatically sets the parent, making manual assignment redundant.
[Severity: High]
This isn't a bug introduced by this patch, but can a repeated
PACKET_DEV_INFO from the hardware cause an unbounded memory leak and
duplicate device registrations?
drivers/input/keyboard/applespi.c:applespi_handle_cmd_response() {
...
if (packet->type == PACKET_DEV_INFO) {
...
schedule_work(&applespi->work);
}
...
}
When the work runs, it executes applespi_register_touchpad_device(),
which unconditionally allocates a new managed device:
drivers/input/keyboard/applespi.c:applespi_register_touchpad_device() {
...
touchpad_input_dev = devm_input_allocate_device(&applespi->spi->dev);
...
error = input_register_device(touchpad_input_dev);
...
}
If the peripheral sends multiple PACKET_DEV_INFO packets, would this
blindly allocate and register multiple touchpad devices without checking
if one already exists?
[Severity: High]
This isn't a bug introduced by this patch, but could this dereference a
NULL pointer if the async worker hasn't completed initializing the
touchpad?
drivers/input/keyboard/applespi.c:applespi_probe() {
...
debugfs_create_file("tp_dim", 0400, applespi->debugfs_root, applespi,
&applespi_tp_dim_fops);
...
}
If userspace opens this file before applespi_register_touchpad_device()
is finished by the workqueue, applespi_tp_dim_open() is called:
drivers/input/keyboard/applespi.c:applespi_tp_dim_open() {
...
applespi->touchpad_input_dev->id.product,
...
}
Since touchpad_input_dev might still be NULL, will this crash the kernel?
[Severity: High]
This isn't a bug introduced by this patch, but does the probe error path
miss cleaning up async tasks and SPI reads?
drivers/input/keyboard/applespi.c:applespi_probe() {
...
acpi_sts = acpi_enable_gpe(NULL, applespi->gpe);
if (ACPI_FAILURE(acpi_sts)) {
dev_err(&spi->dev, "failed to enable GPE\n");
return -ENODEV;
}
...
}
If acpi_install_gpe_handler() (called earlier) receives an interrupt
before acpi_enable_gpe() fails, it could queue an async SPI transfer or
work item. Returning -ENODEV immediately frees the applespi structure
without calling applespi_drain_reads() or cancel_work_sync(), which
could result in a use-after-free.
[Severity: High]
This isn't a bug introduced by this patch, but does this iteration logic
mismatch the finger data reported to the input subsystem?
drivers/input/keyboard/applespi.c:report_tp_state() {
...
report_finger_data(input, applespi->slots[i], &applespi->pos[i],
&t->fingers[i]);
...
}
If earlier loops filter out fingers (e.g., touch_major == 0) and store
their coordinates densely in applespi->pos, reusing the same sequential
index i for t->fingers[i] could pair the packed positions with the
wrong original finger data from the hardware. Could this corrupt
multitouch reporting?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260711131140.18777-1-fourdollars@debian.org?part=1
next prev parent reply other threads:[~2026-07-11 13:26 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-11 5:52 [PATCH 0/1] Input: applespi - force PIO mode on MacBook8,1 Shih-Yuan Lee
2026-07-11 5:52 ` [PATCH 1/1] " Shih-Yuan Lee
2026-07-11 6:00 ` sashiko-bot
2026-07-11 6:54 ` [PATCH v2 0/3] Input: applespi - fixes for DMA timeout, UAF, and NULL pointer dereference Shih-Yuan Lee
2026-07-11 6:54 ` [PATCH v2 1/3] Input: applespi - force PIO mode on MacBook8,1 Shih-Yuan Lee
2026-07-11 7:04 ` sashiko-bot
2026-07-11 6:54 ` [PATCH v2 2/3] Input: applespi - cancel pending work on driver remove Shih-Yuan Lee
2026-07-11 7:09 ` sashiko-bot
2026-07-11 6:54 ` [PATCH v2 3/3] Input: applespi - fix NULL pointer dereference in tp_dim open Shih-Yuan Lee
2026-07-11 7:08 ` sashiko-bot
2026-07-11 11:49 ` [PATCH v4 0/3] Input/SPI: fixes for MacBook8,1 DMA timeout, UAF, and NULL pointer dereference Shih-Yuan Lee
2026-07-11 11:49 ` [PATCH v4 1/3] Input: applespi - cancel pending work on driver remove Shih-Yuan Lee
2026-07-11 12:05 ` sashiko-bot
2026-07-11 11:49 ` [PATCH v4 2/3] Input: applespi - fix NULL pointer dereference in tp_dim open Shih-Yuan Lee
2026-07-11 12:02 ` sashiko-bot
2026-07-11 11:49 ` [PATCH v4 3/3] spi: pxa2xx: disable DMA for Apple MacBook8,1 Shih-Yuan Lee
2026-07-11 11:58 ` sashiko-bot
2026-07-11 13:11 ` [PATCH v5 0/3] Input/SPI: fixes for MacBook8,1 DMA timeout, UAF, and NULL pointer dereference Shih-Yuan Lee
2026-07-11 13:11 ` [PATCH v5 1/3] Input: applespi - cancel pending work on driver remove Shih-Yuan Lee
2026-07-11 13:26 ` sashiko-bot [this message]
2026-07-11 21:55 ` Dmitry Torokhov
2026-07-11 13:11 ` [PATCH v5 2/3] Input: applespi - fix NULL pointer dereference in tp_dim open Shih-Yuan Lee
2026-07-11 13:26 ` sashiko-bot
2026-07-11 13:11 ` [PATCH v5 3/3] spi: pxa2xx: disable DMA for Apple MacBook8,1 Shih-Yuan Lee
2026-07-12 16:05 ` [PATCH v5 0/3] Input/SPI: fixes for MacBook8,1 DMA timeout, UAF, and NULL pointer dereference Shih-Yuan Lee
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260711132638.09EBE1F000E9@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=dmitry.torokhov@gmail.com \
--cc=fourdollars@debian.org \
--cc=linux-input@vger.kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox