lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20111230005849.11559.78948.stgit@notabene.brown>
Date:	Fri, 30 Dec 2011 11:58:49 +1100
From:	NeilBrown <neilb@...e.de>
To:	linux-omap@...r.kernel.org, linux-kernel@...r.kernel.org
Subject: [PATCH 5/5] bq27x00 - don't report power-supply change so often.

A power_supply_changed should only be reported on significant changes
such as transition between charging and not.  Incremental changes
such as charge increasing should not be reported - that can easily
be polled for.

Signed-off-by: NeilBrown <neilb@...e.de>
---

 drivers/power/bq27x00_battery.c |   15 ++++++++++++---
 1 files changed, 12 insertions(+), 3 deletions(-)

diff --git a/drivers/power/bq27x00_battery.c b/drivers/power/bq27x00_battery.c
index bb16f5b..7993a17 100644
--- a/drivers/power/bq27x00_battery.c
+++ b/drivers/power/bq27x00_battery.c
@@ -57,11 +57,15 @@
 #define BQ27000_FLAG_CHGS		BIT(7)
 #define BQ27000_FLAG_FC			BIT(5)
 
+#define BQ27000_FLAGS_IMPORTANT		(BQ27000_FLAG_FC|BQ27000_FLAG_CHGS|BIT(31))
+
 #define BQ27500_REG_SOC			0x2C
 #define BQ27500_REG_DCAP		0x3C /* Design capacity */
 #define BQ27500_FLAG_DSC		BIT(0)
 #define BQ27500_FLAG_FC			BIT(9)
 
+#define BQ27500_FLAGS_IMPORTANT		(BQ27500_FLAG_FC|BQ27500_FLAG_DSC|BIT(31))
+
 #define BQ27000_RS			20 /* Resistor sense */
 
 struct bq27x00_device_info;
@@ -259,6 +263,7 @@ static void bq27x00_update(struct bq27x00_device_info *di)
 {
 	struct bq27x00_reg_cache cache = {0, };
 	bool is_bq27500 = di->chip == BQ27500;
+	int flags_changed;
 
 	cache.flags = bq27x00_read(di, BQ27x00_REG_FLAGS, is_bq27500);
 	if (cache.flags >= 0) {
@@ -280,10 +285,14 @@ static void bq27x00_update(struct bq27x00_device_info *di)
 
 	/* Ignore current_now which is a snapshot of the current battery state
 	 * and is likely to be different even between two consecutive reads */
-	if (memcmp(&di->cache, &cache, sizeof(cache) - sizeof(int)) != 0) {
-		di->cache = cache;
+	flags_changed = di->cache.flags ^ cache.flags;
+	di->cache = cache;
+	if (is_bq27500)
+		flags_changed &= BQ27500_FLAGS_IMPORTANT;
+	else
+		flags_changed &= BQ27000_FLAGS_IMPORTANT;
+	if (flags_changed)
 		power_supply_changed(&di->bat);
-	}
 
 	di->last_update = jiffies;
 }


--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