diff mbox

[2/2] powerpc/eeh: Reworked eeh_pe_bus_get()

Message ID 1454909719-17252-2-git-send-email-gwshan@linux.vnet.ibm.com (mailing list archive)
State Superseded
Headers show

Commit Message

Gavin Shan Feb. 8, 2016, 5:35 a.m. UTC
The original implementation is ugly: unnecessary if statements and
"out" tag. This reworks the function to avoid above weaknesses. No
functional changes introduced.

Signed-off-by: Gavin Shan <gwshan@linux.vnet.ibm.com>
---
 arch/powerpc/kernel/eeh_pe.c | 28 ++++++++++++----------------
 1 file changed, 12 insertions(+), 16 deletions(-)

Comments

Andrew Donnellan Feb. 8, 2016, 5:55 a.m. UTC | #1
On 08/02/16 16:35, Gavin Shan wrote:
> The original implementation is ugly: unnecessary if statements and
> "out" tag. This reworks the function to avoid above weaknesses. No
> functional changes introduced.
>
> Signed-off-by: Gavin Shan <gwshan@linux.vnet.ibm.com>

This is definitely a lot nicer to read and doesn't appear to have any 
functional changes.

Reviewed-by: Andrew Donnellan <andrew.donnellan@au1.ibm.com>
Gavin Shan Feb. 8, 2016, 10:40 p.m. UTC | #2
On Mon, Feb 08, 2016 at 04:35:19PM +1100, Gavin Shan wrote:
>The original implementation is ugly: unnecessary if statements and
>"out" tag. This reworks the function to avoid above weaknesses. No
>functional changes introduced.
>
>Signed-off-by: Gavin Shan <gwshan@linux.vnet.ibm.com>

Michael, please ignore this one now because it conflicts with another
patch which needs to be ported to stable. I'll repost all of them
later.

Thanks,
Gavin

>---
> arch/powerpc/kernel/eeh_pe.c | 28 ++++++++++++----------------
> 1 file changed, 12 insertions(+), 16 deletions(-)
>
>diff --git a/arch/powerpc/kernel/eeh_pe.c b/arch/powerpc/kernel/eeh_pe.c
>index 8654cb1..1d64e60 100644
>--- a/arch/powerpc/kernel/eeh_pe.c
>+++ b/arch/powerpc/kernel/eeh_pe.c
>@@ -923,25 +923,21 @@ out:
>  */
> struct pci_bus *eeh_pe_bus_get(struct eeh_pe *pe)
> {
>-	struct pci_bus *bus = NULL;
> 	struct eeh_dev *edev;
> 	struct pci_dev *pdev;
>
>-	if (pe->type & EEH_PE_PHB) {
>-		bus = pe->phb->bus;
>-	} else if (pe->type & EEH_PE_BUS ||
>-		   pe->type & EEH_PE_DEVICE) {
>-		if (pe->bus) {
>-			bus = pe->bus;
>-			goto out;
>-		}
>+	if (pe->type & EEH_PE_PHB)
>+		return pe->phb->bus;
>
>-		edev = list_first_entry(&pe->edevs, struct eeh_dev, list);
>-		pdev = eeh_dev_to_pci_dev(edev);
>-		if (pdev)
>-			bus = pdev->bus;
>-	}
>+	/* The primary bus might be cached during probe time */
>+	if (pe->bus)
>+		return pe->bus;
>
>-out:
>-	return bus;
>+	/* Retrieve the parent PCI bus of first (top) PCI device */
>+	edev = list_first_entry_or_null(&pe->edevs, struct eeh_dev, list);
>+	pdev = eeh_dev_to_pci_dev(edev);
>+	if (pdev)
>+		return pdev->bus;
>+
>+	return NULL;
> }
>-- 
>2.1.0
>
diff mbox

Patch

diff --git a/arch/powerpc/kernel/eeh_pe.c b/arch/powerpc/kernel/eeh_pe.c
index 8654cb1..1d64e60 100644
--- a/arch/powerpc/kernel/eeh_pe.c
+++ b/arch/powerpc/kernel/eeh_pe.c
@@ -923,25 +923,21 @@  out:
  */
 struct pci_bus *eeh_pe_bus_get(struct eeh_pe *pe)
 {
-	struct pci_bus *bus = NULL;
 	struct eeh_dev *edev;
 	struct pci_dev *pdev;
 
-	if (pe->type & EEH_PE_PHB) {
-		bus = pe->phb->bus;
-	} else if (pe->type & EEH_PE_BUS ||
-		   pe->type & EEH_PE_DEVICE) {
-		if (pe->bus) {
-			bus = pe->bus;
-			goto out;
-		}
+	if (pe->type & EEH_PE_PHB)
+		return pe->phb->bus;
 
-		edev = list_first_entry(&pe->edevs, struct eeh_dev, list);
-		pdev = eeh_dev_to_pci_dev(edev);
-		if (pdev)
-			bus = pdev->bus;
-	}
+	/* The primary bus might be cached during probe time */
+	if (pe->bus)
+		return pe->bus;
 
-out:
-	return bus;
+	/* Retrieve the parent PCI bus of first (top) PCI device */
+	edev = list_first_entry_or_null(&pe->edevs, struct eeh_dev, list);
+	pdev = eeh_dev_to_pci_dev(edev);
+	if (pdev)
+		return pdev->bus;
+
+	return NULL;
 }