mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Sascha Hauer <sha@pengutronix.de>
To: Ahmad Fatoum <a.fatoum@pengutronix.de>
Cc: barebox@lists.infradead.org, Johannes Zink <j.zink@pengutronix.de>
Subject: Re: [PATCH master 1/2] regulator: handle regulator_get_voltage(NULL) gracefully
Date: Mon, 8 Aug 2022 16:21:48 +0200	[thread overview]
Message-ID: <20220808142148.GV31528@pengutronix.de> (raw)
In-Reply-To: <20220718114824.2632364-1-a.fatoum@pengutronix.de>

On Mon, Jul 18, 2022 at 01:48:23PM +0200, Ahmad Fatoum wrote:
> Unlike recent versions of Linux, barebox represents the dummy regulator
> as a NULL pointer and regulator API is supposed to anticipate operation
> on a NULL pointer. When regulator_get_voltage was ported from Linux,
> this was not taken into consideration, which leads to
> regulator_get_voltage(NULL) crashing with a NULL pointer dereference.
> 
> Fix this by returning -EINVAL for dummy regulators. This aligns us with
> how Linux would behave in this situation.
> 
> Fixes: 6ee83ce08b24 ("regulator: add regulator_get_voltage() to API")
> Reported-by: Johannes Zink <j.zink@pengutronix.de>
> Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
> ---
>  drivers/regulator/core.c | 7 ++++++-
>  1 file changed, 6 insertions(+), 1 deletion(-)

Applied, thanks

Sascha

> 
> diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
> index 1fb344656f38..472b26f3a0ac 100644
> --- a/drivers/regulator/core.c
> +++ b/drivers/regulator/core.c
> @@ -574,9 +574,14 @@ EXPORT_SYMBOL_GPL(regulator_bulk_free);
>  
>  int regulator_get_voltage(struct regulator *regulator)
>  {
> -	struct regulator_dev *rdev = regulator->ri->rdev;
> +	struct regulator_dev *rdev;
>  	int sel, ret;
>  
> +	if (!regulator)
> +		return -EINVAL;
> +
> +	rdev = regulator->ri->rdev;
> +
>  	if (rdev->desc->ops->get_voltage_sel) {
>  		sel = rdev->desc->ops->get_voltage_sel(rdev);
>  		if (sel < 0)
> -- 
> 2.30.2
> 
> 
> 

-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |



      parent reply	other threads:[~2022-08-08 14:23 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-18 11:48 Ahmad Fatoum
2022-07-18 11:48 ` [PATCH master 2/2] common: don't fixup empty serial/machine_compatible strings Ahmad Fatoum
2022-08-08 14:21 ` Sascha Hauer [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=20220808142148.GV31528@pengutronix.de \
    --to=sha@pengutronix.de \
    --cc=a.fatoum@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    --cc=j.zink@pengutronix.de \
    --subject='Re: [PATCH master 1/2] regulator: handle regulator_get_voltage(NULL) gracefully' \
    /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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox