Date: Sat, 25 Mar 2023 15:56:09 +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 <elfr...@users.sourceforge.net>
---
V3:
A closing parenthesis (which was overlooked somehow) was preserved
for an if statement.

 arch/powerpc/platforms/4xx/pci.c | 18 +++++++-----------
 1 file changed, 7 insertions(+), 11 deletions(-)

diff --git a/arch/powerpc/platforms/4xx/pci.c b/arch/powerpc/platforms/4xx/pci.c
index fdf13e12ca9d..46ba0a4e5b04 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);
 }

 /*
--
2.40.0

Reply via email to