2019-03-24 23:10:59

by Kangjie Lu

[permalink] [raw]
Subject: [PATCH] gpio: fix a potential NULL pointer dereference

In case devm_kzalloc, the patch returns ENOMEM to avoid potential
NULL pointer dereference.

Signed-off-by: Kangjie Lu <[email protected]>
---
drivers/gpio/gpio-aspeed.c | 2 ++
1 file changed, 2 insertions(+)

diff --git a/drivers/gpio/gpio-aspeed.c b/drivers/gpio/gpio-aspeed.c
index 854bce4fb9e7..217507002dbc 100644
--- a/drivers/gpio/gpio-aspeed.c
+++ b/drivers/gpio/gpio-aspeed.c
@@ -1224,6 +1224,8 @@ static int __init aspeed_gpio_probe(struct platform_device *pdev)

gpio->offset_timer =
devm_kzalloc(&pdev->dev, gpio->chip.ngpio, GFP_KERNEL);
+ if (!gpio->offset_timer)
+ return -ENOMEM;

return aspeed_gpio_setup_irqs(gpio, pdev);
}
--
2.17.1



2019-03-24 23:20:08

by Andrew Jeffery

[permalink] [raw]
Subject: Re: [PATCH] gpio: fix a potential NULL pointer dereference



On Mon, 25 Mar 2019, at 09:40, Kangjie Lu wrote:
> In case devm_kzalloc, the patch returns ENOMEM to avoid potential
> NULL pointer dereference.
>
> Signed-off-by: Kangjie Lu <[email protected]>

Reviewed-by: Andrew Jeffery <[email protected]>

> ---
> drivers/gpio/gpio-aspeed.c | 2 ++
> 1 file changed, 2 insertions(+)
>
> diff --git a/drivers/gpio/gpio-aspeed.c b/drivers/gpio/gpio-aspeed.c
> index 854bce4fb9e7..217507002dbc 100644
> --- a/drivers/gpio/gpio-aspeed.c
> +++ b/drivers/gpio/gpio-aspeed.c
> @@ -1224,6 +1224,8 @@ static int __init aspeed_gpio_probe(struct
> platform_device *pdev)
>
> gpio->offset_timer =
> devm_kzalloc(&pdev->dev, gpio->chip.ngpio, GFP_KERNEL);
> + if (!gpio->offset_timer)
> + return -ENOMEM;
>
> return aspeed_gpio_setup_irqs(gpio, pdev);
> }
> --
> 2.17.1
>
>

2019-03-25 08:29:57

by Bartosz Golaszewski

[permalink] [raw]
Subject: Re: [PATCH] gpio: fix a potential NULL pointer dereference

pon., 25 mar 2019 o 00:12 Andrew Jeffery <[email protected]> napisaƂ(a):
>
>
>
> On Mon, 25 Mar 2019, at 09:40, Kangjie Lu wrote:
> > In case devm_kzalloc, the patch returns ENOMEM to avoid potential
> > NULL pointer dereference.
> >
> > Signed-off-by: Kangjie Lu <[email protected]>
>
> Reviewed-by: Andrew Jeffery <[email protected]>
>
> > ---
> > drivers/gpio/gpio-aspeed.c | 2 ++
> > 1 file changed, 2 insertions(+)
> >
> > diff --git a/drivers/gpio/gpio-aspeed.c b/drivers/gpio/gpio-aspeed.c
> > index 854bce4fb9e7..217507002dbc 100644
> > --- a/drivers/gpio/gpio-aspeed.c
> > +++ b/drivers/gpio/gpio-aspeed.c
> > @@ -1224,6 +1224,8 @@ static int __init aspeed_gpio_probe(struct
> > platform_device *pdev)
> >
> > gpio->offset_timer =
> > devm_kzalloc(&pdev->dev, gpio->chip.ngpio, GFP_KERNEL);
> > + if (!gpio->offset_timer)
> > + return -ENOMEM;
> >
> > return aspeed_gpio_setup_irqs(gpio, pdev);
> > }
> > --
> > 2.17.1
> >
> >

Applied to fixes.

Bart