[PATCH 1/3] HID: Add shutdown callback for device drivers
From: Mario Limonciello <mario.limonciello@amd.com>
Date: 2026-09-10 17:03:26
Also in:
linux-usb, lkml
Subsystem:
hid core layer, the rest · Maintainers:
Jiri Kosina, Benjamin Tissoires, Linus Torvalds
HID device drivers can receive suspend and resume notifications through callbacks forwarded by their transport driver. There is no corresponding way to perform device-specific work during an orderly system shutdown. Add a shutdown callback to struct hid_driver and dispatch it from the HID bus shutdown operation. This allows a HID device driver to communicate with hardware before its transport is shut down. Assisted-by: LLM Signed-off-by: Mario Limonciello <mario.limonciello@amd.com> --- drivers/hid/hid-core.c | 13 +++++++++++++ include/linux/hid.h | 2 ++ 2 files changed, 15 insertions(+)
diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
index a3ff0514f9cdf..7c8c1aa1f09c3 100644
--- a/drivers/hid/hid-core.c
+++ b/drivers/hid/hid-core.c@@ -2738,6 +2738,18 @@ static int hid_bus_match(struct device *dev, const struct device_driver *drv) return hid_match_device(hdev, hdrv) != NULL; } +static void hid_bus_shutdown(struct device *dev) +{ + struct hid_driver *hdrv; + + if (!dev->driver) + return; + + hdrv = to_hid_driver(dev->driver); + if (hdrv->shutdown) + hdrv->shutdown(to_hid_device(dev)); +} + /** * hid_compare_device_paths - check if both devices share the same path * @hdev_a: hid device
@@ -3012,6 +3024,7 @@ const struct bus_type hid_bus_type = { .match = hid_bus_match, .probe = hid_device_probe, .remove = hid_device_remove, + .shutdown = hid_bus_shutdown, .uevent = hid_uevent, }; EXPORT_SYMBOL(hid_bus_type);
diff --git a/include/linux/hid.h b/include/linux/hid.h
index 8d17b741638c9..ddf57779bb3ef 100644
--- a/include/linux/hid.h
+++ b/include/linux/hid.h@@ -861,6 +861,7 @@ struct hid_usage_id { * @suspend: invoked on suspend (NULL means nop) * @resume: invoked on resume if device was not reset (NULL means nop) * @reset_resume: invoked on resume if device was reset (NULL means nop) + * @shutdown: invoked on system shutdown (NULL means nop) * @on_hid_hw_open: invoked when hid core opens first instance (NULL means nop) * @on_hid_hw_close: invoked when hid core closes last instance (NULL means nop) *
@@ -924,6 +925,7 @@ struct hid_driver { int (*suspend)(struct hid_device *hdev, pm_message_t message); int (*resume)(struct hid_device *hdev); int (*reset_resume)(struct hid_device *hdev); + void (*shutdown)(struct hid_device *hdev); void (*on_hid_hw_open)(struct hid_device *hdev); void (*on_hid_hw_close)(struct hid_device *hdev);
--
2.43.0