spi: dw-pci: free previously allocated IRQs if desc->setup() fails
authorJay Fang <f.fangjian@huawei.com>
Tue, 15 Sep 2020 01:22:49 +0000 (09:22 +0800)
committerMark Brown <broonie@kernel.org>
Thu, 17 Sep 2020 18:56:04 +0000 (19:56 +0100)
Free previously allocated IRQs when return an error code of desc->setup()
which is not always successful. And simplify the code by adding a goto
label.

Fixes: 8f5c285f3ef5 ("SPI: designware: pci: Switch over to MSI interrupts")
CC: Felipe Balbi <felipe.balbi@linux.intel.com>
Signed-off-by: Jay Fang <f.fangjian@huawei.com>
Link: https://lore.kernel.org/r/1600132969-53037-1-git-send-email-f.fangjian@huawei.com
Signed-off-by: Mark Brown <broonie@kernel.org>
drivers/spi/spi-dw-pci.c

index 2ea7380..271839a 100644 (file)
@@ -127,18 +127,16 @@ static int spi_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
                if (desc->setup) {
                        ret = desc->setup(dws);
                        if (ret)
-                               return ret;
+                               goto err_free_irq_vectors;
                }
        } else {
-               pci_free_irq_vectors(pdev);
-               return -ENODEV;
+               ret = -ENODEV;
+               goto err_free_irq_vectors;
        }
 
        ret = dw_spi_add_host(&pdev->dev, dws);
-       if (ret) {
-               pci_free_irq_vectors(pdev);
-               return ret;
-       }
+       if (ret)
+               goto err_free_irq_vectors;
 
        /* PCI hook and SPI hook use the same drv data */
        pci_set_drvdata(pdev, dws);
@@ -152,6 +150,10 @@ static int spi_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
        pm_runtime_allow(&pdev->dev);
 
        return 0;
+
+err_free_irq_vectors:
+       pci_free_irq_vectors(pdev);
+       return ret;
 }
 
 static void spi_pci_remove(struct pci_dev *pdev)