linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
From: Markus Elfring <Markus.Elfring@web.de>
To: kernel-janitors@vger.kernel.org, linuxppc-dev@lists.ozlabs.org,
	Benjamin Herrenschmidt <benh@kernel.crashing.org>,
	Christophe Leroy <christophe.leroy@csgroup.eu>,
	Josh Boyer <jwboyer@linux.vnet.ibm.com>,
	Michael Ellerman <mpe@ellerman.id.au>,
	Nicholas Piggin <npiggin@gmail.com>, Stefan Roese <sr@denx.de>
Cc: LKML <linux-kernel@vger.kernel.org>, cocci@inria.fr
Subject: [PATCH 1/4] powerpc/4xx: Fix exception handling in ppc4xx_pciex_port_setup_hose()
Date: Thu, 16 Mar 2023 21:10:54 +0100	[thread overview]
Message-ID: <2e2fbd6f-e622-51b7-a19a-2662d8ca2d7f@web.de> (raw)
In-Reply-To: <72a7bfe2-6051-01b0-6c51-a0f8cc0c93a5@web.de>

Date: Thu, 16 Mar 2023 19:00:57 +0100

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

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

2. Use more appropriate labels instead.

3. Reorder jump targets at the end.

4. Delete two questionable checks.

This issue was detected by using the Coccinelle software.

Fixes: a2d2e1ec07a80946cbe812dc8c73291cad8214b2 ("[POWERPC] 4xx: PLB to PCI Express support")
Fixes: 80daac3f86d4f5aafc9d3e79addb90fa118244e2 ("[POWERPC] 4xx: Add endpoint support to 4xx PCIe driver")
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
 arch/powerpc/platforms/4xx/pci.c | 19 ++++++++++---------
 1 file changed, 10 insertions(+), 9 deletions(-)

diff --git a/arch/powerpc/platforms/4xx/pci.c b/arch/powerpc/platforms/4xx/pci.c
index ca5dd7a5842a..7336c7039b10 100644
--- a/arch/powerpc/platforms/4xx/pci.c
+++ b/arch/powerpc/platforms/4xx/pci.c
@@ -1930,7 +1930,7 @@ static void __init ppc4xx_pciex_port_setup_hose(struct ppc4xx_pciex_port *port)
     /* Allocate the host controller data structure */
     hose = pcibios_alloc_controller(port->node);
     if (!hose)
-        goto fail;
+        return;
 
     /* We stick the port number in "indirect_type" so the config space
      * ops can retrieve the port data structure easily
@@ -1962,7 +1962,7 @@ static void __init ppc4xx_pciex_port_setup_hose(struct ppc4xx_pciex_port *port)
         if (cfg_data == NULL) {
             printk(KERN_ERR "%pOF: Can't map external config space !",
                    port->node);
-            goto fail;
+            goto free_controller;
         }
         hose->cfg_data = cfg_data;
     }
@@ -1974,7 +1974,7 @@ static void __init ppc4xx_pciex_port_setup_hose(struct ppc4xx_pciex_port *port)
     if (mbase == NULL) {
         printk(KERN_ERR "%pOF: Can't map internal config space !",
                port->node);
-        goto fail;
+        goto recheck_cfg_data;
     }
     hose->cfg_addr = mbase;
 
@@ -2007,7 +2007,7 @@ static void __init ppc4xx_pciex_port_setup_hose(struct ppc4xx_pciex_port *port)
 
     /* Parse inbound mapping resources */
     if (ppc4xx_parse_dma_ranges(hose, mbase, &dma_window) != 0)
-        goto fail;
+        goto unmap_io_mbase;
 
     /* Configure outbound ranges POMs */
     ppc4xx_configure_pciex_POMs(port, hose, mbase);
@@ -2064,13 +2064,14 @@ static void __init ppc4xx_pciex_port_setup_hose(struct ppc4xx_pciex_port *port)
     }
 
     return;
- fail:
-    if (hose)
-        pcibios_free_controller(hose);
+
+unmap_io_mbase:
+    iounmap(mbase);
+recheck_cfg_data:
     if (cfg_data)
         iounmap(cfg_data);
