]> git.proxmox.com Git - mirror_edk2.git/commitdiff
MdeModulePkg/XhciPei: Unlinked XhciPei memory block
authorAbner Chang <abner.chang@amd.com>
Wed, 11 Jan 2023 03:10:08 +0000 (11:10 +0800)
committermergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Mon, 16 Jan 2023 02:34:53 +0000 (02:34 +0000)
Unlink the XhciPei memory block when it has been freed.

Signed-off-by: Jiangang He <jiangang.he@amd.com>
Cc: Hao A Wu <hao.a.wu@intel.com>
Cc: Ray Ni <ray.ni@intel.com>
Cc: Garrett Kirkendall <garrett.kirkendall@amd.com>
Cc: Abner Chang <abner.chang@amd.com>
Cc: Kuei-Hung Lin <Kuei-Hung.Lin@amd.com>
Reviewed-by: Hao A Wu <hao.a.wu@intel.com>
MdeModulePkg/Bus/Pci/XhciPei/UsbHcMem.c

index c64b38fcfc89be6a4dd4607ac77680f05bd491bc..e779a311388c400416ab70332c9a3bede855e9ae 100644 (file)
@@ -3,6 +3,7 @@ PEIM to produce gPeiUsb2HostControllerPpiGuid based on gPeiUsbControllerPpiGuid
 which is used to enable recovery function from USB Drivers.\r
 \r
 Copyright (c) 2014 - 2016, Intel Corporation. All rights reserved.<BR>\r
+Copyright (C) 2022 Advanced Micro Devices, Inc. All rights reserved.<BR>\r
 \r
 SPDX-License-Identifier: BSD-2-Clause-Patent\r
 \r
@@ -365,6 +366,32 @@ UsbHcInitMemPool (
   return Pool;\r
 }\r
 \r
+/**\r
+  Unlink the memory block from the pool's list.\r
+\r
+  @param  Head           The block list head of the memory's pool.\r
+  @param  BlockToUnlink  The memory block to unlink.\r
+\r
+**/\r
+VOID\r
+UsbHcUnlinkMemBlock (\r
+  IN USBHC_MEM_BLOCK  *Head,\r
+  IN USBHC_MEM_BLOCK  *BlockToUnlink\r
+  )\r
+{\r
+  USBHC_MEM_BLOCK  *Block;\r
+\r
+  ASSERT ((Head != NULL) && (BlockToUnlink != NULL));\r
+\r
+  for (Block = Head; Block != NULL; Block = Block->Next) {\r
+    if (Block->Next == BlockToUnlink) {\r
+      Block->Next         = BlockToUnlink->Next;\r
+      BlockToUnlink->Next = NULL;\r
+      break;\r
+    }\r
+  }\r
+}\r
+\r
 /**\r
   Release the memory management pool.\r
 \r
@@ -386,7 +413,7 @@ UsbHcFreeMemPool (
   // first block.\r
   //\r
   for (Block = Pool->Head->Next; Block != NULL; Block = Pool->Head->Next) {\r
-    // UsbHcUnlinkMemBlock (Pool->Head, Block);\r
+    UsbHcUnlinkMemBlock (Pool->Head, Block);\r
     UsbHcFreeMemBlock (Pool, Block);\r
   }\r
 \r
@@ -532,7 +559,7 @@ UsbHcFreeMem (
   // Release the current memory block if it is empty and not the head\r
   //\r
   if ((Block != Head) && UsbHcIsMemBlockEmpty (Block)) {\r
-    // UsbHcUnlinkMemBlock (Head, Block);\r
+    UsbHcUnlinkMemBlock (Head, Block);\r
     UsbHcFreeMemBlock (Pool, Block);\r
   }\r
 }\r