From caaba929568b60f3f2637de7473e93297b2d7ceb Mon Sep 17 00:00:00 2001 From: Yang Yingliang Date: Fri, 21 Dec 2018 12:11:51 +0800 Subject: [PATCH] device: add device_shutdown_one() 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() ------------------------------------------------ Move the shutdown device code into a new function device_shutdown_one(). Signed-off-by: Yang Yingliang --- drivers/base/core.c | 65 ++++++++++++++++++++++++--------------------- 1 file changed, 35 insertions(+), 30 deletions(-) diff --git a/drivers/base/core.c b/drivers/base/core.c index 04bbcd779e11..60833f94f785 100644 --- a/drivers/base/core.c +++ b/drivers/base/core.c @@ -2854,6 +2854,40 @@ int device_move(struct device *dev, struct device *new_parent, } EXPORT_SYMBOL_GPL(device_move); +static void device_shutdown_one(struct device *dev, struct device *parent) +{ + /* hold lock to avoid race with probe/release */ + if (parent) + device_lock(parent); + device_lock(dev); + + /* Don't allow any more runtime suspends */ + pm_runtime_get_noresume(dev); + pm_runtime_barrier(dev); + + if (dev->class && dev->class->shutdown_pre) { + if (initcall_debug) + dev_info(dev, "shutdown_pre\n"); + dev->class->shutdown_pre(dev); + } + if (dev->bus && dev->bus->shutdown) { + if (initcall_debug) + dev_info(dev, "shutdown\n"); + dev->bus->shutdown(dev); + } else if (dev->driver && dev->driver->shutdown) { + if (initcall_debug) + dev_info(dev, "shutdown\n"); + dev->driver->shutdown(dev); + } + + device_unlock(dev); + if (parent) + device_unlock(parent); + + put_device(dev); + put_device(parent); +} + /** * device_shutdown - call ->shutdown() on each device to shutdown. */ @@ -2888,36 +2922,7 @@ void device_shutdown(void) list_del_init(&dev->kobj.entry); spin_unlock(&devices_kset->list_lock); - /* hold lock to avoid race with probe/release */ - if (parent) - device_lock(parent); - device_lock(dev); - - /* Don't allow any more runtime suspends */ - pm_runtime_get_noresume(dev); - pm_runtime_barrier(dev); - - if (dev->class && dev->class->shutdown_pre) { - if (initcall_debug) - dev_info(dev, "shutdown_pre\n"); - dev->class->shutdown_pre(dev); - } - if (dev->bus && dev->bus->shutdown) { - if (initcall_debug) - dev_info(dev, "shutdown\n"); - dev->bus->shutdown(dev); - } else if (dev->driver && dev->driver->shutdown) { - if (initcall_debug) - dev_info(dev, "shutdown\n"); - dev->driver->shutdown(dev); - } - - device_unlock(dev); - if (parent) - device_unlock(parent); - - put_device(dev); - put_device(parent); + device_shutdown_one(dev, parent); spin_lock(&devices_kset->list_lock); } -- GitLab