2010-11-19 18:42:06

by Vasily Kulikov

[permalink] [raw]
Subject: [PATCH] power: gpio-charger: fix potential NULL dereference

kzalloc() result is not compared with NULL. It might lead to NULL
pointer dereference in OOM situation.

Signed-off-by: Vasiliy Kulikov <[email protected]>
---
Compile tested only.

drivers/power/gpio-charger.c | 4 ++++
1 files changed, 4 insertions(+), 0 deletions(-)

diff --git a/drivers/power/gpio-charger.c b/drivers/power/gpio-charger.c
index fccbe99..b07a71c 100644
--- a/drivers/power/gpio-charger.c
+++ b/drivers/power/gpio-charger.c
@@ -87,6 +87,10 @@ static int __devinit gpio_charger_probe(struct platform_device *pdev)
}

gpio_charger = kzalloc(sizeof(*gpio_charger), GFP_KERNEL);
+ if (!gpio_charger) {
+ dev_err(&pdev->dev, "kzalloc failed\n");
+ return -ENOMEM;
+ }

charger = &gpio_charger->charger;

--
1.7.0.4


2010-11-19 19:02:18

by Lars-Peter Clausen

[permalink] [raw]
Subject: Re: [PATCH] power: gpio-charger: fix potential NULL dereference

Vasiliy Kulikov wrote:
> kzalloc() result is not compared with NULL. It might lead to NULL
> pointer dereference in OOM situation.
>
> Signed-off-by: Vasiliy Kulikov <[email protected]>
> ---
> Compile tested only.
>
> drivers/power/gpio-charger.c | 4 ++++
> 1 files changed, 4 insertions(+), 0 deletions(-)
>
> diff --git a/drivers/power/gpio-charger.c b/drivers/power/gpio-charger.c
> index fccbe99..b07a71c 100644
> --- a/drivers/power/gpio-charger.c
> +++ b/drivers/power/gpio-charger.c
> @@ -87,6 +87,10 @@ static int __devinit gpio_charger_probe(struct platform_device *pdev)
> }
>
> gpio_charger = kzalloc(sizeof(*gpio_charger), GFP_KERNEL);
> + if (!gpio_charger) {
> + dev_err(&pdev->dev, "kzalloc failed\n");
> + return -ENOMEM;
> + }
>
> charger = &gpio_charger->charger;
>

Hi

I already send a similar patch yesterday.
See http://lkml.org/lkml/2010/11/18/632

- Lars