]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Bus/Ata/AtaBusDxe/AtaBus.c
fix memory leak at AccessAtaDevice() of AtaBus.
[mirror_edk2.git] / MdeModulePkg / Bus / Ata / AtaBusDxe / AtaBus.c
index 12af44dee3d65fa0274d48201b6e313f305961f4..cb6ee7ae32caa1793f56bea328731e46a03b0a73 100644 (file)
@@ -153,8 +153,8 @@ ReleaseAtaResources (
   EFI_TPL           OldTpl;\r
 \r
   FreeUnicodeStringTable (AtaDevice->ControllerNameTable);\r
-  FreeAlignedBuffer (AtaDevice->Asb, sizeof (*AtaDevice->Asb));\r
-  FreeAlignedBuffer (AtaDevice->IdentifyData, sizeof (*AtaDevice->IdentifyData));\r
+  FreeAlignedBuffer (AtaDevice->Asb, sizeof (EFI_ATA_STATUS_BLOCK));\r
+  FreeAlignedBuffer (AtaDevice->IdentifyData, sizeof (ATA_IDENTIFY_DATA));\r
   if (AtaDevice->DevicePath != NULL) {\r
     FreePool (AtaDevice->DevicePath);\r
   }\r
@@ -163,7 +163,7 @@ ReleaseAtaResources (
     //\r
     // Free the Subtask list.\r
     //\r
-    for(Entry = (&AtaDevice->AtaTaskList)->ForwardLink; \r
+    for(Entry = AtaDevice->AtaTaskList.ForwardLink; \r
         Entry != (&AtaDevice->AtaTaskList);\r
        ) {\r
       DelEntry = Entry;\r
@@ -243,7 +243,7 @@ RegisterAtaDevice (
   //\r
   // Allocate ATA device from the template.\r
   //\r
-  AtaDevice = AllocateCopyPool (sizeof (gAtaDeviceTemplate), &gAtaDeviceTemplate);\r
+  AtaDevice = AllocateCopyPool (sizeof (ATA_DEVICE), &gAtaDeviceTemplate);\r
   if (AtaDevice == NULL) {\r
     Status = EFI_OUT_OF_RESOURCES;\r
     goto Done;\r
@@ -258,12 +258,12 @@ RegisterAtaDevice (
   AtaDevice->DevicePath         = DevicePath;\r
   AtaDevice->Port               = Port;\r
   AtaDevice->PortMultiplierPort = PortMultiplierPort;\r
-  AtaDevice->Asb = AllocateAlignedBuffer (AtaDevice, sizeof (*AtaDevice->Asb));\r
+  AtaDevice->Asb = AllocateAlignedBuffer (AtaDevice, sizeof (EFI_ATA_STATUS_BLOCK));\r
   if (AtaDevice->Asb == NULL) {\r
     Status = EFI_OUT_OF_RESOURCES;\r
     goto Done;\r
   }\r
-  AtaDevice->IdentifyData = AllocateAlignedBuffer (AtaDevice, sizeof (*AtaDevice->IdentifyData));\r
+  AtaDevice->IdentifyData = AllocateAlignedBuffer (AtaDevice, sizeof (ATA_IDENTIFY_DATA));\r
   if (AtaDevice->IdentifyData == NULL) {\r
     Status = EFI_OUT_OF_RESOURCES;\r
     goto Done;\r
@@ -501,7 +501,7 @@ UnregisterAtaDevice (
         Handle,\r
         EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER\r
         );\r
-    return Status;\r
+      return Status;\r
     }\r
   }\r
 \r
@@ -1239,7 +1239,7 @@ AtaBlockIoFlushBlocksEx (
   )\r
 {\r
   //\r
-  // Signla event and return directly.\r
+  // Signal event and return directly.\r
   //\r
   if (Token != NULL && Token->Event != NULL) {\r
     Token->TransactionStatus = EFI_SUCCESS;\r
@@ -1307,11 +1307,11 @@ AtaDiskInfoIdentify (
   AtaDevice = ATA_DEVICE_FROM_DISK_INFO (This);\r
 \r
   Status = EFI_BUFFER_TOO_SMALL;\r
-  if (*IdentifyDataSize >= sizeof (*AtaDevice->IdentifyData)) {\r
+  if (*IdentifyDataSize >= sizeof (ATA_IDENTIFY_DATA)) {\r
     Status = EFI_SUCCESS;\r
-    CopyMem (IdentifyData, AtaDevice->IdentifyData, sizeof (*AtaDevice->IdentifyData));\r
+    CopyMem (IdentifyData, AtaDevice->IdentifyData, sizeof (ATA_IDENTIFY_DATA));\r
   }\r
-  *IdentifyDataSize = sizeof (*AtaDevice->IdentifyData);\r
+  *IdentifyDataSize = sizeof (ATA_IDENTIFY_DATA);\r
 \r
   return Status;\r
 }\r
@@ -1462,6 +1462,7 @@ AtaStorageSecurityReceiveData (
 {\r
   EFI_STATUS                       Status;\r
   ATA_DEVICE                       *Private;\r
+  EFI_TPL                          OldTpl;\r
 \r
   DEBUG ((EFI_D_INFO, "EFI Storage Security Protocol - Read"));\r
   if ((PayloadBuffer == NULL || PayloadTransferSize == NULL) && PayloadBufferSize != 0) {\r
@@ -1479,6 +1480,8 @@ AtaStorageSecurityReceiveData (
     return EFI_NO_MEDIA;\r
   }\r
 \r
+  OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r
+\r
   Status = TrustTransferAtaDevice (\r
              Private,\r
              PayloadBuffer,\r
@@ -1490,6 +1493,7 @@ AtaStorageSecurityReceiveData (
              PayloadTransferSize\r
              );\r
 \r
+  gBS->RestoreTPL (OldTpl);\r
   return Status;\r
 }\r
 \r
@@ -1568,6 +1572,7 @@ AtaStorageSecuritySendData (
 {\r
   EFI_STATUS                       Status;\r
   ATA_DEVICE                       *Private;\r
+  EFI_TPL                          OldTpl;\r
 \r
   DEBUG ((EFI_D_INFO, "EFI Storage Security Protocol - Send"));\r
   if ((PayloadBuffer == NULL) && (PayloadBufferSize != 0)) {\r
@@ -1581,6 +1586,7 @@ AtaStorageSecuritySendData (
     return EFI_MEDIA_CHANGED;\r
   }\r
 \r
+  OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r
   Status = TrustTransferAtaDevice (\r
              Private,\r
              PayloadBuffer,\r
@@ -1592,6 +1598,7 @@ AtaStorageSecuritySendData (
              NULL\r
              );\r
 \r
+  gBS->RestoreTPL (OldTpl);\r
   return Status;\r
 }\r
 \r