diff mbox series

[2/4] powerpc/4xx: Fix exception handling in ppc4xx_probe_pcix_bridge()

Message ID 1f1a8941-88a8-b2fa-b186-4e57e6809a10@web.de (mailing list archive)
State Superseded
Headers show
Series powerpc/4xx: Adjustments for four function implementations | expand

Commit Message

Markus Elfring March 16, 2023, 8:14 p.m. UTC
Date: Thu, 16 Mar 2023 19:09:33 +0100

The label “fail” was used to jump to another pointer check despite of
the detail in the implementation of the function “ppc4xx_probe_pcix_bridge”
that it was determined already that the corresponding variable contained
a null pointer (because of a failed function call in two cases).

1. Thus return directly after a call of the function “ioremap” failed.

2. Use a more appropriate label instead.

3. Delete two questionable checks.

4. Adjust the exception handling for another if branch a bit more.

5. Remove a return statement at the end.

This issue was detected by using the Coccinelle software.

Fixes: 5738ec6d00b7abbcd4cd342af83fd18d192b0979 ("[POWERPC] 4xx: PLB to PCI-X support")
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
 arch/powerpc/platforms/4xx/pci.c | 18 +++++++-----------
 1 file changed, 7 insertions(+), 11 deletions(-)

--
2.39.2
diff mbox series

Patch

diff --git a/arch/powerpc/platforms/4xx/pci.c b/arch/powerpc/platforms/4xx/pci.c
index 7336c7039b10..fdf13e12ca9d 100644
--- a/arch/powerpc/platforms/4xx/pci.c
+++ b/arch/powerpc/platforms/4xx/pci.c
@@ -564,13 +564,13 @@  static void __init ppc4xx_probe_pcix_bridge(struct device_node *np)
     reg = ioremap(rsrc_reg.start, resource_size(&rsrc_reg));
     if (reg == NULL) {
         printk(KERN_ERR "%pOF: Can't map registers !", np);
-        goto fail;
+        return;
     }
 
     /* Allocate the host controller data structure */
     hose = pcibios_alloc_controller(np);
     if (!hose)
-        goto fail;
+        goto unmap_io;
 
     hose->first_busno = bus_range ? bus_range[0] : 0x0;
     hose->last_busno = bus_range ? bus_range[1] : 0xff;
@@ -595,8 +595,10 @@  static void __init ppc4xx_probe_pcix_bridge(struct device_node *np)
     pci_process_bridge_OF_ranges(hose, np, primary);
 
     /* Parse inbound mapping resources */
-    if (ppc4xx_parse_dma_ranges(hose, reg, &dma_window) != 0)
-        goto fail;
+    if (ppc4xx_parse_dma_ranges(hose, reg, &dma_window)) {
+        pcibios_free_controller(hose);
+        goto unmap_io;
+    }
 
     /* Configure outbound ranges POMs */
     ppc4xx_configure_pcix_POMs(hose, reg);
@@ -605,14 +607,8 @@  static void __init ppc4xx_probe_pcix_bridge(struct device_node *np)
     ppc4xx_configure_pcix_PIMs(hose, reg, &dma_window, big_pim, msi);
 
     /* We don't need the registers anymore */
+unmap_io:
     iounmap(reg);
-    return;
-
- fail:
-    if (hose)
-        pcibios_free_controller(hose);
-    if (reg)
-        iounmap(reg);
 }
 
 #ifdef CONFIG_PPC4xx_PCI_EXPRESS