From a83f8dc12ed9a0a8175c3fa56ebc48f6b6390e5e Mon Sep 17 00:00:00 2001 From: Yang Yingliang Date: Fri, 21 Dec 2018 13:01:24 +0800 Subject: [PATCH] device: add device_shutdown_by_driver() helper euler inclusion category: bugfix bugzilla: 5452 CVE: NA This patchset is add a kernel parameter to avoid kdump problem on Hi1620ES. It will be revert when we have better solution on Hi1620CS. [PATCH 1/4] Revert "iommu/arm-smmu-v3: Abort all transactions if SMMU is enabled in kdump kernel" [PATCH 2/4] device: add device_shutdown_one() helper [PATCH 3/4] device: add device_shutdown_by_driver() helper [PATCH 4/4] kexec: add kexec_device_shutdown() ------------------------------------------------ Add device_shutdown_by_driver() helper that shutdown the devices through driver name Signed-off-by: Yang Yingliang --- drivers/base/core.c | 30 ++++++++++++++++++++++++++++++ include/linux/device.h | 1 + 2 files changed, 31 insertions(+) diff --git a/drivers/base/core.c b/drivers/base/core.c index 60833f94f785..b5f8b5a26ab0 100644 --- a/drivers/base/core.c +++ b/drivers/base/core.c @@ -2929,6 +2929,36 @@ void device_shutdown(void) spin_unlock(&devices_kset->list_lock); } +void device_shutdown_by_driver(char *drv_name) +{ + struct device *dev, *parent, *next; + int len = 0; + + if (!drv_name) + return; + + len = strlen(drv_name); + if (!len) + return; + + wait_for_device_probe(); + device_block_probing(); + + spin_lock(&devices_kset->list_lock); + list_for_each_entry_safe(dev, next, &devices_kset->list, kobj.entry) { + if (dev->driver && len == strlen(dev->driver->name) && + !strncmp(dev->driver->name, drv_name, len)) { + parent = get_device(dev->parent); + get_device(dev); + list_del(&dev->kobj.entry); + spin_unlock(&devices_kset->list_lock); + device_shutdown_one(dev, parent); + spin_lock(&devices_kset->list_lock); + } + } + spin_unlock(&devices_kset->list_lock); +} + /* * Device logging functions */ diff --git a/include/linux/device.h b/include/linux/device.h index 8f882549edee..b397ca8c3cae 100644 --- a/include/linux/device.h +++ b/include/linux/device.h @@ -1321,6 +1321,7 @@ static inline int devtmpfs_mount(const char *mountpoint) { return 0; } /* drivers/base/power/shutdown.c */ extern void device_shutdown(void); +extern void device_shutdown_by_driver(char *drv_name); /* debugging and troubleshooting/diagnostic helpers. */ extern const char *dev_driver_string(const struct device *dev); -- GitLab