]> git.proxmox.com Git - mirror_edk2.git/commitdiff
DuetPkg: SataControllerDxe: fix private array subscripting
authorLaszlo Ersek <lersek@redhat.com>
Tue, 22 Sep 2015 11:18:13 +0000 (11:18 +0000)
committerlersek <lersek@Edk2>
Tue, 22 Sep 2015 11:18:13 +0000 (11:18 +0000)
Each one of the DisqualifiedModes, IdentifyData and IdentifyValid arrays
in the EFI_SATA_CONTROLLER_PRIVATE_DATA structure is a matrix, represented
as a flat array.

The code currently uses the incorrect formula

  Channel * Device

to index them. The right formula is

  [Channel][Device]

which can be implemented as

  Channel * NumDevicePerChannel + Device

Add a helper function that does this, and replace the incorrect
subscripts.

Cc: Alexander Graf <agraf@suse.de>
Cc: Reza Jelveh <reza.jelveh@tuhh.de>
Cc: Jordan Justen <jordan.l.justen@intel.com>
Cc: Ruiyu Ni <ruiyu.ni@intel.com>
Cc: Hannes Reinecke <hare@suse.de>
Cc: Gabriel L. Somlo <somlo@cmu.edu>
Cc: Feng Tian <feng.tian@intel.com>
Reported-by: Feng Tian <feng.tian@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Laszlo Ersek <lersek@redhat.com>
Reviewed-by: Feng Tian <feng.tian@intel.com>
Tested-by: Gabriel Somlo <somlo@cmu.edu>
Reviewed-by: Jordan Justen <jordan.l.justen@intel.com>
git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@18525 6f19259b-4bc3-4df7-8a09-765794883524

DuetPkg/SataControllerDxe/SataController.c

index e78915ad31652a7145db3b51e32be9ef4782f3c3..e5d10e234e88c3135892b9b400c5db409e4f4504 100644 (file)
@@ -600,6 +600,37 @@ SataControllerStop (
                 );\r
 }\r
 \r
+/**\r
+  Calculate the flat array subscript of a (Channel, Device) pair.\r
+\r
+  @param[in] SataPrivateData  The private data structure corresponding to the\r
+                              SATA controller that attaches the device for\r
+                              which the flat array subscript is being\r
+                              calculated.\r
+\r
+  @param[in] Channel          The channel (ie. port) number on the SATA\r
+                              controller that the device is attached to.\r
+\r
+  @param[in] Device           The device number on the channel.\r
+\r
+  @return  The flat array subscript suitable for indexing DisqualifiedModes,\r
+           IdentifyData, and IdentifyValid.\r
+**/\r
+STATIC\r
+UINTN\r
+FlatDeviceIndex (\r
+  IN CONST EFI_SATA_CONTROLLER_PRIVATE_DATA  *SataPrivateData,\r
+  IN UINTN                                   Channel,\r
+  IN UINTN                                   Device\r
+  )\r
+{\r
+  ASSERT (SataPrivateData != NULL);\r
+  ASSERT (Channel < SataPrivateData->IdeInit.ChannelCount);\r
+  ASSERT (Device < SataPrivateData->DeviceCount);\r
+\r
+  return Channel * SataPrivateData->DeviceCount + Device;\r
+}\r
+\r
 //\r
 // Interface functions of IDE_CONTROLLER_INIT protocol\r
 //\r
@@ -746,6 +777,8 @@ IdeInitSubmitData (
   )\r
 {\r
   EFI_SATA_CONTROLLER_PRIVATE_DATA  *SataPrivateData;\r
+  UINTN                             DeviceIndex;\r
+\r
   SataPrivateData = SATA_CONTROLLER_PRIVATE_DATA_FROM_THIS (This);\r
   ASSERT (SataPrivateData != NULL);\r
 \r
@@ -753,19 +786,21 @@ IdeInitSubmitData (
     return EFI_INVALID_PARAMETER;\r
   }\r
 \r
+  DeviceIndex = FlatDeviceIndex (SataPrivateData, Channel, Device);\r
+\r
   //\r
   // Make a local copy of device's IdentifyData and mark the valid flag\r
   //\r
   if (IdentifyData != NULL) {\r
     CopyMem (\r
-      &(SataPrivateData->IdentifyData[Channel * Device]),\r
+      &(SataPrivateData->IdentifyData[DeviceIndex]),\r
       IdentifyData,\r
       sizeof (EFI_IDENTIFY_DATA)\r
       );\r
 \r
-    SataPrivateData->IdentifyValid[Channel * Device] = TRUE;\r
+    SataPrivateData->IdentifyValid[DeviceIndex] = TRUE;\r
   } else {\r
-    SataPrivateData->IdentifyValid[Channel * Device] = FALSE;\r
+    SataPrivateData->IdentifyValid[DeviceIndex] = FALSE;\r
   }\r
 \r
   return EFI_SUCCESS;\r
@@ -821,6 +856,8 @@ IdeInitDisqualifyMode (
   )\r
 {\r
   EFI_SATA_CONTROLLER_PRIVATE_DATA  *SataPrivateData;\r
+  UINTN                             DeviceIndex;\r
+\r
   SataPrivateData = SATA_CONTROLLER_PRIVATE_DATA_FROM_THIS (This);\r
   ASSERT (SataPrivateData != NULL);\r
 \r
@@ -828,12 +865,14 @@ IdeInitDisqualifyMode (
     return EFI_INVALID_PARAMETER;\r
   }\r
 \r
+  DeviceIndex = FlatDeviceIndex (SataPrivateData, Channel, Device);\r
+\r
   //\r
   // Record the disqualified modes per channel per device. From ATA/ATAPI spec,\r
   // if a mode is not supported, the modes higher than it is also not supported.\r
   //\r
   CopyMem (\r
-    &(SataPrivateData->DisqualifiedModes[Channel * Device]),\r
+    &(SataPrivateData->DisqualifiedModes[DeviceIndex]),\r
     BadModes,\r
     sizeof (EFI_ATA_COLLECTIVE_MODE)\r
     );\r
@@ -910,6 +949,7 @@ IdeInitCalculateMode (
   EFI_ATA_COLLECTIVE_MODE           *DisqualifiedModes;\r
   UINT16                            SelectedMode;\r
   EFI_STATUS                        Status;\r
+  UINTN                             DeviceIndex;\r
 \r
   SataPrivateData = SATA_CONTROLLER_PRIVATE_DATA_FROM_THIS (This);\r
   ASSERT (SataPrivateData != NULL);\r
@@ -924,9 +964,11 @@ IdeInitCalculateMode (
     return EFI_OUT_OF_RESOURCES;\r
   }\r
 \r
-  IdentifyData = &(SataPrivateData->IdentifyData[Channel * Device]);\r
-  IdentifyValid = SataPrivateData->IdentifyValid[Channel * Device];\r
-  DisqualifiedModes = &(SataPrivateData->DisqualifiedModes[Channel * Device]);\r
+  DeviceIndex = FlatDeviceIndex (SataPrivateData, Channel, Device);\r
+\r
+  IdentifyData = &(SataPrivateData->IdentifyData[DeviceIndex]);\r
+  IdentifyValid = SataPrivateData->IdentifyValid[DeviceIndex];\r
+  DisqualifiedModes = &(SataPrivateData->DisqualifiedModes[DeviceIndex]);\r
 \r
   //\r
   // Make sure we've got the valid identify data of the device from SubmitData()\r