diff mbox series

[3/4] powerpc/4xx: Fix exception handling in ppc4xx_probe_pci_bridge()

Message ID 4aa9785d-5992-91c0-c0ba-700192749f78@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:16 p.m. UTC
Date: Thu, 16 Mar 2023 19:12:10 +0100

The label “fail” was used to jump to another pointer check despite of
the detail in the implementation of the function “ppc4xx_probe_pci_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: c839e0eff500af03de65e560c2e21c3831586e6e ("[POWERPC] 4xx: PLB to PCI 2.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 fdf13e12ca9d..0c0848f0c819 100644
--- a/arch/powerpc/platforms/4xx/pci.c
+++ b/arch/powerpc/platforms/4xx/pci.c
@@ -358,13 +358,13 @@  static void __init ppc4xx_probe_pci_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;
@@ -383,8 +383,10 @@  static void __init ppc4xx_probe_pci_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_pci_PMMs(hose, reg);
@@ -393,14 +395,8 @@  static void __init ppc4xx_probe_pci_bridge(struct device_node *np)
     ppc4xx_configure_pci_PTMs(hose, reg, &dma_window);
 
     /* We don't need the registers anymore */
+unmap_io:
     iounmap(reg);
-    return;
-
- fail:
-    if (hose)
-        pcibios_free_controller(hose);
-    if (reg)
-        iounmap(reg);
 }
 
 /*