public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] regulator: Avoid potential NULL dereference in reg_fixed_voltage_probe()
@ 2011-11-27  2:13 Axel Lin
  2011-11-27 11:35 ` Mark Brown
  0 siblings, 1 reply; 4+ messages in thread
From: Axel Lin @ 2011-11-27  2:13 UTC (permalink / raw)
  To: linux-kernel; +Cc: Rajendra Nayak, Liam Girdwood, Mark Brown

of_get_fixed_voltage_config() may return NULL, return -ENOMEM in this case
so we don't dereference NULL pointer.

Signed-off-by: Axel Lin <axel.lin@gmail.com>
---
 drivers/regulator/fixed.c |    5 ++++-
 1 files changed, 4 insertions(+), 1 deletions(-)

diff --git a/drivers/regulator/fixed.c b/drivers/regulator/fixed.c
index 639e19d..2f917a1 100644
--- a/drivers/regulator/fixed.c
+++ b/drivers/regulator/fixed.c
@@ -166,8 +166,11 @@ static int __devinit reg_fixed_voltage_probe(struct platform_device *pdev)
 	struct fixed_voltage_data *drvdata;
 	int ret;
 
-	if (pdev->dev.of_node)
+	if (pdev->dev.of_node) {
 		config = of_get_fixed_voltage_config(&pdev->dev);
+		if (!config)
+			return -ENOMEM;
+	}
 
 	drvdata = kzalloc(sizeof(struct fixed_voltage_data), GFP_KERNEL);
 	if (drvdata == NULL) {
-- 
1.7.5.4




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

* Re: [PATCH] regulator: Avoid potential NULL dereference in reg_fixed_voltage_probe()
  2011-11-27  2:13 [PATCH] regulator: Avoid potential NULL dereference in reg_fixed_voltage_probe() Axel Lin
@ 2011-11-27 11:35 ` Mark Brown
  2011-11-27 11:56   ` Axel Lin
  0 siblings, 1 reply; 4+ messages in thread
From: Mark Brown @ 2011-11-27 11:35 UTC (permalink / raw)
  To: Axel Lin; +Cc: linux-kernel, Rajendra Nayak, Liam Girdwood

On Sun, Nov 27, 2011 at 10:13:50AM +0800, Axel Lin wrote:

> -	if (pdev->dev.of_node)
> +	if (pdev->dev.of_node) {
>  		config = of_get_fixed_voltage_config(&pdev->dev);
> +		if (!config)
> +			return -ENOMEM;
> +	}

Looking at this I'm thinking it's better to just drop the check for
of_node entirely and just let of_get_fixed_voltage_config() fail to find
what it needs.

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

* Re: [PATCH] regulator: Avoid potential NULL dereference in reg_fixed_voltage_probe()
  2011-11-27 11:35 ` Mark Brown
@ 2011-11-27 11:56   ` Axel Lin
  2011-11-27 12:02     ` Mark Brown
  0 siblings, 1 reply; 4+ messages in thread
From: Axel Lin @ 2011-11-27 11:56 UTC (permalink / raw)
  To: Mark Brown; +Cc: linux-kernel, Rajendra Nayak, Liam Girdwood

2011/11/27 Mark Brown <broonie@opensource.wolfsonmicro.com>:
> On Sun, Nov 27, 2011 at 10:13:50AM +0800, Axel Lin wrote:
>
>> -     if (pdev->dev.of_node)
>> +     if (pdev->dev.of_node) {
>>               config = of_get_fixed_voltage_config(&pdev->dev);
>> +             if (!config)
>> +                     return -ENOMEM;
>> +     }
>
> Looking at this I'm thinking it's better to just drop the check for
> of_node entirely and just let of_get_fixed_voltage_config() fail to find
> what it needs.
>
In the case of pdev->dev.of_node == NULL, config points to
pdev->dev.platform_data.

Or do you prefer change it this way:

--- a/drivers/regulator/fixed.c
+++ b/drivers/regulator/fixed.c
@@ -163,12 +163,17 @@ static struct regulator_ops fixed_voltage_ops = {

 static int __devinit reg_fixed_voltage_probe(struct platform_device *pdev)
 {
-       struct fixed_voltage_config *config = pdev->dev.platform_data;
+       struct fixed_voltage_config *config;
        struct fixed_voltage_data *drvdata;
        int ret;

        if (pdev->dev.of_node)
                config = of_get_fixed_voltage_config(&pdev->dev);
+       else
+               config = pdev->dev.platform_data;
+
+       if (!config)
+               return -ENOMEM;

        drvdata = kzalloc(sizeof(struct fixed_voltage_data), GFP_KERNEL);
        if (drvdata == NULL) {

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

* Re: [PATCH] regulator: Avoid potential NULL dereference in reg_fixed_voltage_probe()
  2011-11-27 11:56   ` Axel Lin
@ 2011-11-27 12:02     ` Mark Brown
  0 siblings, 0 replies; 4+ messages in thread
From: Mark Brown @ 2011-11-27 12:02 UTC (permalink / raw)
  To: Axel Lin; +Cc: linux-kernel, Rajendra Nayak, Liam Girdwood

On Sun, Nov 27, 2011 at 07:56:20PM +0800, Axel Lin wrote:

> Or do you prefer change it this way:

Yes, that looks sensible.

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

end of thread, other threads:[~2011-11-27 12:03 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-11-27  2:13 [PATCH] regulator: Avoid potential NULL dereference in reg_fixed_voltage_probe() Axel Lin
2011-11-27 11:35 ` Mark Brown
2011-11-27 11:56   ` Axel Lin
2011-11-27 12:02     ` Mark Brown

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