linux-pm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] power: supply: bq24190_charger.c: call pm_runtime_put in pm_runtime_get_sync failed case
@ 2020-06-01  6:25 Navid
  0 siblings, 0 replies; 3+ messages in thread
From: Navid @ 2020-06-01  6:25 UTC (permalink / raw)
  To: Sebastian Reichel, linux-pm, linux-kernel
  Cc: emamd001, wu000273, kjlu, mccamant, Navid

Even in failed case of pm_runtime_get_sync, the usage_count
is incremented. In order to keep the usage_count with correct
value call pm_runtime_put_autosuspend.

Signed-off-by: Navid <navid.emamdoost@gmail.com>
---
 drivers/power/supply/bq24190_charger.c | 26 ++++++++++++++++++--------
 1 file changed, 18 insertions(+), 8 deletions(-)

diff --git a/drivers/power/supply/bq24190_charger.c b/drivers/power/supply/bq24190_charger.c
index 453d6332d43a..502ccdac2443 100644
--- a/drivers/power/supply/bq24190_charger.c
+++ b/drivers/power/supply/bq24190_charger.c
@@ -448,8 +448,10 @@ static ssize_t bq24190_sysfs_show(struct device *dev,
 		return -EINVAL;
 
 	ret = pm_runtime_get_sync(bdi->dev);
-	if (ret < 0)
-		return ret;
+	if (ret < 0) {
+		count = ret;
+		goto out;
+	}
 
 	ret = bq24190_read_mask(bdi, info->reg, info->mask, info->shift, &v);
 	if (ret)
@@ -458,6 +460,7 @@ static ssize_t bq24190_sysfs_show(struct device *dev,
 		count = scnprintf(buf, PAGE_SIZE, "%hhx\n", v);
 
 	pm_runtime_mark_last_busy(bdi->dev);
+out:
 	pm_runtime_put_autosuspend(bdi->dev);
 
 	return count;
@@ -481,14 +484,17 @@ static ssize_t bq24190_sysfs_store(struct device *dev,
 		return ret;
 
 	ret = pm_runtime_get_sync(bdi->dev);
-	if (ret < 0)
-		return ret;
+	if (ret < 0) {
+		count = ret;
+		goto out;
+	}
 
 	ret = bq24190_write_mask(bdi, info->reg, info->mask, info->shift, v);
 	if (ret)
 		count = ret;
 
 	pm_runtime_mark_last_busy(bdi->dev);
+out:
 	pm_runtime_put_autosuspend(bdi->dev);
 
 	return count;
@@ -1076,7 +1082,7 @@ static int bq24190_charger_get_property(struct power_supply *psy,
 
 	ret = pm_runtime_get_sync(bdi->dev);
 	if (ret < 0)
-		return ret;
+		goto out;
 
 	switch (psp) {
 	case POWER_SUPPLY_PROP_CHARGE_TYPE:
@@ -1132,6 +1138,7 @@ static int bq24190_charger_get_property(struct power_supply *psy,
 	}
 
 	pm_runtime_mark_last_busy(bdi->dev);
+out:
 	pm_runtime_put_autosuspend(bdi->dev);
 
 	return ret;
@@ -1148,7 +1155,7 @@ static int bq24190_charger_set_property(struct power_supply *psy,
 
 	ret = pm_runtime_get_sync(bdi->dev);
 	if (ret < 0)
-		return ret;
+		goto out;
 
 	switch (psp) {
 	case POWER_SUPPLY_PROP_ONLINE:
@@ -1174,6 +1181,7 @@ static int bq24190_charger_set_property(struct power_supply *psy,
 	}
 
 	pm_runtime_mark_last_busy(bdi->dev);
+out:
 	pm_runtime_put_autosuspend(bdi->dev);
 
 	return ret;
@@ -1409,7 +1417,7 @@ static int bq24190_battery_get_property(struct power_supply *psy,
 
 	ret = pm_runtime_get_sync(bdi->dev);
 	if (ret < 0)
-		return ret;
+		goto out;
 
 	switch (psp) {
 	case POWER_SUPPLY_PROP_STATUS:
@@ -1438,6 +1446,7 @@ static int bq24190_battery_get_property(struct power_supply *psy,
 	}
 
 	pm_runtime_mark_last_busy(bdi->dev);
+out:
 	pm_runtime_put_autosuspend(bdi->dev);
 
 	return ret;
@@ -1455,7 +1464,7 @@ static int bq24190_battery_set_property(struct power_supply *psy,
 
 	ret = pm_runtime_get_sync(bdi->dev);
 	if (ret < 0)
-		return ret;
+		goto out;
 
 	switch (psp) {
 	case POWER_SUPPLY_PROP_ONLINE:
@@ -1469,6 +1478,7 @@ static int bq24190_battery_set_property(struct power_supply *psy,
 	}
 
 	pm_runtime_mark_last_busy(bdi->dev);
+out:
 	pm_runtime_put_autosuspend(bdi->dev);
 
 	return ret;
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] power: supply: bq24190_charger.c: call pm_runtime_put in pm_runtime_get_sync failed case
@ 2020-06-01  8:01 Markus Elfring
  0 siblings, 0 replies; 3+ messages in thread
From: Markus Elfring @ 2020-06-01  8:01 UTC (permalink / raw)
  To: Navid Emamdoost, linux-pm
  Cc: Navid Emamdoost, linux-kernel, Kangjie Lu, Qiushi Wu,
	Stephen McCamant, Sebastian Reichel, Rafael J. Wysocki,
	Dinghao Liu

> Even in failed case of pm_runtime_get_sync, the usage_count
> is incremented. In order to keep the usage_count with correct
> value call pm_runtime_put_autosuspend.

* I find the word “usage_count” questionable in this change description.

* Will the tag “Fixes” become relevant for the commit message?

* Can an other label be more helpful than “out”?

* Would you like to take another look at a related update suggestion
  like “power: supply: bq24190_charger: Fix runtime PM imbalance on error”?
  https://lore.kernel.org/linux-pm/20200525110540.6949-1-dinghao.liu@zju.edu.cn/
  https://lore.kernel.org/patchwork/patch/1246783/

Regards,
Markus

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH] power: supply: bq24190_charger.c: call pm_runtime_put in pm_runtime_get_sync failed case
@ 2020-06-01  7:03 Navid Emamdoost
  0 siblings, 0 replies; 3+ messages in thread
From: Navid Emamdoost @ 2020-06-01  7:03 UTC (permalink / raw)
  To: Sebastian Reichel, linux-pm, linux-kernel
  Cc: emamd001, wu000273, kjlu, mccamant, Navid

From: Navid <navid.emamdoost@gmail.com>

Even in failed case of pm_runtime_get_sync, the usage_count
is incremented. In order to keep the usage_count with correct
value call pm_runtime_put_autosuspend.

Signed-off-by: Navid <navid.emamdoost@gmail.com>
---
 drivers/power/supply/bq24190_charger.c | 26 ++++++++++++++++++--------
 1 file changed, 18 insertions(+), 8 deletions(-)

diff --git a/drivers/power/supply/bq24190_charger.c b/drivers/power/supply/bq24190_charger.c
index 453d6332d43a..502ccdac2443 100644
--- a/drivers/power/supply/bq24190_charger.c
+++ b/drivers/power/supply/bq24190_charger.c
@@ -448,8 +448,10 @@ static ssize_t bq24190_sysfs_show(struct device *dev,
 		return -EINVAL;
 
 	ret = pm_runtime_get_sync(bdi->dev);
-	if (ret < 0)
-		return ret;
+	if (ret < 0) {
+		count = ret;
+		goto out;
+	}
 
 	ret = bq24190_read_mask(bdi, info->reg, info->mask, info->shift, &v);
 	if (ret)
@@ -458,6 +460,7 @@ static ssize_t bq24190_sysfs_show(struct device *dev,
 		count = scnprintf(buf, PAGE_SIZE, "%hhx\n", v);
 
 	pm_runtime_mark_last_busy(bdi->dev);
+out:
 	pm_runtime_put_autosuspend(bdi->dev);
 
 	return count;
@@ -481,14 +484,17 @@ static ssize_t bq24190_sysfs_store(struct device *dev,
 		return ret;
 
 	ret = pm_runtime_get_sync(bdi->dev);
-	if (ret < 0)
-		return ret;
+	if (ret < 0) {
+		count = ret;
+		goto out;
+	}
 
 	ret = bq24190_write_mask(bdi, info->reg, info->mask, info->shift, v);
 	if (ret)
 		count = ret;
 
 	pm_runtime_mark_last_busy(bdi->dev);
+out:
 	pm_runtime_put_autosuspend(bdi->dev);
 
 	return count;
@@ -1076,7 +1082,7 @@ static int bq24190_charger_get_property(struct power_supply *psy,
 
 	ret = pm_runtime_get_sync(bdi->dev);
 	if (ret < 0)
-		return ret;
+		goto out;
 
 	switch (psp) {
 	case POWER_SUPPLY_PROP_CHARGE_TYPE:
@@ -1132,6 +1138,7 @@ static int bq24190_charger_get_property(struct power_supply *psy,
 	}
 
 	pm_runtime_mark_last_busy(bdi->dev);
+out:
 	pm_runtime_put_autosuspend(bdi->dev);
 
 	return ret;
@@ -1148,7 +1155,7 @@ static int bq24190_charger_set_property(struct power_supply *psy,
 
 	ret = pm_runtime_get_sync(bdi->dev);
 	if (ret < 0)
-		return ret;
+		goto out;
 
 	switch (psp) {
 	case POWER_SUPPLY_PROP_ONLINE:
@@ -1174,6 +1181,7 @@ static int bq24190_charger_set_property(struct power_supply *psy,
 	}
 
 	pm_runtime_mark_last_busy(bdi->dev);
+out:
 	pm_runtime_put_autosuspend(bdi->dev);
 
 	return ret;
@@ -1409,7 +1417,7 @@ static int bq24190_battery_get_property(struct power_supply *psy,
 
 	ret = pm_runtime_get_sync(bdi->dev);
 	if (ret < 0)
-		return ret;
+		goto out;
 
 	switch (psp) {
 	case POWER_SUPPLY_PROP_STATUS:
@@ -1438,6 +1446,7 @@ static int bq24190_battery_get_property(struct power_supply *psy,
 	}
 
 	pm_runtime_mark_last_busy(bdi->dev);
+out:
 	pm_runtime_put_autosuspend(bdi->dev);
 
 	return ret;
@@ -1455,7 +1464,7 @@ static int bq24190_battery_set_property(struct power_supply *psy,
 
 	ret = pm_runtime_get_sync(bdi->dev);
 	if (ret < 0)
-		return ret;
+		goto out;
 
 	switch (psp) {
 	case POWER_SUPPLY_PROP_ONLINE:
@@ -1469,6 +1478,7 @@ static int bq24190_battery_set_property(struct power_supply *psy,
 	}
 
 	pm_runtime_mark_last_busy(bdi->dev);
+out:
 	pm_runtime_put_autosuspend(bdi->dev);
 
 	return ret;
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2020-06-01  8:03 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-06-01  6:25 [PATCH] power: supply: bq24190_charger.c: call pm_runtime_put in pm_runtime_get_sync failed case Navid
2020-06-01  7:03 Navid Emamdoost
2020-06-01  8:01 Markus Elfring

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).