twl4030_charger: Filter charge_current values under 1024
authorGrond <grond66@riseup.net>
Wed, 21 Dec 2016 05:18:35 +0000 (21:18 -0800)
committerGrazvydas Ignotas <notasas@gmail.com>
Wed, 21 Dec 2016 23:41:56 +0000 (01:41 +0200)
So that hypothetical users of this file don't proceed under the false assumption
that the format of charge_current hasn't changed. This is safe, since the
smallest value which can be given to the TWL4030's current regulator is
~1.666mA, and 1024uA is less than this.

drivers/power/twl4030_charger.c

index 4cd0fcd..8ff3f29 100644 (file)
@@ -706,6 +706,19 @@ static ssize_t store_charge_current(struct device *dev,
        if (ret)
                return -EINVAL;
 
+       /*
+        * Previously, this sysfs parameter used a different raw-register
+        * format. All legal values in this format fall numerically into the
+        * range [0, 1023]. Since in the new format, these encode values so
+        * low as to be meaningless, reject them here so that anybody trying
+        * to use the old format will have at least a chance of figuring out
+        * why it isn't working any more. Note that in both formats, the value
+        * 0 has the same meaning, so it is allowed where values in the range
+        * [1, 1023] are not.
+        */
+       if (new_current < 1024 && new_current != 0)
+               return -EINVAL;
+
        ret = update_charge_parameters(bci, new_current, -1);
        if (ret)
                return ret;