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

gpio: ml-ioh: 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
e3fe07e0 d76e8bab

+13 -3
+13 -3
drivers/gpio/gpio-ml-ioh.c
··· 385 385 return ret; 386 386 } 387 387 388 - static void ioh_gpio_alloc_generic_chip(struct ioh_gpio *chip, 389 - unsigned int irq_start, unsigned int num) 388 + static int ioh_gpio_alloc_generic_chip(struct ioh_gpio *chip, 389 + unsigned int irq_start, 390 + unsigned int num) 390 391 { 391 392 struct irq_chip_generic *gc; 392 393 struct irq_chip_type *ct; 393 394 394 395 gc = irq_alloc_generic_chip("ioh_gpio", 1, irq_start, chip->base, 395 396 handle_simple_irq); 397 + if (!gc) 398 + return -ENOMEM; 399 + 396 400 gc->private = chip; 397 401 ct = gc->chip_types; 398 402 ··· 408 404 409 405 irq_setup_generic_chip(gc, IRQ_MSK(num), IRQ_GC_INIT_MASK_CACHE, 410 406 IRQ_NOREQUEST | IRQ_NOPROBE, 0); 407 + 408 + return 0; 411 409 } 412 410 413 411 static int ioh_gpio_probe(struct pci_dev *pdev, ··· 474 468 goto err_gpiochip_add; 475 469 } 476 470 chip->irq_base = irq_base; 477 - ioh_gpio_alloc_generic_chip(chip, irq_base, num_ports[j]); 471 + 472 + ret = ioh_gpio_alloc_generic_chip(chip, 473 + irq_base, num_ports[j]); 474 + if (ret) 475 + goto err_gpiochip_add; 478 476 } 479 477 480 478 chip = chip_save;