From: Minkyu Kang <mk7.kang@samsung.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH] fuelgauge: max17042: fix i2c read issue which causes infinity loop.
Date: Wed, 11 Dec 2013 11:27:54 +0900 [thread overview]
Message-ID: <52A7CDAA.2030305@samsung.com> (raw)
In-Reply-To: <1386688742-17901-1-git-send-email-p.marczak@samsung.com>
Dear Przemyslaw Marczak,
On 11/12/13 00:19, Przemyslaw Marczak wrote:
> Issues:
> - reading i2c data by passing u16 pointer causes errors in read data.
> - max17042 status register fields have not only Power On Reset meaning
> so using proper mask is required.
>
> Changes:
> - read i2c data to type u32 instead of u16 - avoids buffer overflow
> - compare FG status register using mask not just one bit value
>
> Signed-off-by: Przemyslaw Marczak <p.marczak@samsung.com>
> Cc: Lukasz Majewski <l.majewski@samsung.com>
> ---
> drivers/power/fuel_gauge/fg_max17042.c | 9 ++++++---
> 1 file changed, 6 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/power/fuel_gauge/fg_max17042.c b/drivers/power/fuel_gauge/fg_max17042.c
> index c285747..2cbf8cf 100644
> --- a/drivers/power/fuel_gauge/fg_max17042.c
> +++ b/drivers/power/fuel_gauge/fg_max17042.c
> @@ -28,11 +28,14 @@ static int fg_write_regs(struct pmic *p, u8 addr, u16 *data, int num)
>
> static int fg_read_regs(struct pmic *p, u8 addr, u16 *data, int num)
> {
> + unsigned int dat = 0;
initial value is unnecessary.
> int ret = 0;
> int i;
>
> - for (i = 0; i < num; i++, addr++)
> - ret |= pmic_reg_read(p, addr, (u32 *) (data + i));
> + for (i = 0; i < num; i++, addr++) {
> + ret |= pmic_reg_read(p, addr, &dat);
I think, need check return value.
if failed to read then you should not update data.
and such a case, do we need to read end of num?
why don't you return error directly?
I think this code should be..
ret = pmic_reg_read(p, addr, &dat);
if (ret)
return ret;
*(data + i) = (u16)dat;
> + *(data + i) = (u16) dat;
please remove space between ) and dat.
> + }
>
> return ret;
then it can be return 0; and initial value ( = 0) is unnecessary.
> }
> @@ -178,7 +181,7 @@ static int power_check_battery(struct pmic *p, struct pmic *bat)
> ret |= pmic_reg_read(p, MAX17042_STATUS, &val);
> debug("fg status: 0x%x\n", val);
>
> - if (val == MAX17042_POR)
> + if (val && MAX17042_POR)
if (val & MAX17042_POR) ?
> por_fuelgauge_init(p);
>
> ret |= pmic_reg_read(p, MAX17042_VERSION, &val);
>
Thanks,
Minkyu Kang.
next prev parent reply other threads:[~2013-12-11 2:27 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-12-10 15:19 [U-Boot] [PATCH] fuelgauge: max17042: fix i2c read issue which causes infinity loop Przemyslaw Marczak
2013-12-11 2:27 ` Minkyu Kang [this message]
2013-12-30 10:24 ` [U-Boot] [PATCH v2] " Przemyslaw Marczak
2013-12-30 10:31 ` Przemyslaw Marczak
2014-01-13 9:27 ` Przemyslaw Marczak
2014-01-14 0:24 ` Minkyu Kang
2014-01-14 7:48 ` Przemyslaw Marczak
2014-01-14 21:02 ` [U-Boot] [U-Boot, " Tom Rini
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=52A7CDAA.2030305@samsung.com \
--to=mk7.kang@samsung.com \
--cc=u-boot@lists.denx.de \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.