From ffd863a2dbebbab065653eb2c351af61871d5c93 Mon Sep 17 00:00:00 2001 From: Zongmin Zhou Date: Tue, 8 Jul 2025 11:19:07 +0800 Subject: [PATCH] driver core: add shutdown hook on faux bus Some devices based on faux bus may have to do something during system shutdown. So add shutdown hook to let it use its own shutdown hooks if had. Signed-off-by: Zongmin Zhou --- drivers/base/faux.c | 11 +++++++++++ drivers/usb/usbip/vhci_hcd.c | 12 ++++++++++++ include/linux/device/faux.h | 1 + 3 files changed, 24 insertions(+) diff --git a/drivers/base/faux.c b/drivers/base/faux.c index cbaf265e9b6c..61cc0a25d2c7 100644 --- a/drivers/base/faux.c +++ b/drivers/base/faux.c @@ -92,6 +92,16 @@ static int faux_pm_resume(struct device *dev) #define faux_pm_resume NULL #endif +static void faux_shutdown(struct device *dev) +{ + struct faux_object *faux_obj = to_faux_object(dev); + struct faux_device *faux_dev = &faux_obj->faux_dev; + const struct faux_device_ops *faux_ops = faux_obj->faux_ops; + + if (faux_ops && faux_ops->shutdown) + faux_ops->shutdown(faux_dev); +} + static const struct bus_type faux_bus_type = { .name = "faux", .match = faux_match, @@ -99,6 +109,7 @@ static const struct bus_type faux_bus_type = { .remove = faux_remove, .suspend = faux_pm_suspend, .resume = faux_pm_resume, + .shutdown = faux_shutdown, }; static struct device_driver faux_driver = { diff --git a/drivers/usb/usbip/vhci_hcd.c b/drivers/usb/usbip/vhci_hcd.c index 79c026108d7b..01ce50b6abd5 100644 --- a/drivers/usb/usbip/vhci_hcd.c +++ b/drivers/usb/usbip/vhci_hcd.c @@ -1481,10 +1481,22 @@ static int vhci_hcd_resume(struct faux_device *fdev) #endif +static void vhci_hcd_shutdown(struct faux_device *fdev) +{ + /* + * Must to do something before system shutdown. + * usbip devices attached to vhci-hcd,should be detached before system shutdown. + * Otherwise,this device's status on stub + * will always be SDEV_ST_USED,and can't be attached anymore. + */ + vhci_hcd_remove(fdev); +} + static struct faux_device_ops vhci_driver = { .remove = vhci_hcd_remove, .suspend = vhci_hcd_suspend, .resume = vhci_hcd_resume, + .shutdown = vhci_hcd_shutdown, }; static void del_faux_devices(void) diff --git a/include/linux/device/faux.h b/include/linux/device/faux.h index 9dc4b81c672c..b3b66ab5de28 100644 --- a/include/linux/device/faux.h +++ b/include/linux/device/faux.h @@ -47,6 +47,7 @@ struct faux_device_ops { void (*remove)(struct faux_device *faux_dev); int (*suspend)(struct faux_device *faux_dev, pm_message_t state); int (*resume)(struct faux_device *faux_dev); + void (*shutdown)(struct faux_device *faux_dev); }; struct faux_device *faux_device_create(const char *name, -- 2.25.1