Re: [PATCH] HID: wacom: Cancel init_work when probe fails after scheduling it

From: Jiri Kosina

Date: Thu Nov 19 2026 - 15:25:11 EST


On Sat, 5 Sep 2026, Aamir Ahmed wrote:

> wacom_parse_and_register() schedules wacom->init_work with a one second
> delay from wacom_query_tablet_data(), and only then opens the hardware
> for devices with WACOM_DEVICETYPE_WL_MONITOR, that is the wireless
> receiver's monitor interface and the ExpressKey Remote. If that
> hid_hw_open() fails, the error path stops the hardware and releases the
> driver's resources but leaves init_work pending.
>
> wacom_probe() then returns the error and the HID core releases the
> devres group it opened around probe(), which frees the wacom structure
> allocated with devm_kzalloc(). When init_work runs a second later,
> wacom_init_work() derives the wacom pointer from the work item, so
> _wacom_query_tablet_data() and wacom_led_control() read and write freed
> memory.
>
> This is the only work item that can be pending at that point. The
> others are scheduled from incoming reports, and the HID core drops
> reports for the whole of probe() by holding driver_input_lock, which
> this driver never releases early. The neighbouring BAMBOO_TOUCH error
> path already cancels init_work before failing for the same reason.
>
> Cancel init_work on the shared error path, after hid_hw_stop() as
> wacom_remove() does. The cancel is harmless where the work was never
> scheduled or was already cancelled.
>
> Fixes: a544c619a54b ("HID: wacom: do not attempt to switch mode while in probe")
> Reported-by: Sashiko AI <sashiko-bot@xxxxxxxxxx>
> Closes: https://lore.kernel.org/linux-input/20260905102908.ADE1F1F00A3D@xxxxxxxxxxxxxxx/
> Assisted-by: LLM
> Signed-off-by: Aamir Ahmed <elb12345@xxxxxxxxxxxxx>

Ping, Jason, your review of this one would be appreciated as well. Thanks,

--
Jiri Kosina
SUSE Labs