From: Liam Breck <liam@networkimprov.net>
To: "Sebastian Reichel" <sre@kernel.org>,
"Pali Rohár" <pali.rohar@gmail.com>,
linux-pm@vger.kernel.org
Cc: Paul Kocialkowski <contact@paulk.fr>,
Liam Breck <kernel@networkimprov.net>
Subject: [RFC v2 4/5] power: supply: bq27xxx: Flag identical chip data when in debug mode
Date: Sun, 6 Aug 2017 23:22:15 -0700 [thread overview]
Message-ID: <20170807062216.19988-5-liam@networkimprov.net> (raw)
In-Reply-To: <20170807062216.19988-1-liam@networkimprov.net>
From: Liam Breck <kernel@networkimprov.net>
The driver has 13 unique register maps, several of which are shared
by multiple chips. When adding support for a new chip, it's easy to
add a duplicate map by mistake.
In debug mode we now scan bq27xxx_chip_data[n].regs/props/dm_regs for
duplicates.
Signed-off-by: Liam Breck <kernel@networkimprov.net>
---
drivers/power/supply/bq27xxx_battery.c | 40 +++++++++++++++++++++++++++++++++-
1 file changed, 39 insertions(+), 1 deletion(-)
diff --git a/drivers/power/supply/bq27xxx_battery.c b/drivers/power/supply/bq27xxx_battery.c
index 8e535890..d85f9ec2 100644
--- a/drivers/power/supply/bq27xxx_battery.c
+++ b/drivers/power/supply/bq27xxx_battery.c
@@ -885,7 +885,7 @@ static struct bq27xxx_dm_reg bq27621_dm_regs[] = {
.props = ref##_props, \
.props_size = ARRAY_SIZE(ref##_props) }
-static struct {
+static struct bq27xxx_chip_datum {
u32 opts;
u32 unseal_key;
u8 *regs;
@@ -919,6 +919,40 @@ static struct {
[BQ27621] = BQ27XXX_DATA(bq27621, 0x80008000, BQ27XXX_O_UTOT | BQ27XXX_O_CFGUP | BQ27XXX_O_RAM),
};
+static void __maybe_unused bq27xxx_battery_dbg_dupes(struct bq27xxx_device_info *di)
+{
+ static bool once = false;
+ const size_t max = ARRAY_SIZE(bq27xxx_chip_data);
+ const char * const msg = "bq27xxx_chip_data[%d].%s & [%d].%s are identical\n";
+ struct bq27xxx_chip_datum *a, *b;
+ int i, j;
+
+ if (once)
+ return;
+ once = true;
+
+ for (i = 1; i < max-1; i++) {
+ a = bq27xxx_chip_data + i;
+
+ for (j = i+1; j < max; j++) {
+ b = bq27xxx_chip_data + j;
+
+ if (a->regs != b->regs &&
+ !memcmp(a->regs, b->regs, sizeof(bq27000_regs)))
+ dev_warn(di->dev, msg, i, "regs", j, "regs");
+
+ if (a->props != b->props &&
+ a->props_size == b->props_size &&
+ !memcmp(a->props, b->props, a->props_size))
+ dev_warn(di->dev, msg, i, "props", j, "props");
+
+ if (a->dm_regs != b->dm_regs &&
+ !memcmp(a->dm_regs, b->dm_regs, sizeof(bq27500_dm_regs)))
+ dev_warn(di->dev, msg, i, "dm_regs", j, "dm_regs");
+ }
+ }
+}
+
static DEFINE_MUTEX(bq27xxx_list_lock);
static LIST_HEAD(bq27xxx_battery_devices);
@@ -1976,6 +2010,10 @@ int bq27xxx_battery_setup(struct bq27xxx_device_info *di)
.drv_data = di,
};
+#ifdef DEBUG
+ bq27xxx_battery_dbg_dupes(di);
+#endif
+
INIT_DELAYED_WORK(&di->work, bq27xxx_battery_poll);
mutex_init(&di->lock);
--
2.13.2
next prev parent reply other threads:[~2017-08-07 6:23 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-08-07 6:22 [RFC v2 0/5] bq27xxx_battery data memory update Liam Breck
2017-08-07 6:22 ` [RFC v2 1/5] power: supply: bq27xxx: Create single chip data table Liam Breck
2017-08-09 16:08 ` Sebastian Reichel
2017-08-12 0:52 ` Liam Breck
2017-08-12 16:39 ` Sebastian Reichel
2017-08-07 6:22 ` [RFC v2 2/5] power: supply: bq27xxx: Add chip IDs for previously shadowed chips Liam Breck
2017-08-12 15:02 ` Sebastian Reichel
2017-08-12 17:56 ` Liam Breck
2017-08-12 18:45 ` Sebastian Reichel
2017-08-07 6:22 ` [RFC v2 3/5] power: supply: bq27xxx: Enable data memory update for certain chips Liam Breck
2017-08-12 16:04 ` Sebastian Reichel
2017-08-12 18:00 ` Liam Breck
2017-08-12 18:57 ` Sebastian Reichel
2017-08-07 6:22 ` Liam Breck [this message]
2017-08-12 16:25 ` [RFC v2 4/5] power: supply: bq27xxx: Flag identical chip data when in debug mode Sebastian Reichel
2017-08-12 18:35 ` Liam Breck
2017-08-12 18:40 ` Liam Breck
2017-08-07 6:22 ` [RFC v2 5/5] power: supply: bq27xxx: Remove duplicate chip data arrays Liam Breck
2017-08-12 16:22 ` 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=20170807062216.19988-5-liam@networkimprov.net \
--to=liam@networkimprov.net \
--cc=contact@paulk.fr \
--cc=kernel@networkimprov.net \
--cc=linux-pm@vger.kernel.org \
--cc=pali.rohar@gmail.com \
--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