From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pf1-f194.google.com (mail-pf1-f194.google.com [209.85.210.194]) by mx.groups.io with SMTP id smtpd.web11.9904.1686744275557841276 for ; Wed, 14 Jun 2023 05:04:35 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@ventanamicro.com header.s=google header.b=ci0D0WJm; spf=pass (domain: ventanamicro.com, ip: 209.85.210.194, mailfrom: rsingh@ventanamicro.com) Received: by mail-pf1-f194.google.com with SMTP id d2e1a72fcca58-66615629689so956385b3a.2 for ; Wed, 14 Jun 2023 05:04:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1686744275; x=1689336275; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=EQKrGJh4xik5KV1cfy4cIExLj0ih08woRe4xPyDcQ+w=; b=ci0D0WJmedynQa/AWJFkH4MirdCHOthBgXzmzXyYSM5Jwysb3VqQVln1E1t+PDsmhE m0i8fMuRzL/4Mzjsgr3YsjAKEZY0ZVJZGlG7nrgJ6+YkDWRI8Vm71M62HT+UZ1btYCZc JAtlerSCxf+N7PdBJzTIBlvnE07yVFj/Vqvq5ij4b7Jy7hSwiClEltLG9n4pRC5O/Md2 Z0oLtsnHJBMSBTHrXvvYNAAVxF9iW5623U+EDXMtMalR86HzIaj3g5rDF8wit6st9ZA4 RMo+fdR+TX0jvshOz/sfLMzQduKKcVqlXSJrk6DiTcv8XBT9IfscaIYM8NPIUhdSpEXZ aN9w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686744275; x=1689336275; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=EQKrGJh4xik5KV1cfy4cIExLj0ih08woRe4xPyDcQ+w=; b=ba6NESVDhTdlFtZi0x1Og8fr/asoG00k0ua0CCEugACyg99jtUAEqDOlbuAI0JZzHp 547pFacZl1BSyaMIOTyk+ie8WzUMpJ1xr2hI/jOmGWu98RWeyJ/IOb1su9qfEa1AlHLK VBkiJHGKCV6xDdbghNGJD1YKjWqABwiH8qV3lQz++PMJXePdJpZv1EbmkLvSIczRVK+Q JFeKuYnLuSiWFXWj1Dh0ZkRAtKSUIXi4mVYKOLzuZyDllseTTYXUXcPCgeoLyIeL7yK8 7ZiLPD225h5JmIvsHZ5wF7YH0fQk1wCVnnlEgrCkEaK15f2kuReJ6sEuFLU0rEvmkSZm YjLw== X-Gm-Message-State: AC+VfDzz4GDh/sai3Yzbucv7Hf594wGGF/U+kyPHC4qz9VbkYFT4Wrmv bvSekhKMbBHyoWq8+jjO9101wgzYJ7NbRW2LIo1OpwZd X-Google-Smtp-Source: ACHHUZ7/X69oQyCXqMV/N2QNUdT4zg/Burej0qDwmc/mf83E/SrtWZBUPuuP3FainJAHcbzr9T4y6A== X-Received: by 2002:a05:6a00:985:b0:658:f86f:b18e with SMTP id u5-20020a056a00098500b00658f86fb18emr2270678pfg.22.1686744274810; Wed, 14 Jun 2023 05:04:34 -0700 (PDT) Return-Path: Received: from user-Latitude-5420.. ([2401:4900:1f24:5b04:55c0:e0ac:a219:b82b]) by smtp.gmail.com with ESMTPSA id g12-20020a62e30c000000b0065438394fa4sm10560284pfh.90.2023.06.14.05.04.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Jun 2023 05:04:34 -0700 (PDT) From: Ranbir Singh To: devel@edk2.groups.io, rsingh@ventanamicro.com Cc: Hao A Wu , Ray Ni Subject: [PATCH v1 1/1] MdeModulePkg/Bus/Pci/EhciDxe: Fix FORWARD_NULL Coverity issues Date: Wed, 14 Jun 2023 17:34:30 +0530 Message-Id: <20230614120430.146450-1-rsingh@ventanamicro.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Ranbir Singh The function UsbHcGetPciAddressForHostMem has ASSERT ((Block !=3D NULL)); and the UsbHcFreeMem has ASSERT (Block !=3D 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 for loop and the loop exits because of Block !=3D 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 Cc: Ray Ni REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3D4210 Signed-off-by: Ranbir Singh Signed-off-by: Ranbir Singh --- MdeModulePkg/Bus/Pci/EhciDxe/UsbHcMem.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/MdeModulePkg/Bus/Pci/EhciDxe/UsbHcMem.c b/MdeModulePkg/Bus/Pci= /EhciDxe/UsbHcMem.c index 0a3ceb9f711a..623cca0d7eb3 100644 --- a/MdeModulePkg/Bus/Pci/EhciDxe/UsbHcMem.c +++ b/MdeModulePkg/Bus/Pci/EhciDxe/UsbHcMem.c @@ -250,6 +250,12 @@ UsbHcGetPciAddressForHostMem ( }=0D =0D ASSERT ((Block !=3D NULL));=0D +=0D + if (Block =3D=3D NULL) {=0D + DEBUG ((DEBUG_INFO, "Given memory block not present in host controller= 's pool\n"));=0D + return 0;=0D + }=0D +=0D //=0D // calculate the pci memory address for host memory address.=0D //=0D @@ -536,6 +542,11 @@ UsbHcFreeMem ( //=0D ASSERT (Block !=3D NULL);=0D =0D + if (Block =3D=3D NULL) {=0D + DEBUG ((DEBUG_INFO, "Memory to free not present in host controller's p= ool\n"));=0D + return;=0D + }=0D +=0D //=0D // Release the current memory block if it is empty and not the head=0D //=0D --=20 2.34.1