UPSTREAM: power_supply: fix return value of get_property
[firefly-linux-kernel-4.4.55.git] / drivers / power / power_supply_core.c
index 456987c88baab9f4b8a0d2b7224b10d659b8bddc..a74d8ca383a1e8cb040ca08f78b7c77d15821375 100644 (file)
@@ -491,8 +491,11 @@ int power_supply_get_property(struct power_supply *psy,
                            enum power_supply_property psp,
                            union power_supply_propval *val)
 {
-       if (atomic_read(&psy->use_cnt) <= 0)
+       if (atomic_read(&psy->use_cnt) <= 0) {
+               if (!psy->initialized)
+                       return -EAGAIN;
                return -ENODEV;
+       }
 
        return psy->desc->get_property(psy, psp, val);
 }
@@ -565,11 +568,12 @@ static int power_supply_read_temp(struct thermal_zone_device *tzd,
 
        WARN_ON(tzd == NULL);
        psy = tzd->devdata;
-       ret = psy->desc->get_property(psy, POWER_SUPPLY_PROP_TEMP, &val);
+       ret = power_supply_get_property(psy, POWER_SUPPLY_PROP_TEMP, &val);
+       if (ret)
+               return ret;
 
        /* Convert tenths of degree Celsius to milli degree Celsius. */
-       if (!ret)
-               *temp = val.intval * 100;
+       *temp = val.intval * 100;
 
        return ret;
 }
@@ -612,10 +616,12 @@ static int ps_get_max_charge_cntl_limit(struct thermal_cooling_device *tcd,
        int ret;
 
        psy = tcd->devdata;
-       ret = psy->desc->get_property(psy,
-               POWER_SUPPLY_PROP_CHARGE_CONTROL_LIMIT_MAX, &val);
-       if (!ret)
-               *state = val.intval;
+       ret = power_supply_get_property(psy,
+                       POWER_SUPPLY_PROP_CHARGE_CONTROL_LIMIT_MAX, &val);
+       if (ret)
+               return ret;
+
+       *state = val.intval;
 
        return ret;
 }
@@ -628,10 +634,12 @@ static int ps_get_cur_chrage_cntl_limit(struct thermal_cooling_device *tcd,
        int ret;
 
        psy = tcd->devdata;
-       ret = psy->desc->get_property(psy,
-               POWER_SUPPLY_PROP_CHARGE_CONTROL_LIMIT, &val);
-       if (!ret)
-               *state = val.intval;
+       ret = power_supply_get_property(psy,
+                       POWER_SUPPLY_PROP_CHARGE_CONTROL_LIMIT, &val);
+       if (ret)
+               return ret;
+
+       *state = val.intval;
 
        return ret;
 }
@@ -780,6 +788,7 @@ __power_supply_register(struct device *parent,
         *    after calling power_supply_register()).
         */
        atomic_inc(&psy->use_cnt);
+       psy->initialized = true;
 
        queue_delayed_work(system_power_efficient_wq,
                           &psy->deferred_register_work,