linux-pm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Maarten ter Huurne <maarten@treewalker.org>
To: Lars-Peter Clausen <lars@metafoo.de>
Cc: Sebastian Reichel <sre@kernel.org>,
	Dmitry Eremin-Solenikov <dbaryshkov@gmail.com>,
	David Woodhouse <dwmw2@infradead.org>,
	linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org,
	Maarten ter Huurne <maarten@treewalker.org>
Subject: [PATCH] jz4740-battery: Correct voltage change check
Date: Sun, 28 Feb 2016 17:05:48 +0100	[thread overview]
Message-ID: <1456675548-16692-1-git-send-email-maarten@treewalker.org> (raw)

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>
---
 drivers/power/jz4740-battery.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/power/jz4740-battery.c b/drivers/power/jz4740-battery.c
index abdfc21..88f04f4 100644
--- a/drivers/power/jz4740-battery.c
+++ b/drivers/power/jz4740-battery.c
@@ -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;
 	}
-- 
2.6.2

             reply	other threads:[~2016-02-28 16:05 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-02-28 16:05 Maarten ter Huurne [this message]
2016-03-03 14:21 ` [PATCH] jz4740-battery: Correct voltage change check Sebastian Reichel

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1456675548-16692-1-git-send-email-maarten@treewalker.org \
    --to=maarten@treewalker.org \
    --cc=dbaryshkov@gmail.com \
    --cc=dwmw2@infradead.org \
    --cc=lars@metafoo.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=sre@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).