Commit 6da2f2cc authored by Bjorn Helgaas's avatar Bjorn Helgaas

PCI/PM: Make power management op coding style consistent

Some of the power management ops use this style:

  struct device_driver *drv = dev->driver;
  if (drv && drv->pm && drv->pm->prepare(dev))
    drv->pm->prepare(dev);

while others use this:

  const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL;
  if (pm && pm->runtime_resume)
    pm->runtime_resume(dev);

Convert the first style to the second so they're all consistent.  Remove
local "error" variables when unnecessary.  No functional change intended.

Link: https://lore.kernel.org/r/20191014230016.240912-6-helgaas@kernel.orgSigned-off-by: default avatarBjorn Helgaas <bhelgaas@google.com>
Reviewed-by: default avatarRafael J. Wysocki <rafael.j.wysocki@intel.com>
parent f7b32a86
...@@ -679,11 +679,11 @@ static bool pci_has_legacy_pm_support(struct pci_dev *pci_dev) ...@@ -679,11 +679,11 @@ static bool pci_has_legacy_pm_support(struct pci_dev *pci_dev)
static int pci_pm_prepare(struct device *dev) static int pci_pm_prepare(struct device *dev)
{ {
struct device_driver *drv = dev->driver;
struct pci_dev *pci_dev = to_pci_dev(dev); struct pci_dev *pci_dev = to_pci_dev(dev);
const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL;
if (drv && drv->pm && drv->pm->prepare) { if (pm && pm->prepare) {
int error = drv->pm->prepare(dev); int error = pm->prepare(dev);
if (error < 0) if (error < 0)
return error; return error;
...@@ -917,8 +917,7 @@ static int pci_pm_suspend_noirq(struct device *dev) ...@@ -917,8 +917,7 @@ static int pci_pm_suspend_noirq(struct device *dev)
static int pci_pm_resume_noirq(struct device *dev) static int pci_pm_resume_noirq(struct device *dev)
{ {
struct pci_dev *pci_dev = to_pci_dev(dev); struct pci_dev *pci_dev = to_pci_dev(dev);
struct device_driver *drv = dev->driver; const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL;
int error = 0;
if (dev_pm_may_skip_resume(dev)) if (dev_pm_may_skip_resume(dev))
return 0; return 0;
...@@ -946,17 +945,16 @@ static int pci_pm_resume_noirq(struct device *dev) ...@@ -946,17 +945,16 @@ static int pci_pm_resume_noirq(struct device *dev)
if (pci_has_legacy_pm_support(pci_dev)) if (pci_has_legacy_pm_support(pci_dev))
return pci_legacy_resume_early(dev); return pci_legacy_resume_early(dev);
if (drv && drv->pm && drv->pm->resume_noirq) if (pm && pm->resume_noirq)
error = drv->pm->resume_noirq(dev); return pm->resume_noirq(dev);
return error; return 0;
} }
static int pci_pm_resume(struct device *dev) static int pci_pm_resume(struct device *dev)
{ {
struct pci_dev *pci_dev = to_pci_dev(dev); struct pci_dev *pci_dev = to_pci_dev(dev);
const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL; const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL;
int error = 0;
/* /*
* This is necessary for the suspend error path in which resume is * This is necessary for the suspend error path in which resume is
...@@ -972,12 +970,12 @@ static int pci_pm_resume(struct device *dev) ...@@ -972,12 +970,12 @@ static int pci_pm_resume(struct device *dev)
if (pm) { if (pm) {
if (pm->resume) if (pm->resume)
error = pm->resume(dev); return pm->resume(dev);
} else { } else {
pci_pm_reenable_device(pci_dev); pci_pm_reenable_device(pci_dev);
} }
return error; return 0;
} }
#else /* !CONFIG_SUSPEND */ #else /* !CONFIG_SUSPEND */
...@@ -1037,16 +1035,16 @@ static int pci_pm_freeze(struct device *dev) ...@@ -1037,16 +1035,16 @@ static int pci_pm_freeze(struct device *dev)
static int pci_pm_freeze_noirq(struct device *dev) static int pci_pm_freeze_noirq(struct device *dev)
{ {
struct pci_dev *pci_dev = to_pci_dev(dev); struct pci_dev *pci_dev = to_pci_dev(dev);
struct device_driver *drv = dev->driver; const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL;
if (pci_has_legacy_pm_support(pci_dev)) if (pci_has_legacy_pm_support(pci_dev))
return pci_legacy_suspend_late(dev, PMSG_FREEZE); return pci_legacy_suspend_late(dev, PMSG_FREEZE);
if (drv && drv->pm && drv->pm->freeze_noirq) { if (pm && pm->freeze_noirq) {
int error; int error;
error = drv->pm->freeze_noirq(dev); error = pm->freeze_noirq(dev);
suspend_report_result(drv->pm->freeze_noirq, error); suspend_report_result(pm->freeze_noirq, error);
if (error) if (error)
return error; return error;
} }
...@@ -1065,8 +1063,8 @@ static int pci_pm_freeze_noirq(struct device *dev) ...@@ -1065,8 +1063,8 @@ static int pci_pm_freeze_noirq(struct device *dev)
static int pci_pm_thaw_noirq(struct device *dev) static int pci_pm_thaw_noirq(struct device *dev)
{ {
struct pci_dev *pci_dev = to_pci_dev(dev); struct pci_dev *pci_dev = to_pci_dev(dev);
struct device_driver *drv = dev->driver; const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL;
int error = 0; int error;
if (pcibios_pm_ops.thaw_noirq) { if (pcibios_pm_ops.thaw_noirq) {
error = pcibios_pm_ops.thaw_noirq(dev); error = pcibios_pm_ops.thaw_noirq(dev);
...@@ -1090,10 +1088,10 @@ static int pci_pm_thaw_noirq(struct device *dev) ...@@ -1090,10 +1088,10 @@ static int pci_pm_thaw_noirq(struct device *dev)
if (pci_has_legacy_pm_support(pci_dev)) if (pci_has_legacy_pm_support(pci_dev))
return pci_legacy_resume_early(dev); return pci_legacy_resume_early(dev);
if (drv && drv->pm && drv->pm->thaw_noirq) if (pm && pm->thaw_noirq)
error = drv->pm->thaw_noirq(dev); return pm->thaw_noirq(dev);
return error; return 0;
} }
static int pci_pm_thaw(struct device *dev) static int pci_pm_thaw(struct device *dev)
...@@ -1164,24 +1162,24 @@ static int pci_pm_poweroff_late(struct device *dev) ...@@ -1164,24 +1162,24 @@ static int pci_pm_poweroff_late(struct device *dev)
static int pci_pm_poweroff_noirq(struct device *dev) static int pci_pm_poweroff_noirq(struct device *dev)
{ {
struct pci_dev *pci_dev = to_pci_dev(dev); struct pci_dev *pci_dev = to_pci_dev(dev);
struct device_driver *drv = dev->driver; const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL;
if (dev_pm_smart_suspend_and_suspended(dev)) if (dev_pm_smart_suspend_and_suspended(dev))
return 0; return 0;
if (pci_has_legacy_pm_support(to_pci_dev(dev))) if (pci_has_legacy_pm_support(pci_dev))
return pci_legacy_suspend_late(dev, PMSG_HIBERNATE); return pci_legacy_suspend_late(dev, PMSG_HIBERNATE);
if (!drv || !drv->pm) { if (!pm) {
pci_fixup_device(pci_fixup_suspend_late, pci_dev); pci_fixup_device(pci_fixup_suspend_late, pci_dev);
return 0; return 0;
} }
if (drv->pm->poweroff_noirq) { if (pm->poweroff_noirq) {
int error; int error;
error = drv->pm->poweroff_noirq(dev); error = pm->poweroff_noirq(dev);
suspend_report_result(drv->pm->poweroff_noirq, error); suspend_report_result(pm->poweroff_noirq, error);
if (error) if (error)
return error; return error;
} }
...@@ -1207,8 +1205,8 @@ static int pci_pm_poweroff_noirq(struct device *dev) ...@@ -1207,8 +1205,8 @@ static int pci_pm_poweroff_noirq(struct device *dev)
static int pci_pm_restore_noirq(struct device *dev) static int pci_pm_restore_noirq(struct device *dev)
{ {
struct pci_dev *pci_dev = to_pci_dev(dev); struct pci_dev *pci_dev = to_pci_dev(dev);
struct device_driver *drv = dev->driver; const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL;
int error = 0; int error;
if (pcibios_pm_ops.restore_noirq) { if (pcibios_pm_ops.restore_noirq) {
error = pcibios_pm_ops.restore_noirq(dev); error = pcibios_pm_ops.restore_noirq(dev);
...@@ -1222,17 +1220,16 @@ static int pci_pm_restore_noirq(struct device *dev) ...@@ -1222,17 +1220,16 @@ static int pci_pm_restore_noirq(struct device *dev)
if (pci_has_legacy_pm_support(pci_dev)) if (pci_has_legacy_pm_support(pci_dev))
return pci_legacy_resume_early(dev); return pci_legacy_resume_early(dev);
if (drv && drv->pm && drv->pm->restore_noirq) if (pm && pm->restore_noirq)
error = drv->pm->restore_noirq(dev); return pm->restore_noirq(dev);
return error; return 0;
} }
static int pci_pm_restore(struct device *dev) static int pci_pm_restore(struct device *dev)
{ {
struct pci_dev *pci_dev = to_pci_dev(dev); struct pci_dev *pci_dev = to_pci_dev(dev);
const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL; const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL;
int error = 0;
/* /*
* This is necessary for the hibernation error path in which restore is * This is necessary for the hibernation error path in which restore is
...@@ -1248,12 +1245,12 @@ static int pci_pm_restore(struct device *dev) ...@@ -1248,12 +1245,12 @@ static int pci_pm_restore(struct device *dev)
if (pm) { if (pm) {
if (pm->restore) if (pm->restore)
error = pm->restore(dev); return pm->restore(dev);
} else { } else {
pci_pm_reenable_device(pci_dev); pci_pm_reenable_device(pci_dev);
} }
return error; return 0;
} }
#else /* !CONFIG_HIBERNATE_CALLBACKS */ #else /* !CONFIG_HIBERNATE_CALLBACKS */
...@@ -1329,9 +1326,9 @@ static int pci_pm_runtime_suspend(struct device *dev) ...@@ -1329,9 +1326,9 @@ static int pci_pm_runtime_suspend(struct device *dev)
static int pci_pm_runtime_resume(struct device *dev) static int pci_pm_runtime_resume(struct device *dev)
{ {
int rc = 0;
struct pci_dev *pci_dev = to_pci_dev(dev); struct pci_dev *pci_dev = to_pci_dev(dev);
const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL; const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL;
int error = 0;
/* /*
* Restoring config space is necessary even if the device is not bound * Restoring config space is necessary even if the device is not bound
...@@ -1347,18 +1344,17 @@ static int pci_pm_runtime_resume(struct device *dev) ...@@ -1347,18 +1344,17 @@ static int pci_pm_runtime_resume(struct device *dev)
pci_pm_default_resume(pci_dev); pci_pm_default_resume(pci_dev);
if (pm && pm->runtime_resume) if (pm && pm->runtime_resume)
rc = pm->runtime_resume(dev); error = pm->runtime_resume(dev);
pci_dev->runtime_d3cold = false; pci_dev->runtime_d3cold = false;
return rc; return error;
} }
static int pci_pm_runtime_idle(struct device *dev) static int pci_pm_runtime_idle(struct device *dev)
{ {
struct pci_dev *pci_dev = to_pci_dev(dev); struct pci_dev *pci_dev = to_pci_dev(dev);
const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL; const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL;
int ret = 0;
/* /*
* If pci_dev->driver is not set (unbound), the device should * If pci_dev->driver is not set (unbound), the device should
...@@ -1371,9 +1367,9 @@ static int pci_pm_runtime_idle(struct device *dev) ...@@ -1371,9 +1367,9 @@ static int pci_pm_runtime_idle(struct device *dev)
return -ENOSYS; return -ENOSYS;
if (pm->runtime_idle) if (pm->runtime_idle)
ret = pm->runtime_idle(dev); return pm->runtime_idle(dev);
return ret; return 0;
} }
static const struct dev_pm_ops pci_dev_pm_ops = { static const struct dev_pm_ops pci_dev_pm_ops = {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment