Skip to content

Commit 6da2f2c

Browse files
committed
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.org Signed-off-by: Bjorn Helgaas <bhelgaas@google.com> Reviewed-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
1 parent f7b32a8 commit 6da2f2c

1 file changed

Lines changed: 36 additions & 40 deletions

File tree

‎drivers/pci/pci-driver.c‎

Lines changed: 36 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -679,11 +679,11 @@ static bool pci_has_legacy_pm_support(struct pci_dev *pci_dev)
679679

680680
static int pci_pm_prepare(struct device *dev)
681681
{
682-
struct device_driver *drv = dev->driver;
683682
struct pci_dev *pci_dev = to_pci_dev(dev);
683+
const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL;
684684

685-
if (drv && drv->pm && drv->pm->prepare) {
686-
int error = drv->pm->prepare(dev);
685+
if (pm && pm->prepare) {
686+
int error = pm->prepare(dev);
687687
if (error < 0)
688688
return error;
689689

@@ -917,8 +917,7 @@ static int pci_pm_suspend_noirq(struct device *dev)
917917
static int pci_pm_resume_noirq(struct device *dev)
918918
{
919919
struct pci_dev *pci_dev = to_pci_dev(dev);
920-
struct device_driver *drv = dev->driver;
921-
int error = 0;
920+
const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL;
922921

923922
if (dev_pm_may_skip_resume(dev))
924923
return 0;
@@ -946,17 +945,16 @@ static int pci_pm_resume_noirq(struct device *dev)
946945
if (pci_has_legacy_pm_support(pci_dev))
947946
return pci_legacy_resume_early(dev);
948947

949-
if (drv && drv->pm && drv->pm->resume_noirq)
950-
error = drv->pm->resume_noirq(dev);
948+
if (pm && pm->resume_noirq)
949+
return pm->resume_noirq(dev);
951950

952-
return error;
951+
return 0;
953952
}
954953

955954
static int pci_pm_resume(struct device *dev)
956955
{
957956
struct pci_dev *pci_dev = to_pci_dev(dev);
958957
const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL;
959-
int error = 0;
960958

961959
/*
962960
* This is necessary for the suspend error path in which resume is
@@ -972,12 +970,12 @@ static int pci_pm_resume(struct device *dev)
972970

973971
if (pm) {
974972
if (pm->resume)
975-
error = pm->resume(dev);
973+
return pm->resume(dev);
976974
} else {
977975
pci_pm_reenable_device(pci_dev);
978976
}
979977

980-
return error;
978+
return 0;
981979
}
982980

983981
#else /* !CONFIG_SUSPEND */
@@ -1037,16 +1035,16 @@ static int pci_pm_freeze(struct device *dev)
10371035
static int pci_pm_freeze_noirq(struct device *dev)
10381036
{
10391037
struct pci_dev *pci_dev = to_pci_dev(dev);
1040-
struct device_driver *drv = dev->driver;
1038+
const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL;
10411039

10421040
if (pci_has_legacy_pm_support(pci_dev))
10431041
return pci_legacy_suspend_late(dev, PMSG_FREEZE);
10441042

1045-
if (drv && drv->pm && drv->pm->freeze_noirq) {
1043+
if (pm && pm->freeze_noirq) {
10461044
int error;
10471045

1048-
error = drv->pm->freeze_noirq(dev);
1049-
suspend_report_result(drv->pm->freeze_noirq, error);
1046+
error = pm->freeze_noirq(dev);
1047+
suspend_report_result(pm->freeze_noirq, error);
10501048
if (error)
10511049
return error;
10521050
}
@@ -1065,8 +1063,8 @@ static int pci_pm_freeze_noirq(struct device *dev)
10651063
static int pci_pm_thaw_noirq(struct device *dev)
10661064
{
10671065
struct pci_dev *pci_dev = to_pci_dev(dev);
1068-
struct device_driver *drv = dev->driver;
1069-
int error = 0;
1066+
const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL;
1067+
int error;
10701068

10711069
if (pcibios_pm_ops.thaw_noirq) {
10721070
error = pcibios_pm_ops.thaw_noirq(dev);
@@ -1090,10 +1088,10 @@ static int pci_pm_thaw_noirq(struct device *dev)
10901088
if (pci_has_legacy_pm_support(pci_dev))
10911089
return pci_legacy_resume_early(dev);
10921090

1093-
if (drv && drv->pm && drv->pm->thaw_noirq)
1094-
error = drv->pm->thaw_noirq(dev);
1091+
if (pm && pm->thaw_noirq)
1092+
return pm->thaw_noirq(dev);
10951093

1096-
return error;
1094+
return 0;
10971095
}
10981096

10991097
static int pci_pm_thaw(struct device *dev)
@@ -1164,24 +1162,24 @@ static int pci_pm_poweroff_late(struct device *dev)
11641162
static int pci_pm_poweroff_noirq(struct device *dev)
11651163
{
11661164
struct pci_dev *pci_dev = to_pci_dev(dev);
1167-
struct device_driver *drv = dev->driver;
1165+
const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL;
11681166

11691167
if (dev_pm_smart_suspend_and_suspended(dev))
11701168
return 0;
11711169

1172-
if (pci_has_legacy_pm_support(to_pci_dev(dev)))
1170+
if (pci_has_legacy_pm_support(pci_dev))
11731171
return pci_legacy_suspend_late(dev, PMSG_HIBERNATE);
11741172

1175-
if (!drv || !drv->pm) {
1173+
if (!pm) {
11761174
pci_fixup_device(pci_fixup_suspend_late, pci_dev);
11771175
return 0;
11781176
}
11791177

1180-
if (drv->pm->poweroff_noirq) {
1178+
if (pm->poweroff_noirq) {
11811179
int error;
11821180

1183-
error = drv->pm->poweroff_noirq(dev);
1184-
suspend_report_result(drv->pm->poweroff_noirq, error);
1181+
error = pm->poweroff_noirq(dev);
1182+
suspend_report_result(pm->poweroff_noirq, error);
11851183
if (error)
11861184
return error;
11871185
}
@@ -1207,8 +1205,8 @@ static int pci_pm_poweroff_noirq(struct device *dev)
12071205
static int pci_pm_restore_noirq(struct device *dev)
12081206
{
12091207
struct pci_dev *pci_dev = to_pci_dev(dev);
1210-
struct device_driver *drv = dev->driver;
1211-
int error = 0;
1208+
const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL;
1209+
int error;
12121210

12131211
if (pcibios_pm_ops.restore_noirq) {
12141212
error = pcibios_pm_ops.restore_noirq(dev);
@@ -1222,17 +1220,16 @@ static int pci_pm_restore_noirq(struct device *dev)
12221220
if (pci_has_legacy_pm_support(pci_dev))
12231221
return pci_legacy_resume_early(dev);
12241222

1225-
if (drv && drv->pm && drv->pm->restore_noirq)
1226-
error = drv->pm->restore_noirq(dev);
1223+
if (pm && pm->restore_noirq)
1224+
return pm->restore_noirq(dev);
12271225

1228-
return error;
1226+
return 0;
12291227
}
12301228

12311229
static int pci_pm_restore(struct device *dev)
12321230
{
12331231
struct pci_dev *pci_dev = to_pci_dev(dev);
12341232
const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL;
1235-
int error = 0;
12361233

12371234
/*
12381235
* This is necessary for the hibernation error path in which restore is
@@ -1248,12 +1245,12 @@ static int pci_pm_restore(struct device *dev)
12481245

12491246
if (pm) {
12501247
if (pm->restore)
1251-
error = pm->restore(dev);
1248+
return pm->restore(dev);
12521249
} else {
12531250
pci_pm_reenable_device(pci_dev);
12541251
}
12551252

1256-
return error;
1253+
return 0;
12571254
}
12581255

12591256
#else /* !CONFIG_HIBERNATE_CALLBACKS */
@@ -1329,9 +1326,9 @@ static int pci_pm_runtime_suspend(struct device *dev)
13291326

13301327
static int pci_pm_runtime_resume(struct device *dev)
13311328
{
1332-
int rc = 0;
13331329
struct pci_dev *pci_dev = to_pci_dev(dev);
13341330
const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL;
1331+
int error = 0;
13351332

13361333
/*
13371334
* 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)
13471344
pci_pm_default_resume(pci_dev);
13481345

13491346
if (pm && pm->runtime_resume)
1350-
rc = pm->runtime_resume(dev);
1347+
error = pm->runtime_resume(dev);
13511348

13521349
pci_dev->runtime_d3cold = false;
13531350

1354-
return rc;
1351+
return error;
13551352
}
13561353

13571354
static int pci_pm_runtime_idle(struct device *dev)
13581355
{
13591356
struct pci_dev *pci_dev = to_pci_dev(dev);
13601357
const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL;
1361-
int ret = 0;
13621358

13631359
/*
13641360
* If pci_dev->driver is not set (unbound), the device should
@@ -1371,9 +1367,9 @@ static int pci_pm_runtime_idle(struct device *dev)
13711367
return -ENOSYS;
13721368

13731369
if (pm->runtime_idle)
1374-
ret = pm->runtime_idle(dev);
1370+
return pm->runtime_idle(dev);
13751371

1376-
return ret;
1372+
return 0;
13771373
}
13781374

13791375
static const struct dev_pm_ops pci_dev_pm_ops = {

0 commit comments

Comments
 (0)