From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) (using TLSv1 with cipher CAMELLIA256-SHA (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 07BB21A1E6D for ; Sun, 28 Aug 2016 19:42:46 -0700 (PDT) Received: from orsmga001.jf.intel.com ([10.7.209.18]) by orsmga103.jf.intel.com with ESMTP; 28 Aug 2016 19:42:46 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.28,594,1464678000"; d="scan'208";a="1021563583" Received: from shwdeopenpsi014.ccr.corp.intel.com ([10.239.9.34]) by orsmga001.jf.intel.com with ESMTP; 28 Aug 2016 19:42:45 -0700 From: Hao Wu To: edk2-devel@lists.01.org, feng.tian@intel.com Cc: Hao Wu Date: Mon, 29 Aug 2016 10:42:23 +0800 Message-Id: <1472438547-9368-4-git-send-email-hao.a.wu@intel.com> X-Mailer: git-send-email 1.9.5.msysgit.0 In-Reply-To: <1472438547-9368-1-git-send-email-hao.a.wu@intel.com> References: <1472438547-9368-1-git-send-email-hao.a.wu@intel.com> Subject: [PATCH 3/7] MdeModulePkg NvmExpressDxe: Refine GetNameSpace API to follow spec X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 29 Aug 2016 02:42:46 -0000 According to the UEFI spec, EFI_NVM_EXPRESS_PASS_THRU_PROTOCOL.GetNamespace() should return EFI_NOT_FOUND when the input DevicePath is a device path node type that the NVM Express Pass Thru driver supports, but there is not a valid translation from DevicePath to a namespace ID. Current code will return EFI_SUCCESS. This commit adds additional check in the GetNameSpace API to make sure correct status is returned. Cc: Feng Tian Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Hao Wu --- MdeModulePkg/Bus/Pci/NvmExpressDxe/NvmExpressPassthru.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/MdeModulePkg/Bus/Pci/NvmExpressDxe/NvmExpressPassthru.c b/MdeModulePkg/Bus/Pci/NvmExpressDxe/NvmExpressPassthru.c index ccff4f6..f0d2f5a 100644 --- a/MdeModulePkg/Bus/Pci/NvmExpressDxe/NvmExpressPassthru.c +++ b/MdeModulePkg/Bus/Pci/NvmExpressDxe/NvmExpressPassthru.c @@ -820,6 +820,7 @@ NvmExpressGetNamespace ( ) { NVME_NAMESPACE_DEVICE_PATH *Node; + NVME_CONTROLLER_PRIVATE_DATA *Private; if ((This == NULL) || (DevicePath == NULL) || (NamespaceId == NULL)) { return EFI_INVALID_PARAMETER; @@ -829,13 +830,22 @@ NvmExpressGetNamespace ( return EFI_UNSUPPORTED; } - Node = (NVME_NAMESPACE_DEVICE_PATH *)DevicePath; + Node = (NVME_NAMESPACE_DEVICE_PATH *)DevicePath; + Private = NVME_CONTROLLER_PRIVATE_DATA_FROM_PASS_THRU (This); if (DevicePath->SubType == MSG_NVME_NAMESPACE_DP) { if (DevicePathNodeLength(DevicePath) != sizeof(NVME_NAMESPACE_DEVICE_PATH)) { return EFI_NOT_FOUND; } + // + // Check NamespaceId in the device path node is valid or not. + // + if ((Node->NamespaceId == 0) || + (Node->NamespaceId > Private->ControllerData->Nn)) { + return EFI_NOT_FOUND; + } + *NamespaceId = Node->NamespaceId; return EFI_SUCCESS; -- 1.9.5.msysgit.0