powerpc/eeh: Null check uses of eeh_pe_bus_get
[firefly-linux-kernel-4.4.55.git] / arch / powerpc / platforms / powernv / eeh-powernv.c
index e1c90725522a1a8bf263ed3b7bb0c25e1317518a..92736851c795afac23926700014a72ac0e6c44d1 100644 (file)
@@ -444,9 +444,12 @@ static void *pnv_eeh_probe(struct pci_dn *pdn, void *data)
         * PCI devices of the PE are expected to be removed prior
         * to PE reset.
         */
-       if (!edev->pe->bus)
+       if (!(edev->pe->state & EEH_PE_PRI_BUS)) {
                edev->pe->bus = pci_find_bus(hose->global_number,
                                             pdn->busno);
+               if (edev->pe->bus)
+                       edev->pe->state |= EEH_PE_PRI_BUS;
+       }
 
        /*
         * Enable EEH explicitly so that we will do EEH check
@@ -953,6 +956,11 @@ static int pnv_eeh_reset(struct eeh_pe *pe, int option)
                }
 
                bus = eeh_pe_bus_get(pe);
+               if (!bus) {
+                       pr_err("%s: Cannot find PCI bus for PHB#%d-PE#%x\n",
+                              __func__, pe->phb->global_number, pe->addr);
+                       return -EIO;
+               }
                if (pci_is_root_bus(bus) ||
                        pci_is_root_bus(bus->parent))
                        ret = pnv_eeh_root_reset(hose, option);
@@ -1160,7 +1168,7 @@ static void pnv_eeh_get_and_dump_hub_diag(struct pci_controller *hose)
                return;
        }
 
-       switch (data->type) {
+       switch (be16_to_cpu(data->type)) {
        case OPAL_P7IOC_DIAG_TYPE_RGC:
                pr_info("P7IOC diag-data for RGC\n\n");
                pnv_eeh_dump_hub_diag_common(data);
@@ -1392,7 +1400,7 @@ static int pnv_eeh_next_error(struct eeh_pe **pe)
 
                                /* Try best to clear it */
                                opal_pci_eeh_freeze_clear(phb->opal_id,
-                                       frozen_pe_no,
+                                       be64_to_cpu(frozen_pe_no),
                                        OPAL_EEH_ACTION_CLEAR_FREEZE_ALL);
                                ret = EEH_NEXT_ERR_NONE;
                        } else if ((*pe)->state & EEH_PE_ISOLATED ||