linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Sebastian Reichel <sre@kernel.org>
To: Dan Carpenter <dan.carpenter@oracle.com>
Cc: Stefan Popa <stefan.popa@analog.com>,
	linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org,
	kernel-janitors@vger.kernel.org
Subject: Re: [PATCH] power: supply: adp5061: Fix a couple off by ones
Date: Wed, 11 Jul 2018 12:04:18 +0200	[thread overview]
Message-ID: <20180711100418.p2t4mfvgyjbzrxwy@earth.universe> (raw)
In-Reply-To: <20180711075808.gpa3362vbins7crx@kili.mountain>

[-- Attachment #1: Type: text/plain, Size: 1379 bytes --]

Hi,

On Wed, Jul 11, 2018 at 10:58:13AM +0300, Dan Carpenter wrote:
> We end up reading one element beyond the end of the adp5061_vmax[] array
> here.
> 
> Fixes: fe8e81b7e899 ("adp5061: New driver for ADP5061 I2C battery charger")
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>

Thanks, queued.

-- Sebastian

> diff --git a/drivers/power/supply/adp5061.c b/drivers/power/supply/adp5061.c
> index c00a02ef7424..939fd3d8fb1a 100644
> --- a/drivers/power/supply/adp5061.c
> +++ b/drivers/power/supply/adp5061.c
> @@ -266,8 +266,8 @@ static int adp5061_get_max_voltage(struct adp5061_state *st,
>  		return ret;
>  
>  	regval = ((regval & ADP5061_TERM_SET_VTRM_MSK) >> 2) - 0x0F;
> -	if (regval > ARRAY_SIZE(adp5061_vmax))
> -		regval = ARRAY_SIZE(adp5061_vmax);
> +	if (regval >= ARRAY_SIZE(adp5061_vmax))
> +		regval = ARRAY_SIZE(adp5061_vmax) - 1;
>  
>  	val->intval = adp5061_vmax[regval] * 1000;
>  
> @@ -344,8 +344,8 @@ static int adp5061_get_const_chg_current(struct adp5061_state *st,
>  		return ret;
>  
>  	regval = ((regval & ADP5061_CHG_CURR_ICHG_MSK) >> 2);
> -	if (regval > ARRAY_SIZE(adp5061_const_ichg))
> -		regval = ARRAY_SIZE(adp5061_const_ichg);
> +	if (regval >= ARRAY_SIZE(adp5061_const_ichg))
> +		regval = ARRAY_SIZE(adp5061_const_ichg) - 1;
>  
>  	val->intval = adp5061_const_ichg[regval] * 1000;
>  

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

      reply	other threads:[~2018-07-11 10:04 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-07-11  7:58 [PATCH] power: supply: adp5061: Fix a couple off by ones Dan Carpenter
2018-07-11 10:04 ` Sebastian Reichel [this message]

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=20180711100418.p2t4mfvgyjbzrxwy@earth.universe \
    --to=sre@kernel.org \
    --cc=dan.carpenter@oracle.com \
    --cc=kernel-janitors@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=stefan.popa@analog.com \
    /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).