]> git.proxmox.com Git - mirror_edk2.git/commitdiff
MdeModulePkg NvmExpressDxe: Refine GetNameSpace API to follow spec
authorHao Wu <hao.a.wu@intel.com>
Fri, 19 Aug 2016 03:18:42 +0000 (11:18 +0800)
committerHao Wu <hao.a.wu@intel.com>
Tue, 6 Sep 2016 07:31:23 +0000 (15:31 +0800)
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 <feng.tian@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Hao Wu <hao.a.wu@intel.com>
Reviewed-by: Feng Tian <feng.tian@intel.com>
MdeModulePkg/Bus/Pci/NvmExpressDxe/NvmExpressPassthru.c

index ccff4f61d9ffc444bdeb87a36a962beca4e78aab..f0d2f5a83bd37fb20e70c09e17c8e7d0ad0e204e 100644 (file)
@@ -820,6 +820,7 @@ NvmExpressGetNamespace (
   )\r
 {\r
   NVME_NAMESPACE_DEVICE_PATH       *Node;\r
+  NVME_CONTROLLER_PRIVATE_DATA     *Private;\r
 \r
   if ((This == NULL) || (DevicePath == NULL) || (NamespaceId == NULL)) {\r
     return EFI_INVALID_PARAMETER;\r
@@ -829,13 +830,22 @@ NvmExpressGetNamespace (
     return EFI_UNSUPPORTED;\r
   }\r
 \r
-  Node = (NVME_NAMESPACE_DEVICE_PATH *)DevicePath;\r
+  Node    = (NVME_NAMESPACE_DEVICE_PATH *)DevicePath;\r
+  Private = NVME_CONTROLLER_PRIVATE_DATA_FROM_PASS_THRU (This);\r
 \r
   if (DevicePath->SubType == MSG_NVME_NAMESPACE_DP) {\r
     if (DevicePathNodeLength(DevicePath) != sizeof(NVME_NAMESPACE_DEVICE_PATH)) {\r
       return EFI_NOT_FOUND;\r
     }\r
 \r
+    //\r
+    // Check NamespaceId in the device path node is valid or not.\r
+    //\r
+    if ((Node->NamespaceId == 0) ||\r
+      (Node->NamespaceId > Private->ControllerData->Nn)) {\r
+      return EFI_NOT_FOUND;\r
+    }\r
+\r
     *NamespaceId = Node->NamespaceId;\r
 \r
     return EFI_SUCCESS;\r