summaryrefslogtreecommitdiffstats
path: root/MdeModulePkg
diff options
context:
space:
mode:
authorRanbir Singh <Ranbir.Singh3@Dell.com>2023-07-03 19:44:24 +0800
committermergify[bot] <37929162+mergify[bot]@users.noreply.github.com>2023-07-17 02:19:45 +0000
commitdd49d448b0815c65847241a3faa957e3b4605001 (patch)
tree049ea9dd275a1fb975dd8604bcc215b972642602 /MdeModulePkg
parentf220dcbba86bfc1222180c61bbd31dd6023433db (diff)
downloadedk2-dd49d448b0815c65847241a3faa957e3b4605001.tar.gz
edk2-dd49d448b0815c65847241a3faa957e3b4605001.tar.bz2
edk2-dd49d448b0815c65847241a3faa957e3b4605001.zip
MdeModulePkg/Bus/Pci/EhciDxe: Fix FORWARD_NULL Coverity issues
The function UsbHcGetPciAddressForHostMem has ASSERT ((Block != NULL)); and the UsbHcFreeMem has ASSERT (Block != NULL); statement after for loop, but these are applicable only in DEBUG mode. In RELEASE mode, if for whatever reasons there is no match inside the for loop and the loop exits because of Block != NULL; condition, then there is no "Block" NULL pointer check afterwards and the code proceeds to do dereferencing "Block" which will lead to CRASH. Hence, for safety add NULL pointer checks always. Cc: Hao A Wu <hao.a.wu@intel.com> Cc: Ray Ni <ray.ni@intel.com> REF: https://bugzilla.tianocore.org/show_bug.cgi?id=4210 Signed-off-by: Ranbir Singh <Ranbir.Singh3@Dell.com> Signed-off-by: Ranbir Singh <rsingh@ventanamicro.com> Reviewed-by: Hao A Wu <hao.a.wu@intel.com>
Diffstat (limited to 'MdeModulePkg')
-rw-r--r--MdeModulePkg/Bus/Pci/EhciDxe/UsbHcMem.c9
1 files changed, 9 insertions, 0 deletions
diff --git a/MdeModulePkg/Bus/Pci/EhciDxe/UsbHcMem.c b/MdeModulePkg/Bus/Pci/EhciDxe/UsbHcMem.c
index 0a3ceb9f71..79575b6f63 100644
--- a/MdeModulePkg/Bus/Pci/EhciDxe/UsbHcMem.c
+++ b/MdeModulePkg/Bus/Pci/EhciDxe/UsbHcMem.c
@@ -250,6 +250,11 @@ UsbHcGetPciAddressForHostMem (
}
ASSERT ((Block != NULL));
+
+ if (Block == NULL) {
+ return 0;
+ }
+
//
// calculate the pci memory address for host memory address.
//
@@ -536,6 +541,10 @@ UsbHcFreeMem (
//
ASSERT (Block != NULL);
+ if (Block == NULL) {
+ return;
+ }
+
//
// Release the current memory block if it is empty and not the head
//