jz4740-battery: Correct voltage change check
authorMaarten ter Huurne <maarten@treewalker.org>
Sun, 28 Feb 2016 16:05:48 +0000 (17:05 +0100)
committerSebastian Reichel <sre@kernel.org>
Thu, 3 Mar 2016 14:05:08 +0000 (15:05 +0100)
The check is supposed to avoid redundant update notifications, so it
should check for the difference between old and new voltage exceeding
a threshold.

Also make sure the result of a failed read is never stored.

Signed-off-by: Maarten ter Huurne <maarten@treewalker.org>
Signed-off-by: Sebastian Reichel <sre@kernel.org>
drivers/power/jz4740-battery.c

index abdfc21..88f04f4 100644 (file)
@@ -208,7 +208,7 @@ static void jz_battery_update(struct jz_battery *jz_battery)
        }
 
        voltage = jz_battery_read_voltage(jz_battery);
-       if (abs(voltage - jz_battery->voltage) < 50000) {
+       if (voltage >= 0 && abs(voltage - jz_battery->voltage) > 50000) {
                jz_battery->voltage = voltage;
                has_changed = true;
        }