-    if (mbase)
-        iounmap(mbase);
+free_controller:
+    pcibios_free_controller(hose);
 }
 
 static void __init ppc4xx_probe_pciex_bridge(struct device_node *np)
--
2.39.2



  reply	other threads:[~2023-03-16 20:12 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <f9303bdc-b1a7-be5e-56c6-dfa8232b8b55@web.de>
2023-03-16 20:07 ` [PATCH 0/4] powerpc/4xx: Adjustments for four function implementations Markus Elfring
2023-03-16 20:10   ` Markus Elfring [this message]
2023-03-16 20:14   ` [PATCH 2/4] powerpc/4xx: Fix exception handling in ppc4xx_probe_pcix_bridge() Markus Elfring
2023-03-16 20:16   ` [PATCH 3/4] powerpc/4xx: Fix exception handling in ppc4xx_probe_pci_bridge() Markus Elfring
2023-03-16 20:18   ` [PATCH 4/4] powerpc/4xx: Delete unnecessary variable initialisations in four functions Markus Elfring
2023-03-25 15:30   ` [PATCH v2 0/4] powerpc/4xx: Adjustments for four function implementations Markus Elfring
2023-03-25 15:36     ` [PATCH v2 1/4] powerpc/4xx: Fix exception handling in ppc4xx_pciex_port_setup_hose() Markus Elfring
2023-03-25 15:38     ` [PATCH v2 2/4] powerpc/4xx: Fix exception handling in ppc4xx_probe_pcix_bridge() Markus Elfring
2023-03-25 15:40     ` [PATCH v2 3/4] powerpc/4xx: Fix exception handling in ppc4xx_probe_pci_bridge() Markus Elfring
2023-03-25 15:42     ` [PATCH v2 4/4] powerpc/4xx: Delete unnecessary variable initialisations in four functions Markus Elfring
2024-01-05 17:42     ` [PATCH v2 0/4] powerpc/4xx: Adjustments for four function implementations Markus Elfring
2023-03-17  8:50 ` [PATCH] powerpc/pseries: Fix exception handling in pSeries_reconfig_add_node() Markus Elfring
2023-03-17 13:11   ` Nathan Lynch
2023-03-17 14:20     ` Markus Elfring
2023-03-17 15:41       ` Nathan Lynch
2023-03-18  7:30         ` Markus Elfring
2023-03-20 15:38           ` Nathan Lynch
2023-03-21  6:54             ` Markus Elfring
2023-03-21 10:30               ` [PATCH v2 0/2] powerpc/pseries: Fixes for " Markus Elfring
2023-03-21 10:33                 ` [PATCH v2 1/2] powerpc/pseries: Do not pass an error pointer to of_node_put() " Markus Elfring
2023-03-21 10:36                 ` [PATCH v2 2/2] powerpc/pseries: Fix exception handling " Markus Elfring
2023-03-25 13:40                 ` [PATCH resent v2 0/2] powerpc/pseries: Fixes for " Markus Elfring
2023-03-25 13:42                   ` [PATCH resent v2 1/2] powerpc/pseries: Do not pass an error pointer to of_node_put() " Markus Elfring
2023-03-25 13:44                   ` [PATCH resent v2 2/2] powerpc/pseries: Fix exception handling " Markus Elfring
2024-01-05 17:19                   ` [PATCH resent v2 0/2] powerpc/pseries: Fixes for " Markus Elfring

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=2e2fbd6f-e622-51b7-a19a-2662d8ca2d7f@web.de \
    --to=markus.elfring@web.de \
    --cc=benh@kernel.crashing.org \
    --cc=christophe.leroy@csgroup.eu \
    --cc=cocci@inria.fr \
    --cc=jwboyer@linux.vnet.ibm.com \
    --cc=kernel-janitors@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linuxppc-dev@lists.ozlabs.org \
    --cc=mpe@ellerman.id.au \
    --cc=npiggin@gmail.com \
    --cc=sr@denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).