regulator: fixed: Prevent NULL pointer dereference when !CONFIG_OF
diff mbox series

Message ID 20190922022928.28355-1-axel.lin@ingics.com
State Accepted
Commit 1d6db22ff7d67a17c571543c69c63b1d261249b0
Headers show
Series
  • regulator: fixed: Prevent NULL pointer dereference when !CONFIG_OF
Related show

Commit Message

Axel Lin Sept. 22, 2019, 2:29 a.m. UTC
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(-)

Comments

Philippe Schenker Sept. 23, 2019, 8:39 a.m. UTC | #1
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);
Guenter Roeck Oct. 7, 2019, 2:24 p.m. UTC | #2
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);

Patch
diff mbox series

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