Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

gpio: sta2x11: check the return value of irq_alloc_generic_chip()

This function can fail, so check the return value before dereferencing
the returned pointer.

Signed-off-by: Bartosz Golaszewski <brgl@bgdev.pl>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>

authored by

Bartosz Golaszewski and committed by
Linus Walleij
d76e8bab 09445a10

+10 -2
+10 -2
drivers/gpio/gpio-sta2x11.c
··· 320 320 return ret; 321 321 } 322 322 323 - static void gsta_alloc_irq_chip(struct gsta_gpio *chip) 323 + static int gsta_alloc_irq_chip(struct gsta_gpio *chip) 324 324 { 325 325 struct irq_chip_generic *gc; 326 326 struct irq_chip_type *ct; 327 327 328 328 gc = irq_alloc_generic_chip(KBUILD_MODNAME, 1, chip->irq_base, 329 329 chip->reg_base, handle_simple_irq); 330 + if (!gc) 331 + return -ENOMEM; 332 + 330 333 gc->private = chip; 331 334 ct = gc->chip_types; 332 335 ··· 353 350 } 354 351 gc->irq_cnt = i - gc->irq_base; 355 352 } 353 + 354 + return 0; 356 355 } 357 356 358 357 /* The platform device used here is instantiated by the MFD device */ ··· 405 400 return err; 406 401 } 407 402 chip->irq_base = err; 408 - gsta_alloc_irq_chip(chip); 403 + 404 + err = gsta_alloc_irq_chip(chip); 405 + if (err) 406 + return err; 409 407 410 408 err = devm_request_irq(&dev->dev, pdev->irq, gsta_gpio_handler, 411 409 IRQF_SHARED, KBUILD_MODNAME, chip);