From 236762b65aeacb9f90467c8818869effcaf9a4ac Mon Sep 17 00:00:00 2001 From: Grond Date: Tue, 20 Dec 2016 21:18:35 -0800 Subject: [PATCH] twl4030_charger: Filter charge_current values under 1024 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 | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/drivers/power/twl4030_charger.c b/drivers/power/twl4030_charger.c index 4cd0fcd7c377..8ff3f2908306 100644 --- a/drivers/power/twl4030_charger.c +++ b/drivers/power/twl4030_charger.c @@ -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; -- 2.39.2