power: supply: bq24190_charger: fix reference leak
authorZhang Qilong <zhangqilong3@huawei.com>
Mon, 2 Nov 2020 14:33:21 +0000 (22:33 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Tue, 29 Dec 2020 12:46:56 +0000 (13:46 +0100)
[ Upstream commit b2f6cb78eaa1cad57dd3fe11d0458cd4fae9a584 ]

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: f385e6e2a1532 ("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>
drivers/power/supply/bq24190_charger.c

index 35ff406aca483e93974aed9ae0514855269fa3eb..0906f6b562bc4c0be98f9ef63029c14202c526ff 100644 (file)
@@ -450,8 +450,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)
@@ -1086,8 +1088,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:
@@ -1158,8 +1162,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:
@@ -1424,8 +1430,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:
@@ -1470,8 +1478,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: