]> git.proxmox.com Git - mirror_edk2.git/commitdiff
MdeModulePkg/NvmExpressPei: Refine data buffer & len check in PassThru
authorHao Wu <hao.a.wu@intel.com>
Fri, 9 Nov 2018 07:14:08 +0000 (15:14 +0800)
committerHao Wu <hao.a.wu@intel.com>
Tue, 13 Nov 2018 12:54:44 +0000 (20:54 +0800)
REF:https://bugzilla.tianocore.org/show_bug.cgi?id=1142

The fix is similar to commit ebb6c7633bca47fcd5b460a67e18e4a717ea91cc.
We found that a similar fix should be applied to the NVMe PEI driver as
well. Hence, this one is for the PEI counterpart driver.

According to the the NVM Express spec Revision 1.1, for some commands
(like Get/Set Feature Command, Figure 89 & 90 of the spec), the Memory
Buffer maybe optional although the command opcode indicates there is a
data transfer between host & controller (Get/Set Feature Command, Figure
38 of the spec).

Hence, this commit refine the checks for the 'TransferLength' and
'TransferBuffer' field of the
EDKII_PEI_NVM_EXPRESS_PASS_THRU_COMMAND_PACKET structure to address this
issue.

Cc: Andrew Fish <afish@apple.com>
Cc: Leif Lindholm <leif.lindholm@linaro.org>
Cc: Michael D Kinney <michael.d.kinney@intel.com>
Cc: Liming Gao <liming.gao@intel.com>
Cc: Ruiyu Ni <ruiyu.ni@intel.com>
Cc: Jiewen Yao <Jiewen.yao@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Hao Wu <hao.a.wu@intel.com>
Acked-by: Laszlo Ersek <lersek@redhat.com>
Reviewed-by: Star Zeng <star.zeng@intel.com>
Reviewed-by: Philippe Mathieu-Daude <philmd@redhat.com>
MdeModulePkg/Bus/Pci/NvmExpressPei/NvmExpressPeiPassThru.c

index 81ad01b7eeca720cb607f432e2ed1d0c129eb449..ddcfe039981f7a82ff92051f82db510ac6cca5b3 100644 (file)
@@ -442,7 +442,8 @@ NvmePassThru (
   // specific addresses.\r
   //\r
   if ((Sq->Opc & (BIT0 | BIT1)) != 0) {\r
-    if ((Packet->TransferLength == 0) || (Packet->TransferBuffer == NULL)) {\r
+    if (((Packet->TransferLength != 0) && (Packet->TransferBuffer == NULL)) ||\r
+        ((Packet->TransferLength == 0) && (Packet->TransferBuffer != NULL))) {\r
       return EFI_INVALID_PARAMETER;\r
     }\r
 \r
@@ -468,21 +469,23 @@ NvmePassThru (
         MapOp = EdkiiIoMmuOperationBusMasterWrite;\r
       }\r
 \r
-      MapLength = Packet->TransferLength;\r
-      Status = IoMmuMap (\r
-                 MapOp,\r
-                 Packet->TransferBuffer,\r
-                 &MapLength,\r
-                 &PhyAddr,\r
-                 &MapData\r
-                 );\r
-      if (EFI_ERROR (Status) || (MapLength != Packet->TransferLength)) {\r
-        Status = EFI_OUT_OF_RESOURCES;\r
-        DEBUG ((DEBUG_ERROR, "%a: Fail to map data buffer.\n", __FUNCTION__));\r
-        goto Exit;\r
-      }\r
+      if ((Packet->TransferLength != 0) && (Packet->TransferBuffer != NULL)) {\r
+        MapLength = Packet->TransferLength;\r
+        Status = IoMmuMap (\r
+                   MapOp,\r
+                   Packet->TransferBuffer,\r
+                   &MapLength,\r
+                   &PhyAddr,\r
+                   &MapData\r
+                   );\r
+        if (EFI_ERROR (Status) || (MapLength != Packet->TransferLength)) {\r
+          Status = EFI_OUT_OF_RESOURCES;\r
+          DEBUG ((DEBUG_ERROR, "%a: Fail to map data buffer.\n", __FUNCTION__));\r
+          goto Exit;\r
+        }\r
 \r
-      Sq->Prp[0] = PhyAddr;\r
+        Sq->Prp[0] = PhyAddr;\r
+      }\r
 \r
       if((Packet->MetadataLength != 0) && (Packet->MetadataBuffer != NULL)) {\r
         MapLength = Packet->MetadataLength;\r