diff mbox series

gpio: fix a potential NULL pointer dereference

Message ID 20190324231002.2106-1-kjlu@umn.edu
State Not Applicable, archived
Headers show
Series gpio: fix a potential NULL pointer dereference | expand

Commit Message

Kangjie Lu March 24, 2019, 11:10 p.m. UTC
In case devm_kzalloc, the patch returns ENOMEM to avoid potential
NULL pointer dereference.

Signed-off-by: Kangjie Lu <kjlu@umn.edu>
---
 drivers/gpio/gpio-aspeed.c | 2 ++
 1 file changed, 2 insertions(+)

Comments

Bartosz Golaszewski March 25, 2019, 8:28 a.m. UTC | #1
pon., 25 mar 2019 o 00:12 Andrew Jeffery <andrew@aj.id.au> 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 <kjlu@umn.edu>
>
> Reviewed-by: Andrew Jeffery <andrew@aj.id.au>
>
> > ---
> >  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
diff mbox series

Patch

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