Skip to content

Commit

Permalink
power: supply: bq24190_charger: fix reference leak
Browse files Browse the repository at this point in the history
[ Upstream commit b2f6cb7 ]

pm_runtime_get_sync will increment pm usage counter even it
failed. Forgetting to call pm_runtime_put_noidle will result
in reference leak in callers(bq24190_sysfs_show,
bq24190_charger_get_property, bq24190_charger_set_property,
bq24190_battery_get_property, bq24190_battery_set_property),
so we should fix it.

Fixes: f385e6e ("power: bq24190_charger: Use PM runtime autosuspend")
Signed-off-by: Zhang Qilong <zhangqilong3@huawei.com>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
  • Loading branch information
Zhang Qilong authored and gregkh committed Dec 30, 2020
1 parent e230e19 commit 2f00dcc
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions drivers/power/supply/bq24190_charger.c
Expand Up @@ -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)
if (ret < 0) {
pm_runtime_put_noidle(bdi->dev);
return ret;
}

ret = bq24190_read_mask(bdi, info->reg, info->mask, info->shift, &v);
if (ret)
Expand Down Expand Up @@ -1075,8 +1077,10 @@ static int bq24190_charger_get_property(struct power_supply *psy,
dev_dbg(bdi->dev, "prop: %d\n", psp);

ret = pm_runtime_get_sync(bdi->dev);
if (ret < 0)
if (ret < 0) {
pm_runtime_put_noidle(bdi->dev);
return ret;
}

switch (psp) {
case POWER_SUPPLY_PROP_CHARGE_TYPE:
Expand Down Expand Up @@ -1147,8 +1151,10 @@ static int bq24190_charger_set_property(struct power_supply *psy,
dev_dbg(bdi->dev, "prop: %d\n", psp);

ret = pm_runtime_get_sync(bdi->dev);
if (ret < 0)
if (ret < 0) {
pm_runtime_put_noidle(bdi->dev);
return ret;
}

switch (psp) {
case POWER_SUPPLY_PROP_ONLINE:
Expand Down Expand Up @@ -1408,8 +1414,10 @@ static int bq24190_battery_get_property(struct power_supply *psy,
dev_dbg(bdi->dev, "prop: %d\n", psp);

ret = pm_runtime_get_sync(bdi->dev);
if (ret < 0)
if (ret < 0) {
pm_runtime_put_noidle(bdi->dev);
return ret;
}

switch (psp) {
case POWER_SUPPLY_PROP_STATUS:
Expand Down Expand Up @@ -1454,8 +1462,10 @@ static int bq24190_battery_set_property(struct power_supply *psy,
dev_dbg(bdi->dev, "prop: %d\n", psp);

ret = pm_runtime_get_sync(bdi->dev);
if (ret < 0)
if (ret < 0) {
pm_runtime_put_noidle(bdi->dev);
return ret;
}

switch (psp) {
case POWER_SUPPLY_PROP_ONLINE:
Expand Down

0 comments on commit 2f00dcc

Please sign in to comment.