From: Dan Carpenter <dan.carpenter@oracle.com>
To: jonghwa3.lee@samsung.com
Cc: linux-pm@vger.kernel.org
Subject: re: max17042_battery: Support regmap to access device's registers
Date: Fri, 14 Aug 2015 12:55:13 +0300 [thread overview]
Message-ID: <20150814095513.GA14436@mwanda> (raw)
Hello Jonghwa Lee,
The patch 39e7213edc4f: "max17042_battery: Support regmap to access
device's registers" from Oct 25, 2013, leads to the following static
checker warning:
drivers/power/max17042_battery.c:501 max17042_init_model()
warn: passing casted pointer 'temp_data' to 'max17042_model_data_compare()' 32 vs 16.
drivers/power/max17042_battery.c
469 static inline int max17042_model_data_compare(struct max17042_chip *chip,
470 u16 *data1, u16 *data2, int size)
471 {
472 int i;
473
474 if (memcmp(data1, data2, size)) {
^^^^
data2 is size * sizeof(u32) bytes long so we are only checking the first
quarter of the buffer. data1 is in size of u16s so I wonder how this
memcmp() works at all?
475 dev_err(&chip->client->dev, "%s compare failed\n", __func__);
476 for (i = 0; i < size; i++)
^^^^
Here size is in terms of u16 elements. The original code mixed u16
units with byte units so it was buggy, but now we are using u32 units so
it's even worse.
477 dev_info(&chip->client->dev, "0x%x, 0x%x",
478 data1[i], data2[i]);
479 dev_info(&chip->client->dev, "\n");
480 return -EINVAL;
481 }
482 return 0;
483 }
484
485 static int max17042_init_model(struct max17042_chip *chip)
486 {
487 int ret;
488 int table_size = ARRAY_SIZE(chip->pdata->config_data->cell_char_tbl);
data1 is any array of u16s.
489 u32 *temp_data;
490
491 temp_data = kcalloc(table_size, sizeof(*temp_data), GFP_KERNEL);
Here "size" (table_size) is in units of u32 elements.
492 if (!temp_data)
493 return -ENOMEM;
494
495 max10742_unlock_model(chip);
496 max17042_write_model_data(chip, MAX17042_MODELChrTbl,
497 table_size);
498 max17042_read_model_data(chip, MAX17042_MODELChrTbl, temp_data,
499 table_size);
^^^^^^^^^^
Here "size" (table_size) is in units of u32 elements.
500
501 ret = max17042_model_data_compare(
502 chip,
503 chip->pdata->config_data->cell_char_tbl,
504 (u16 *)temp_data,
^^^^^^^^^^^^^^^^
This cast is ugly and causes a static checker warning.
505 table_size);
506
507 max10742_lock_model(chip);
508 kfree(temp_data);
509
510 return ret;
511 }
regards,
dan carpenter
next reply other threads:[~2015-08-14 9:55 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-08-14 9:55 Dan Carpenter [this message]
2015-08-17 5:26 ` max17042_battery: Support regmap to access device's registers Krzysztof Kozlowski
2015-08-17 14:08 ` Dan Carpenter
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=20150814095513.GA14436@mwanda \
--to=dan.carpenter@oracle.com \
--cc=jonghwa3.lee@samsung.com \
--cc=linux-pm@vger.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).