arch/powerpc/kernel/pci-common.c:418 pci_read_irq_line() warn: returning -1 instead of -ENOMEM is sloppy
From: Dan Carpenter
Date: Tue Jun 22 2021 - 10:23:00 EST
tree: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master
head: a96bfed64c8986d6404e553f18203cae1f5ac7e6
commit: 450be4960a0fb89b931a6bb3c3f0bb538ac4c03c powerpc/pci: Remove LSI mappings on device teardown
config: powerpc64-randconfig-m031-20210622 (attached as .config)
compiler: powerpc64le-linux-gcc (GCC) 9.3.0
If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@xxxxxxxxx>
Reported-by: Dan Carpenter <dan.carpenter@xxxxxxxxxx>
smatch warnings:
arch/powerpc/kernel/pci-common.c:418 pci_read_irq_line() warn: returning -1 instead of -ENOMEM is sloppy
vim +418 arch/powerpc/kernel/pci-common.c
4666ca2aa34410 Benjamin Herrenschmidt 2011-11-29 410 static int pci_read_irq_line(struct pci_dev *pci_dev)
58083dade53cd4 Kumar Gala 2007-06-27 411 {
c591c2e36ccc9a Alexey Kardashevskiy 2018-02-09 412 int virq;
450be4960a0fb8 Oliver O'Halloran 2020-12-02 413 struct pci_intx_virq *vi, *vitmp;
450be4960a0fb8 Oliver O'Halloran 2020-12-02 414
450be4960a0fb8 Oliver O'Halloran 2020-12-02 415 /* Preallocate vi as rewind is complex if this fails after mapping */
450be4960a0fb8 Oliver O'Halloran 2020-12-02 416 vi = kzalloc(sizeof(struct pci_intx_virq), GFP_KERNEL);
450be4960a0fb8 Oliver O'Halloran 2020-12-02 417 if (!vi)
450be4960a0fb8 Oliver O'Halloran 2020-12-02 @418 return -1;
-ENOMEM;
58083dade53cd4 Kumar Gala 2007-06-27 419
b0494bc8ee449f Benjamin Herrenschmidt 2008-10-27 420 pr_debug("PCI: Try to map irq for %s...\n", pci_name(pci_dev));
58083dade53cd4 Kumar Gala 2007-06-27 421
58083dade53cd4 Kumar Gala 2007-06-27 422 /* Try to get a mapping from the device-tree */
c591c2e36ccc9a Alexey Kardashevskiy 2018-02-09 423 virq = of_irq_parse_and_map_pci(pci_dev, 0, 0);
c591c2e36ccc9a Alexey Kardashevskiy 2018-02-09 424 if (virq <= 0) {
58083dade53cd4 Kumar Gala 2007-06-27 425 u8 line, pin;
58083dade53cd4 Kumar Gala 2007-06-27 426
58083dade53cd4 Kumar Gala 2007-06-27 427 /* If that fails, lets fallback to what is in the config
58083dade53cd4 Kumar Gala 2007-06-27 428 * space and map that through the default controller. We
58083dade53cd4 Kumar Gala 2007-06-27 429 * also set the type to level low since that's what PCI
58083dade53cd4 Kumar Gala 2007-06-27 430 * interrupts are. If your platform does differently, then
58083dade53cd4 Kumar Gala 2007-06-27 431 * either provide a proper interrupt tree or don't use this
58083dade53cd4 Kumar Gala 2007-06-27 432 * function.
58083dade53cd4 Kumar Gala 2007-06-27 433 */
58083dade53cd4 Kumar Gala 2007-06-27 434 if (pci_read_config_byte(pci_dev, PCI_INTERRUPT_PIN, &pin))
450be4960a0fb8 Oliver O'Halloran 2020-12-02 435 goto error_exit;
58083dade53cd4 Kumar Gala 2007-06-27 436 if (pin == 0)
450be4960a0fb8 Oliver O'Halloran 2020-12-02 437 goto error_exit;
58083dade53cd4 Kumar Gala 2007-06-27 438 if (pci_read_config_byte(pci_dev, PCI_INTERRUPT_LINE, &line) ||
54a24cbbd0184f Benjamin Herrenschmidt 2007-12-20 439 line == 0xff || line == 0) {
450be4960a0fb8 Oliver O'Halloran 2020-12-02 440 goto error_exit;
58083dade53cd4 Kumar Gala 2007-06-27 441 }
b0494bc8ee449f Benjamin Herrenschmidt 2008-10-27 442 pr_debug(" No map ! Using line %d (pin %d) from PCI config\n",
54a24cbbd0184f Benjamin Herrenschmidt 2007-12-20 443 line, pin);
58083dade53cd4 Kumar Gala 2007-06-27 444
58083dade53cd4 Kumar Gala 2007-06-27 445 virq = irq_create_mapping(NULL, line);
ef24ba7091517d Michael Ellerman 2016-09-06 446 if (virq)
ec775d0e70eb6b Thomas Gleixner 2011-03-25 447 irq_set_irq_type(virq, IRQ_TYPE_LEVEL_LOW);
58083dade53cd4 Kumar Gala 2007-06-27 448 }
ef24ba7091517d Michael Ellerman 2016-09-06 449
ef24ba7091517d Michael Ellerman 2016-09-06 450 if (!virq) {
b0494bc8ee449f Benjamin Herrenschmidt 2008-10-27 451 pr_debug(" Failed to map !\n");
450be4960a0fb8 Oliver O'Halloran 2020-12-02 452 goto error_exit;
58083dade53cd4 Kumar Gala 2007-06-27 453 }
58083dade53cd4 Kumar Gala 2007-06-27 454
b0494bc8ee449f Benjamin Herrenschmidt 2008-10-27 455 pr_debug(" Mapped to linux irq %d\n", virq);
58083dade53cd4 Kumar Gala 2007-06-27 456
58083dade53cd4 Kumar Gala 2007-06-27 457 pci_dev->irq = virq;
58083dade53cd4 Kumar Gala 2007-06-27 458
450be4960a0fb8 Oliver O'Halloran 2020-12-02 459 mutex_lock(&intx_mutex);
450be4960a0fb8 Oliver O'Halloran 2020-12-02 460 list_for_each_entry(vitmp, &intx_list, list_node) {
450be4960a0fb8 Oliver O'Halloran 2020-12-02 461 if (vitmp->virq == virq) {
450be4960a0fb8 Oliver O'Halloran 2020-12-02 462 kref_get(&vitmp->kref);
450be4960a0fb8 Oliver O'Halloran 2020-12-02 463 kfree(vi);
450be4960a0fb8 Oliver O'Halloran 2020-12-02 464 vi = NULL;
450be4960a0fb8 Oliver O'Halloran 2020-12-02 465 break;
450be4960a0fb8 Oliver O'Halloran 2020-12-02 466 }
450be4960a0fb8 Oliver O'Halloran 2020-12-02 467 }
450be4960a0fb8 Oliver O'Halloran 2020-12-02 468 if (vi) {
450be4960a0fb8 Oliver O'Halloran 2020-12-02 469 vi->virq = virq;
450be4960a0fb8 Oliver O'Halloran 2020-12-02 470 kref_init(&vi->kref);
450be4960a0fb8 Oliver O'Halloran 2020-12-02 471 list_add_tail(&vi->list_node, &intx_list);
450be4960a0fb8 Oliver O'Halloran 2020-12-02 472 }
450be4960a0fb8 Oliver O'Halloran 2020-12-02 473 mutex_unlock(&intx_mutex);
450be4960a0fb8 Oliver O'Halloran 2020-12-02 474
58083dade53cd4 Kumar Gala 2007-06-27 475 return 0;
450be4960a0fb8 Oliver O'Halloran 2020-12-02 476 error_exit:
450be4960a0fb8 Oliver O'Halloran 2020-12-02 477 kfree(vi);
450be4960a0fb8 Oliver O'Halloran 2020-12-02 478 return -1;
58083dade53cd4 Kumar Gala 2007-06-27 479 }
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@xxxxxxxxxxxx