]> xenbits.xensource.com Git - people/aperard/ovmf.git/commitdiff
XhciDxe: Fail the start of malfunctioning XHCI controllers
authorRebecca Cran <rebecca@os.amperecomputing.com>
Fri, 2 Aug 2024 00:39:12 +0000 (18:39 -0600)
committermergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Thu, 5 Sep 2024 05:37:42 +0000 (05:37 +0000)
Add missing error checking for malfunctioning XHCI controllers.

Signed-off-by: Rebecca Cran <rebecca@os.amperecomputing.com>
MdeModulePkg/Bus/Pci/XhciDxe/Xhci.c
MdeModulePkg/Bus/Pci/XhciDxe/XhciReg.c
MdeModulePkg/Bus/Pci/XhciDxe/XhciSched.c

index cf6b32959e687800944ed9b1ba6e38c357b4b31e..a9d7e3616eb1c1059f089f7e1a8021f6d3eda104 100644 (file)
@@ -2077,7 +2077,12 @@ XhcDriverBindingStart (
 \r
   XhcSetBiosOwnership (Xhc);\r
 \r
-  XhcResetHC (Xhc, XHC_RESET_TIMEOUT);\r
+  Status = XhcResetHC (Xhc, XHC_RESET_TIMEOUT);\r
+  if (EFI_ERROR (Status)) {\r
+    DEBUG ((DEBUG_ERROR, "%a: failed to reset HC\n", __func__));\r
+    goto FREE_POOL;\r
+  }\r
+\r
   ASSERT (XhcIsHalt (Xhc));\r
 \r
   //\r
index 525942a167b0a19c313367d99dedb25f98f209f5..dc8228b429c7c8f4ebfc83ea9c4e19d384713c66 100644 (file)
@@ -29,6 +29,8 @@ XhcReadCapReg8 (
   UINT8       Data;\r
   EFI_STATUS  Status;\r
 \r
+  Data = 0;\r
+\r
   Status = Xhc->PciIo->Mem.Read (\r
                              Xhc->PciIo,\r
                              EfiPciIoWidthUint8,\r
index a97ed44dbfc33f2d22ef6952373647033899e4f0..3caa060f35642ec9a1129da7641c2751affa2e75 100644 (file)
@@ -2165,6 +2165,7 @@ XhcInitializeDeviceSlot (
   DEVICE_CONTEXT              *ParentDeviceContext;\r
   EFI_PHYSICAL_ADDRESS        PhyAddr;\r
 \r
+  EvtTrb = NULL;\r
   ZeroMem (&CmdTrb, sizeof (CMD_TRB_ENABLE_SLOT));\r
   CmdTrb.CycleBit = 1;\r
   CmdTrb.Type     = TRB_TYPE_EN_SLOT;\r
@@ -2175,7 +2176,7 @@ XhcInitializeDeviceSlot (
              XHC_GENERIC_TIMEOUT,\r
              (TRB_TEMPLATE **)(UINTN)&EvtTrb\r
              );\r
-  if (EFI_ERROR (Status)) {\r
+  if (EFI_ERROR (Status) || (EvtTrb == NULL)) {\r
     DEBUG ((DEBUG_ERROR, "XhcInitializeDeviceSlot: Enable Slot Failed, Status = %r\n", Status));\r
     return Status;\r
   }\r
@@ -2390,6 +2391,7 @@ XhcInitializeDeviceSlot64 (
   DEVICE_CONTEXT_64           *ParentDeviceContext;\r
   EFI_PHYSICAL_ADDRESS        PhyAddr;\r
 \r
+  EvtTrb = NULL;\r
   ZeroMem (&CmdTrb, sizeof (CMD_TRB_ENABLE_SLOT));\r
   CmdTrb.CycleBit = 1;\r
   CmdTrb.Type     = TRB_TYPE_EN_SLOT;\r
@@ -2400,7 +2402,7 @@ XhcInitializeDeviceSlot64 (
              XHC_GENERIC_TIMEOUT,\r
              (TRB_TEMPLATE **)(UINTN)&EvtTrb\r
              );\r
-  if (EFI_ERROR (Status)) {\r
+  if (EFI_ERROR (Status) || (EvtTrb == NULL)) {\r
     DEBUG ((DEBUG_ERROR, "XhcInitializeDeviceSlot64: Enable Slot Failed, Status = %r\n", Status));\r
     return Status;\r
   }\r
@@ -2602,6 +2604,8 @@ XhcDisableSlotCmd (
   UINT8                 Index;\r
   VOID                  *RingSeg;\r
 \r
+  EvtTrb = NULL;\r
+\r
   //\r
   // Disable the device slots occupied by these devices on its downstream ports.\r
   // Entry 0 is reserved.\r
@@ -2637,7 +2641,7 @@ XhcDisableSlotCmd (
                              XHC_GENERIC_TIMEOUT,\r
                              (TRB_TEMPLATE **)(UINTN)&EvtTrb\r
                              );\r
-  if (EFI_ERROR (Status)) {\r
+  if (EFI_ERROR (Status) || (EvtTrb == NULL)) {\r
     DEBUG ((DEBUG_ERROR, "XhcDisableSlotCmd: Disable Slot Command Failed, Status = %r\n", Status));\r
     return Status;\r
   }\r
@@ -2713,6 +2717,8 @@ XhcDisableSlotCmd64 (
   UINT8                 Index;\r
   VOID                  *RingSeg;\r
 \r
+  EvtTrb = NULL;\r
+\r
   //\r
   // Disable the device slots occupied by these devices on its downstream ports.\r
   // Entry 0 is reserved.\r
@@ -2748,7 +2754,7 @@ XhcDisableSlotCmd64 (
                              XHC_GENERIC_TIMEOUT,\r
                              (TRB_TEMPLATE **)(UINTN)&EvtTrb\r
                              );\r
-  if (EFI_ERROR (Status)) {\r
+  if (EFI_ERROR (Status) || (EvtTrb == NULL)) {\r
     DEBUG ((DEBUG_ERROR, "XhcDisableSlotCmd: Disable Slot Command Failed, Status = %r\n", Status));\r
     return Status;\r
   }\r
@@ -3240,6 +3246,8 @@ XhcSetConfigCmd (
   DEVICE_CONTEXT              *OutputContext;\r
   EVT_TRB_COMMAND_COMPLETION  *EvtTrb;\r
 \r
+  EvtTrb = NULL;\r
+\r
   //\r
   // 4.6.6 Configure Endpoint\r
   //\r
@@ -3290,7 +3298,7 @@ XhcSetConfigCmd (
              XHC_GENERIC_TIMEOUT,\r
              (TRB_TEMPLATE **)(UINTN)&EvtTrb\r
              );\r
-  if (EFI_ERROR (Status)) {\r
+  if (EFI_ERROR (Status) || (EvtTrb == NULL)) {\r
     DEBUG ((DEBUG_ERROR, "XhcSetConfigCmd: Config Endpoint Failed, Status = %r\n", Status));\r
   } else {\r
     Xhc->UsbDevContext[SlotId].ActiveConfiguration = ConfigDesc->ConfigurationValue;\r
@@ -3331,6 +3339,8 @@ XhcSetConfigCmd64 (
   DEVICE_CONTEXT_64           *OutputContext;\r
   EVT_TRB_COMMAND_COMPLETION  *EvtTrb;\r
 \r
+  EvtTrb = NULL;\r
+\r
   //\r
   // 4.6.6 Configure Endpoint\r
   //\r
@@ -3381,7 +3391,7 @@ XhcSetConfigCmd64 (
              XHC_GENERIC_TIMEOUT,\r
              (TRB_TEMPLATE **)(UINTN)&EvtTrb\r
              );\r
-  if (EFI_ERROR (Status)) {\r
+  if (EFI_ERROR (Status) || (EvtTrb == NULL)) {\r
     DEBUG ((DEBUG_ERROR, "XhcSetConfigCmd64: Config Endpoint Failed, Status = %r\n", Status));\r
   } else {\r
     Xhc->UsbDevContext[SlotId].ActiveConfiguration = ConfigDesc->ConfigurationValue;\r
@@ -3417,6 +3427,8 @@ XhcStopEndpoint (
 \r
   DEBUG ((DEBUG_VERBOSE, "XhcStopEndpoint: Slot = 0x%x, Dci = 0x%x\n", SlotId, Dci));\r
 \r
+  EvtTrb = NULL;\r
+\r
   //\r
   // When XhcCheckUrbResult waits for the Stop_Endpoint completion, it also checks\r
   // the PendingUrb completion status, because it's possible that the PendingUrb is\r
@@ -3454,7 +3466,7 @@ XhcStopEndpoint (
                             XHC_GENERIC_TIMEOUT,\r
                             (TRB_TEMPLATE **)(UINTN)&EvtTrb\r
                             );\r
-  if (EFI_ERROR (Status)) {\r
+  if (EFI_ERROR (Status) || (EvtTrb == NULL)) {\r
     DEBUG ((DEBUG_ERROR, "XhcStopEndpoint: Stop Endpoint Failed, Status = %r\n", Status));\r
   }\r
 \r
@@ -3488,6 +3500,8 @@ XhcResetEndpoint (
 \r
   DEBUG ((DEBUG_INFO, "XhcResetEndpoint: Slot = 0x%x, Dci = 0x%x\n", SlotId, Dci));\r
 \r
+  EvtTrb = NULL;\r
+\r
   //\r
   // Send stop endpoint command to transit Endpoint from running to stop state\r
   //\r
@@ -3502,7 +3516,7 @@ XhcResetEndpoint (
                              XHC_GENERIC_TIMEOUT,\r
                              (TRB_TEMPLATE **)(UINTN)&EvtTrb\r
                              );\r
-  if (EFI_ERROR (Status)) {\r
+  if (EFI_ERROR (Status) || (EvtTrb == NULL)) {\r
     DEBUG ((DEBUG_ERROR, "XhcResetEndpoint: Reset Endpoint Failed, Status = %r\n", Status));\r
   }\r
 \r
@@ -3538,6 +3552,8 @@ XhcSetTrDequeuePointer (
 \r
   DEBUG ((DEBUG_VERBOSE, "XhcSetTrDequeuePointer: Slot = 0x%x, Dci = 0x%x, Urb = 0x%x\n", SlotId, Dci, Urb));\r
 \r
+  EvtTrb = NULL;\r
+\r
   //\r
   // Send stop endpoint command to transit Endpoint from running to stop state\r
   //\r
@@ -3555,7 +3571,7 @@ XhcSetTrDequeuePointer (
                            XHC_GENERIC_TIMEOUT,\r
                            (TRB_TEMPLATE **)(UINTN)&EvtTrb\r
                            );\r
-  if (EFI_ERROR (Status)) {\r
+  if (EFI_ERROR (Status) || (EvtTrb == NULL)) {\r
     DEBUG ((DEBUG_ERROR, "XhcSetTrDequeuePointer: Set TR Dequeue Pointer Failed, Status = %r\n", Status));\r
   }\r
 \r
@@ -3604,6 +3620,7 @@ XhcSetInterface (
   EVT_TRB_COMMAND_COMPLETION  *EvtTrb;\r
 \r
   Status = EFI_SUCCESS;\r
+  EvtTrb = NULL;\r
 \r
   InputContext  = Xhc->UsbDevContext[SlotId].InputContext;\r
   OutputContext = Xhc->UsbDevContext[SlotId].OutputContext;\r
@@ -3755,7 +3772,7 @@ XhcSetInterface (
                XHC_GENERIC_TIMEOUT,\r
                (TRB_TEMPLATE **)(UINTN)&EvtTrb\r
                );\r
-    if (EFI_ERROR (Status)) {\r
+    if (EFI_ERROR (Status) || (EvtTrb == NULL)) {\r
       DEBUG ((DEBUG_ERROR, "SetInterface: Config Endpoint Failed, Status = %r\n", Status));\r
     } else {\r
       //\r
@@ -3810,6 +3827,7 @@ XhcSetInterface64 (
   EVT_TRB_COMMAND_COMPLETION  *EvtTrb;\r
 \r
   Status = EFI_SUCCESS;\r
+  EvtTrb = NULL;\r
 \r
   InputContext  = Xhc->UsbDevContext[SlotId].InputContext;\r
   OutputContext = Xhc->UsbDevContext[SlotId].OutputContext;\r
@@ -3961,7 +3979,7 @@ XhcSetInterface64 (
                XHC_GENERIC_TIMEOUT,\r
                (TRB_TEMPLATE **)(UINTN)&EvtTrb\r
                );\r
-    if (EFI_ERROR (Status)) {\r
+    if (EFI_ERROR (Status) || (EvtTrb == NULL)) {\r
       DEBUG ((DEBUG_ERROR, "SetInterface64: Config Endpoint Failed, Status = %r\n", Status));\r
     } else {\r
       //\r
@@ -4001,6 +4019,8 @@ XhcEvaluateContext (
 \r
   ASSERT (Xhc->UsbDevContext[SlotId].SlotId != 0);\r
 \r
+  EvtTrb = NULL;\r
+\r
   //\r
   // 4.6.7 Evaluate Context\r
   //\r
@@ -4028,7 +4048,7 @@ XhcEvaluateContext (
              XHC_GENERIC_TIMEOUT,\r
              (TRB_TEMPLATE **)(UINTN)&EvtTrb\r
              );\r
-  if (EFI_ERROR (Status)) {\r
+  if (EFI_ERROR (Status) || (EvtTrb == NULL)) {\r
     DEBUG ((DEBUG_ERROR, "XhcEvaluateContext: Evaluate Context Failed, Status = %r\n", Status));\r
   }\r
 \r
@@ -4062,6 +4082,8 @@ XhcEvaluateContext64 (
 \r
   ASSERT (Xhc->UsbDevContext[SlotId].SlotId != 0);\r
 \r
+  EvtTrb = NULL;\r
+\r
   //\r
   // 4.6.7 Evaluate Context\r
   //\r
@@ -4089,7 +4111,7 @@ XhcEvaluateContext64 (
              XHC_GENERIC_TIMEOUT,\r
              (TRB_TEMPLATE **)(UINTN)&EvtTrb\r
              );\r
-  if (EFI_ERROR (Status)) {\r
+  if (EFI_ERROR (Status) || (EvtTrb == NULL)) {\r
     DEBUG ((DEBUG_ERROR, "XhcEvaluateContext64: Evaluate Context Failed, Status = %r\n", Status));\r
   }\r
 \r
@@ -4125,6 +4147,7 @@ XhcConfigHubContext (
   EFI_PHYSICAL_ADDRESS        PhyAddr;\r
 \r
   ASSERT (Xhc->UsbDevContext[SlotId].SlotId != 0);\r
+  EvtTrb        = NULL;\r
   InputContext  = Xhc->UsbDevContext[SlotId].InputContext;\r
   OutputContext = Xhc->UsbDevContext[SlotId].OutputContext;\r
 \r
@@ -4158,7 +4181,7 @@ XhcConfigHubContext (
              XHC_GENERIC_TIMEOUT,\r
              (TRB_TEMPLATE **)(UINTN)&EvtTrb\r
              );\r
-  if (EFI_ERROR (Status)) {\r
+  if (EFI_ERROR (Status) || (EvtTrb == NULL)) {\r
     DEBUG ((DEBUG_ERROR, "XhcConfigHubContext: Config Endpoint Failed, Status = %r\n", Status));\r
   }\r
 \r