public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Matthias Kaehlcke <mka@chromium.org>
To: Axel Lin <axel.lin@ingics.com>
Cc: Mark Brown <broonie@kernel.org>, Rob Herring <robh@kernel.org>,
	Liam Girdwood <lgirdwood@gmail.com>,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] regulator: vctrl: Fix out of bounds array access for vctrl->vtable
Date: Fri, 14 Apr 2017 10:11:37 -0700	[thread overview]
Message-ID: <20170414171137.GK28657@google.com> (raw)
In-Reply-To: <20170414025043.13680-1-axel.lin@ingics.com>

Hi Axel,

El Fri, Apr 14, 2017 at 10:50:43AM +0800 Axel Lin ha dit:

> Current code only allocates rdesc->n_voltages entries for vctrl->vtable.
> Thus use rdesc->n_voltages instead of n_voltages in the for loop.

This is intended. n_voltages is the number of voltages of the control
regulator. In the first loop of the function we determine how many of
these voltages are usable by the vctrl regulator (=> rdesc->n_voltages).
The loop that populates vctrl->vtable iterates over n_voltages,
however it skips those that are outside of the voltage range for the
control regulator.

> While at it, also switch to use devm_kcalloc instead of devm_kmalloc_array
> + __GFP_ZERO flag and fix the argument order.

This looks good to me.

Thanks

Matthias

> Signed-off-by: Axel Lin <axel.lin@ingics.com>
> ---
>  drivers/regulator/vctrl-regulator.c | 8 ++++----
>  1 file changed, 4 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/regulator/vctrl-regulator.c b/drivers/regulator/vctrl-regulator.c
> index 6baadef..78de002 100644
> --- a/drivers/regulator/vctrl-regulator.c
> +++ b/drivers/regulator/vctrl-regulator.c
> @@ -345,9 +345,9 @@ static int vctrl_init_vtable(struct platform_device *pdev)
>  		return -EINVAL;
>  	}
>  
> -	vctrl->vtable = devm_kmalloc_array(
> -		&pdev->dev, sizeof(struct vctrl_voltage_table),
> -		rdesc->n_voltages, GFP_KERNEL | __GFP_ZERO);
> +	vctrl->vtable = devm_kcalloc(&pdev->dev, rdesc->n_voltages,
> +				     sizeof(struct vctrl_voltage_table),
> +				     GFP_KERNEL);
>  	if (!vctrl->vtable)
>  		return -ENOMEM;
>  
> @@ -371,7 +371,7 @@ static int vctrl_init_vtable(struct platform_device *pdev)
>  	     NULL);
>  
>  	/* pre-calculate OVP-safe downward transitions */
> -	for (i = n_voltages - 1; i > 0; i--) {
> +	for (i = rdesc->n_voltages - 1; i > 0; i--) {
>  		int j;
>  		int ovp_min_uV = (vctrl->vtable[i].out *
>  				  (100 - vctrl->ovp_threshold)) / 100;

  reply	other threads:[~2017-04-14 17:11 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-04-14  2:50 [PATCH] regulator: vctrl: Fix out of bounds array access for vctrl->vtable Axel Lin
2017-04-14 17:11 ` Matthias Kaehlcke [this message]
2017-04-14 19:01   ` Matthias Kaehlcke
2017-04-14 17:12 ` Applied "regulator: vctrl: Fix out of bounds array access for vctrl->vtable" to the regulator tree Mark Brown

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=20170414171137.GK28657@google.com \
    --to=mka@chromium.org \
    --cc=axel.lin@ingics.com \
    --cc=broonie@kernel.org \
    --cc=lgirdwood@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=robh@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