mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Guenter Roeck <linux@roeck-us.net>
To: Axel Lin <axel.lin@ingics.com>
Cc: Mark Brown <broonie@kernel.org>,
	Philippe Schenker <philippe.schenker@toradex.com>,
	Liam Girdwood <lgirdwood@gmail.com>,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] regulator: fixed: Prevent NULL pointer dereference when !CONFIG_OF
Date: Mon, 7 Oct 2019 07:24:18 -0700	[thread overview]
Message-ID: <20191007142418.GA1732@roeck-us.net> (raw)
In-Reply-To: <20190922022928.28355-1-axel.lin@ingics.com>

On Sun, Sep 22, 2019 at 10:29:28AM +0800, Axel Lin wrote:
> Use of_device_get_match_data which has NULL test for match before
> dereference match->data. Add NULL test for drvtype so it still works
> for fixed_voltage_ops when !CONFIG_OF.
> 
> Signed-off-by: Axel Lin <axel.lin@ingics.com>
> Reviewed-by: Philippe Schenker <philippe.schenker@toradex.com>

Tested-by: Guenter Roeck <linux@roeck-us.net>

> ---
>  drivers/regulator/fixed.c | 5 ++---
>  1 file changed, 2 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/regulator/fixed.c b/drivers/regulator/fixed.c
> index d90a6fd8cbc7..f81533070058 100644
> --- a/drivers/regulator/fixed.c
> +++ b/drivers/regulator/fixed.c
> @@ -144,8 +144,7 @@ static int reg_fixed_voltage_probe(struct platform_device *pdev)
>  	struct device *dev = &pdev->dev;
>  	struct fixed_voltage_config *config;
>  	struct fixed_voltage_data *drvdata;
> -	const struct fixed_dev_type *drvtype =
> -		of_match_device(dev->driver->of_match_table, dev)->data;
> +	const struct fixed_dev_type *drvtype = of_device_get_match_data(dev);
>  	struct regulator_config cfg = { };
>  	enum gpiod_flags gflags;
>  	int ret;
> @@ -177,7 +176,7 @@ static int reg_fixed_voltage_probe(struct platform_device *pdev)
>  	drvdata->desc.type = REGULATOR_VOLTAGE;
>  	drvdata->desc.owner = THIS_MODULE;
>  
> -	if (drvtype->has_enable_clock) {
> +	if (drvtype && drvtype->has_enable_clock) {
>  		drvdata->desc.ops = &fixed_voltage_clkenabled_ops;
>  
>  		drvdata->enable_clock = devm_clk_get(dev, NULL);

      parent reply	other threads:[~2019-10-07 14:24 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-09-22  2:29 Axel Lin
2019-09-23  8:39 ` Philippe Schenker
2019-09-23 21:23 ` Applied "regulator: fixed: Prevent NULL pointer dereference when !CONFIG_OF" to the regulator tree Mark Brown
2019-10-07 14:24 ` Guenter Roeck [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=20191007142418.GA1732@roeck-us.net \
    --to=linux@roeck-us.net \
    --cc=axel.lin@ingics.com \
    --cc=broonie@kernel.org \
    --cc=lgirdwood@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=philippe.schenker@toradex.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

Powered by JetHome