Skip to content

Commit 5b550c9

Browse files
committed
Merge branch 'pm-domains'
* pm-domains: PM / domains: Improve wording of dev_pm_domain_attach() comment PM / Domains: Don't return -EEXIST at attach when PM domain exists spi: Respect all error codes from dev_pm_domain_attach() soundwire: Respect all error codes from dev_pm_domain_attach() mmc: sdio: Respect all error codes from dev_pm_domain_attach() i2c: Respect all error codes from dev_pm_domain_attach() driver core: Respect all error codes from dev_pm_domain_attach() amba: Respect all error codes from dev_pm_domain_attach() PM / Domains: Allow a better error handling of dev_pm_domain_attach() PM / Domains: Check for existing PM domain in dev_pm_domain_attach() PM / Domains: Drop redundant code in genpd while attaching devices PM / Domains: Drop comment in genpd about legacy Samsung DT binding PM / Domains: Fix error path during attach in genpd
2 parents f1c7d00 + 49072f9 commit 5b550c9

File tree

11 files changed

+53
-68
lines changed

11 files changed

+53
-68
lines changed

drivers/acpi/device_pm.c

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1257,18 +1257,15 @@ int acpi_dev_pm_attach(struct device *dev, bool power_on)
12571257
struct acpi_device *adev = ACPI_COMPANION(dev);
12581258

12591259
if (!adev)
1260-
return -ENODEV;
1261-
1262-
if (dev->pm_domain)
1263-
return -EEXIST;
1260+
return 0;
12641261

12651262
/*
12661263
* Only attach the power domain to the first device if the
12671264
* companion is shared by multiple. This is to prevent doing power
12681265
* management twice.
12691266
*/
12701267
if (!acpi_device_is_first_physical_node(adev, dev))
1271-
return -EBUSY;
1268+
return 0;
12721269

12731270
acpi_add_pm_notifier(adev, dev, acpi_pm_notify_work_func);
12741271
dev_pm_domain_set(dev, &acpi_general_pm_domain);
@@ -1278,7 +1275,7 @@ int acpi_dev_pm_attach(struct device *dev, bool power_on)
12781275
}
12791276

12801277
dev->pm_domain->detach = acpi_dev_pm_detach;
1281-
return 0;
1278+
return 1;
12821279
}
12831280
EXPORT_SYMBOL_GPL(acpi_dev_pm_attach);
12841281
#endif /* CONFIG_PM */

drivers/amba/bus.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ static int amba_probe(struct device *dev)
248248
break;
249249

250250
ret = dev_pm_domain_attach(dev, true);
251-
if (ret == -EPROBE_DEFER)
251+
if (ret)
252252
break;
253253

254254
ret = amba_get_enable_pclk(pcdev);
@@ -375,7 +375,7 @@ static int amba_device_try_add(struct amba_device *dev, struct resource *parent)
375375
}
376376

377377
ret = dev_pm_domain_attach(&dev->dev, true);
378-
if (ret == -EPROBE_DEFER) {
378+
if (ret) {
379379
iounmap(tmp);
380380
goto err_release;
381381
}

drivers/base/platform.c

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -572,17 +572,16 @@ static int platform_drv_probe(struct device *_dev)
572572
return ret;
573573

574574
ret = dev_pm_domain_attach(_dev, true);
575-
if (ret != -EPROBE_DEFER) {
576-
if (drv->probe) {
577-
ret = drv->probe(dev);
578-
if (ret)
579-
dev_pm_domain_detach(_dev, true);
580-
} else {
581-
/* don't fail if just dev_pm_domain_attach failed */
582-
ret = 0;
583-
}
575+
if (ret)
576+
goto out;
577+
578+
if (drv->probe) {
579+
ret = drv->probe(dev);
580+
if (ret)
581+
dev_pm_domain_detach(_dev, true);
584582
}
585583

584+
out:
586585
if (drv->prevent_deferred_probe && ret == -EPROBE_DEFER) {
587586
dev_warn(_dev, "probe deferral not supported\n");
588587
ret = -ENXIO;

drivers/base/power/common.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,17 +98,21 @@ EXPORT_SYMBOL_GPL(dev_pm_put_subsys_data);
9898
* Callers must ensure proper synchronization of this function with power
9999
* management callbacks.
100100
*
101-
* Returns 0 on successfully attached PM domain or negative error code.
101+
* Returns 0 on successfully attached PM domain, or when it is found that the
102+
* device doesn't need a PM domain, else a negative error code.
102103
*/
103104
int dev_pm_domain_attach(struct device *dev, bool power_on)
104105
{
105106
int ret;
106107

108+
if (dev->pm_domain)
109+
return 0;
110+
107111
ret = acpi_dev_pm_attach(dev, power_on);
108-
if (ret)
112+
if (!ret)
109113
ret = genpd_dev_pm_attach(dev);
110114

111-
return ret;
115+
return ret < 0 ? ret : 0;
112116
}
113117
EXPORT_SYMBOL_GPL(dev_pm_domain_attach);
114118

drivers/base/power/domain.c

Lines changed: 15 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1377,7 +1377,7 @@ static int genpd_add_device(struct generic_pm_domain *genpd, struct device *dev,
13771377
struct gpd_timing_data *td)
13781378
{
13791379
struct generic_pm_domain_data *gpd_data;
1380-
int ret = 0;
1380+
int ret;
13811381

13821382
dev_dbg(dev, "%s()\n", __func__);
13831383

@@ -1390,11 +1390,6 @@ static int genpd_add_device(struct generic_pm_domain *genpd, struct device *dev,
13901390

13911391
genpd_lock(genpd);
13921392

1393-
if (genpd->prepared_count > 0) {
1394-
ret = -EAGAIN;
1395-
goto out;
1396-
}
1397-
13981393
ret = genpd->attach_dev ? genpd->attach_dev(genpd, dev) : 0;
13991394
if (ret)
14001395
goto out;
@@ -2185,31 +2180,25 @@ static void genpd_dev_pm_sync(struct device *dev)
21852180
* Parse device's OF node to find a PM domain specifier. If such is found,
21862181
* attaches the device to retrieved pm_domain ops.
21872182
*
2188-
* Both generic and legacy Samsung-specific DT bindings are supported to keep
2189-
* backwards compatibility with existing DTBs.
2190-
*
2191-
* Returns 0 on successfully attached PM domain or negative error code. Note
2192-
* that if a power-domain exists for the device, but it cannot be found or
2193-
* turned on, then return -EPROBE_DEFER to ensure that the device is not
2194-
* probed and to re-try again later.
2183+
* Returns 1 on successfully attached PM domain, 0 when the device don't need a
2184+
* PM domain or a negative error code in case of failures. Note that if a
2185+
* power-domain exists for the device, but it cannot be found or turned on,
2186+
* then return -EPROBE_DEFER to ensure that the device is not probed and to
2187+
* re-try again later.
21952188
*/
21962189
int genpd_dev_pm_attach(struct device *dev)
21972190
{
21982191
struct of_phandle_args pd_args;
21992192
struct generic_pm_domain *pd;
2200-
unsigned int i;
22012193
int ret;
22022194

22032195
if (!dev->of_node)
2204-
return -ENODEV;
2205-
2206-
if (dev->pm_domain)
2207-
return -EEXIST;
2196+
return 0;
22082197

22092198
ret = of_parse_phandle_with_args(dev->of_node, "power-domains",
22102199
"#power-domain-cells", 0, &pd_args);
22112200
if (ret < 0)
2212-
return ret;
2201+
return 0;
22132202

22142203
mutex_lock(&gpd_list_lock);
22152204
pd = genpd_get_from_provider(&pd_args);
@@ -2223,21 +2212,14 @@ int genpd_dev_pm_attach(struct device *dev)
22232212

22242213
dev_dbg(dev, "adding to PM domain %s\n", pd->name);
22252214

2226-
for (i = 1; i < GENPD_RETRY_MAX_MS; i <<= 1) {
2227-
ret = genpd_add_device(pd, dev, NULL);
2228-
if (ret != -EAGAIN)
2229-
break;
2230-
2231-
mdelay(i);
2232-
cond_resched();
2233-
}
2215+
ret = genpd_add_device(pd, dev, NULL);
22342216
mutex_unlock(&gpd_list_lock);
22352217

22362218
if (ret < 0) {
22372219
if (ret != -EPROBE_DEFER)
22382220
dev_err(dev, "failed to add to PM domain %s: %d",
22392221
pd->name, ret);
2240-
goto out;
2222+
return ret;
22412223
}
22422224

22432225
dev->pm_domain->detach = genpd_dev_pm_detach;
@@ -2246,8 +2228,11 @@ int genpd_dev_pm_attach(struct device *dev)
22462228
genpd_lock(pd);
22472229
ret = genpd_power_on(pd, 0);
22482230
genpd_unlock(pd);
2249-
out:
2250-
return ret ? -EPROBE_DEFER : 0;
2231+
2232+
if (ret)
2233+
genpd_remove_device(pd, dev);
2234+
2235+
return ret ? -EPROBE_DEFER : 1;
22512236
}
22522237
EXPORT_SYMBOL_GPL(genpd_dev_pm_attach);
22532238

drivers/i2c/i2c-core-base.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,7 @@ static int i2c_device_probe(struct device *dev)
363363
goto err_clear_wakeup_irq;
364364

365365
status = dev_pm_domain_attach(&client->dev, true);
366-
if (status == -EPROBE_DEFER)
366+
if (status)
367367
goto err_clear_wakeup_irq;
368368

369369
/*

drivers/mmc/core/sdio_bus.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ static int sdio_bus_probe(struct device *dev)
139139
return -ENODEV;
140140

141141
ret = dev_pm_domain_attach(dev, false);
142-
if (ret == -EPROBE_DEFER)
142+
if (ret)
143143
return ret;
144144

145145
/* Unbound SDIO functions are always suspended.

drivers/soundwire/bus_type.c

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -83,17 +83,16 @@ static int sdw_drv_probe(struct device *dev)
8383
* attach to power domain but don't turn on (last arg)
8484
*/
8585
ret = dev_pm_domain_attach(dev, false);
86-
if (ret != -EPROBE_DEFER) {
87-
ret = drv->probe(slave, id);
88-
if (ret) {
89-
dev_err(dev, "Probe of %s failed: %d\n", drv->name, ret);
90-
dev_pm_domain_detach(dev, false);
91-
}
92-
}
93-
9486
if (ret)
9587
return ret;
9688

89+
ret = drv->probe(slave, id);
90+
if (ret) {
91+
dev_err(dev, "Probe of %s failed: %d\n", drv->name, ret);
92+
dev_pm_domain_detach(dev, false);
93+
return ret;
94+
}
95+
9796
/* device is probed so let's read the properties now */
9897
if (slave->ops && slave->ops->read_prop)
9998
slave->ops->read_prop(slave);

drivers/spi/spi.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -356,11 +356,12 @@ static int spi_drv_probe(struct device *dev)
356356
}
357357

358358
ret = dev_pm_domain_attach(dev, true);
359-
if (ret != -EPROBE_DEFER) {
360-
ret = sdrv->probe(spi);
361-
if (ret)
362-
dev_pm_domain_detach(dev, true);
363-
}
359+
if (ret)
360+
return ret;
361+
362+
ret = sdrv->probe(spi);
363+
if (ret)
364+
dev_pm_domain_detach(dev, true);
364365

365366
return ret;
366367
}

include/linux/acpi.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -899,7 +899,7 @@ static inline int acpi_subsys_runtime_suspend(struct device *dev) { return 0; }
899899
static inline int acpi_subsys_runtime_resume(struct device *dev) { return 0; }
900900
static inline int acpi_dev_pm_attach(struct device *dev, bool power_on)
901901
{
902-
return -ENODEV;
902+
return 0;
903903
}
904904
#endif
905905

include/linux/pm_domain.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ static inline int of_genpd_parse_idle_states(struct device_node *dn,
280280

281281
static inline int genpd_dev_pm_attach(struct device *dev)
282282
{
283-
return -ENODEV;
283+
return 0;
284284
}
285285

286286
static inline
@@ -297,7 +297,7 @@ extern void dev_pm_domain_set(struct device *dev, struct dev_pm_domain *pd);
297297
#else
298298
static inline int dev_pm_domain_attach(struct device *dev, bool power_on)
299299
{
300-
return -ENODEV;
300+
return 0;
301301
}
302302
static inline void dev_pm_domain_detach(struct device *dev, bool power_off) {}
303303
static inline void dev_pm_domain_set(struct device *dev,

0 commit comments

Comments
 (0)