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

gpio: pch: 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
09445a10 c7f5326f

+12 -3
+12 -3
drivers/gpio/gpio-pch.c
··· 331 331 return ret; 332 332 } 333 333 334 - static void pch_gpio_alloc_generic_chip(struct pch_gpio *chip, 335 - unsigned int irq_start, unsigned int num) 334 + static int pch_gpio_alloc_generic_chip(struct pch_gpio *chip, 335 + unsigned int irq_start, 336 + unsigned int num) 336 337 { 337 338 struct irq_chip_generic *gc; 338 339 struct irq_chip_type *ct; 339 340 340 341 gc = irq_alloc_generic_chip("pch_gpio", 1, irq_start, chip->base, 341 342 handle_simple_irq); 343 + if (!gc) 344 + return -ENOMEM; 345 + 342 346 gc->private = chip; 343 347 ct = gc->chip_types; 344 348 ··· 353 349 354 350 irq_setup_generic_chip(gc, IRQ_MSK(num), IRQ_GC_INIT_MASK_CACHE, 355 351 IRQ_NOREQUEST | IRQ_NOPROBE, 0); 352 + 353 + return 0; 356 354 } 357 355 358 356 static int pch_gpio_probe(struct pci_dev *pdev, ··· 431 425 goto err_request_irq; 432 426 } 433 427 434 - pch_gpio_alloc_generic_chip(chip, irq_base, gpio_pins[chip->ioh]); 428 + ret = pch_gpio_alloc_generic_chip(chip, irq_base, 429 + gpio_pins[chip->ioh]); 430 + if (ret) 431 + goto err_request_irq; 435 432 436 433 end: 437 434 return 0;