All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] regulator: fixed: Prevent NULL pointer dereference when !CONFIG_OF
@ 2019-09-22  2:29 Axel Lin
  2019-09-23  8:39 ` Philippe Schenker
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Axel Lin @ 2019-09-22  2:29 UTC (permalink / raw)
  To: Mark Brown; +Cc: Philippe Schenker, Liam Girdwood, linux-kernel, Axel Lin

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>
---
 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);
-- 
2.20.1


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] regulator: fixed: Prevent NULL pointer dereference when !CONFIG_OF
  2019-09-22  2:29 [PATCH] regulator: fixed: Prevent NULL pointer dereference when !CONFIG_OF 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 ` [PATCH] regulator: fixed: Prevent NULL pointer dereference when !CONFIG_OF Guenter Roeck
  2 siblings, 0 replies; 4+ messages in thread
From: Philippe Schenker @ 2019-09-23  8:39 UTC (permalink / raw)
  To: axel.lin, broonie; +Cc: lgirdwood, linux-kernel

On Sun, 2019-09-22 at 10:29 +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>

> ---
>  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);

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Applied "regulator: fixed: Prevent NULL pointer dereference when !CONFIG_OF" to the regulator tree
  2019-09-22  2:29 [PATCH] regulator: fixed: Prevent NULL pointer dereference when !CONFIG_OF Axel Lin
  2019-09-23  8:39 ` Philippe Schenker
@ 2019-09-23 21:23 ` Mark Brown
  2019-10-07 14:24 ` [PATCH] regulator: fixed: Prevent NULL pointer dereference when !CONFIG_OF Guenter Roeck
  2 siblings, 0 replies; 4+ messages in thread
From: Mark Brown @ 2019-09-23 21:23 UTC (permalink / raw)
  To: Axel Lin; +Cc: Liam Girdwood, linux-kernel, Mark Brown, Philippe Schenker

The patch

   regulator: fixed: Prevent NULL pointer dereference when !CONFIG_OF

has been applied to the regulator tree at

   https://git.kernel.org/pub/scm/linux/kernel/git/broonie/regulator.git for-5.4

All being well this means that it will be integrated into the linux-next
tree (usually sometime in the next 24 hours) and sent to Linus during
the next merge window (or sooner if it is a bug fix), however if
problems are discovered then the patch may be dropped or reverted.  

You may get further e-mails resulting from automated or manual testing
and review of the tree, please engage with people reporting problems and
send followup patches addressing any issues that are reported if needed.

If any updates are required or you are submitting further changes they
should be sent as incremental updates against current git, existing
patches will not be replaced.

Please add any relevant lists and maintainers to the CCs when replying
to this mail.

Thanks,
Mark

From 1d6db22ff7d67a17c571543c69c63b1d261249b0 Mon Sep 17 00:00:00 2001
From: Axel Lin <axel.lin@ingics.com>
Date: Sun, 22 Sep 2019 10:29:28 +0800
Subject: [PATCH] regulator: fixed: Prevent NULL pointer dereference when
 !CONFIG_OF

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>
Link: https://lore.kernel.org/r/20190922022928.28355-1-axel.lin@ingics.com
Signed-off-by: Mark Brown <broonie@kernel.org>
---
 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);
-- 
2.20.1


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] regulator: fixed: Prevent NULL pointer dereference when !CONFIG_OF
  2019-09-22  2:29 [PATCH] regulator: fixed: Prevent NULL pointer dereference when !CONFIG_OF 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
  2 siblings, 0 replies; 4+ messages in thread
From: Guenter Roeck @ 2019-10-07 14:24 UTC (permalink / raw)
  To: Axel Lin; +Cc: Mark Brown, Philippe Schenker, Liam Girdwood, linux-kernel

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);

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2019-10-07 14:24 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-09-22  2:29 [PATCH] regulator: fixed: Prevent NULL pointer dereference when !CONFIG_OF 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 ` [PATCH] regulator: fixed: Prevent NULL pointer dereference when !CONFIG_OF Guenter Roeck

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.