[PATCH RFC 06/15] powerpc/eeh: Sync eeh_phb_pe_get()

Sam Bobroff sbobroff at linux.ibm.com
Wed Oct 2 16:02:44 AEST 2019


Synchronize access to eeh_pe.

Signed-off-by: Sam Bobroff <sbobroff at linux.ibm.com>
---
 arch/powerpc/kernel/eeh_pe.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/arch/powerpc/kernel/eeh_pe.c b/arch/powerpc/kernel/eeh_pe.c
index 0486d3c6ff20..e89a30de2e7e 100644
--- a/arch/powerpc/kernel/eeh_pe.c
+++ b/arch/powerpc/kernel/eeh_pe.c
@@ -269,20 +269,27 @@ int eeh_wait_state(struct eeh_pe *pe, int max_wait)
  * The overall PEs form hierarchy tree. The first layer of the
  * hierarchy tree is composed of PHB PEs. The function is used
  * to retrieve the corresponding PHB PE according to the given PHB.
+ * Returns a referenced PE.
  */
 struct eeh_pe *eeh_phb_pe_get(struct pci_controller *phb)
 {
 	struct eeh_pe *pe;
+	unsigned long flags;
 
+	eeh_lock_pes(&flags);
 	list_for_each_entry(pe, &eeh_phb_pe, child) {
 		/*
 		 * Actually, we needn't check the type since
 		 * the PE for PHB has been determined when that
 		 * was created.
 		 */
-		if ((pe->type & EEH_PE_PHB) && pe->phb == phb)
-			return pe;
+		if ((pe->type & EEH_PE_PHB) && pe->phb == phb) {
+			eeh_get_pe(pe); /* Acquire ref */
+			eeh_unlock_pes(flags);
+			return pe; /* Give ref */
+		}
 	}
+	eeh_unlock_pes(flags);
 
 	return NULL;
 }
-- 
2.22.0.216.g00a2a96fc9



More information about the Linuxppc-dev mailing list