]> git.proxmox.com Git - mirror_edk2.git/commitdiff
MdeModulePkg/UdfDxe: Use error handling when fail to return LSN
authorHao Wu <hao.a.wu@intel.com>
Sat, 29 Sep 2018 05:03:50 +0000 (13:03 +0800)
committerHao Wu <hao.a.wu@intel.com>
Thu, 18 Oct 2018 01:12:43 +0000 (09:12 +0800)
REF:https://bugzilla.tianocore.org/show_bug.cgi?id=1248

This commit will refine the ASSERTs in function GetLongAdLsn() and
GetAllocationDescriptorLsn() when the logical sector number cannot be
returned due to unrecognized media format.

Error handling logic will be used for those ASSERTs.

Cc: Ruiyu Ni <ruiyu.ni@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Hao Wu <hao.a.wu@intel.com>
Reviewed-by: Paulo Alcantara <palcantara@suse.de>
Reviewed-by: Star Zeng <star.zeng@intel.com>
MdeModulePkg/Universal/Disk/UdfDxe/FileSystemOperations.c

index 8b58cc9eb16df6e1a10a00f2edb2290cf0070094..1400846bf103a765c89065d2695b1422efb02923 100644 (file)
@@ -271,26 +271,39 @@ GetPdFromLongAd (
 /**\r
   Return logical sector number of a given Long Allocation Descriptor.\r
 \r
-  @param[in]  Volume              Volume information pointer.\r
-  @param[in]  LongAd              Long Allocation Descriptor pointer.\r
+  @param[in]   Volume             Volume information pointer.\r
+  @param[in]   LongAd             Long Allocation Descriptor pointer.\r
+  @param[out]  Lsn                Logical sector number pointer.\r
 \r
-  @return The logical sector number of a given Long Allocation Descriptor.\r
+  @retval EFI_SUCCESS             Logical sector number successfully returned.\r
+  @retval EFI_UNSUPPORTED         Logical sector number is not returned due to\r
+                                  unrecognized format.\r
 \r
 **/\r
-UINT64\r
+EFI_STATUS\r
 GetLongAdLsn (\r
-  IN UDF_VOLUME_INFO                 *Volume,\r
-  IN UDF_LONG_ALLOCATION_DESCRIPTOR  *LongAd\r
+  IN  UDF_VOLUME_INFO                 *Volume,\r
+  IN  UDF_LONG_ALLOCATION_DESCRIPTOR  *LongAd,\r
+  OUT UINT64                          *Lsn\r
   )\r
 {\r
   UDF_PARTITION_DESCRIPTOR *PartitionDesc;\r
 \r
   PartitionDesc = GetPdFromLongAd (Volume, LongAd);\r
-  ASSERT (PartitionDesc != NULL);\r
+  if (PartitionDesc == NULL) {\r
+    DEBUG ((\r
+      DEBUG_ERROR,\r
+      "%a: Fail to get the Partition Descriptor from the given Long Allocation Descriptor.\n",\r
+      __FUNCTION__\r
+      ));\r
+    return EFI_UNSUPPORTED;\r
+  }\r
 \r
-  return (UINT64)PartitionDesc->PartitionStartingLocation -\r
-    Volume->MainVdsStartLocation +\r
-    LongAd->ExtentLocation.LogicalBlockNumber;\r
+  *Lsn = (UINT64)PartitionDesc->PartitionStartingLocation -\r
+         Volume->MainVdsStartLocation +\r
+         LongAd->ExtentLocation.LogicalBlockNumber;\r
+\r
+  return EFI_SUCCESS;\r
 }\r
 \r
 /**\r
@@ -342,7 +355,10 @@ FindFileSetDescriptor (
   UDF_DESCRIPTOR_TAG             *DescriptorTag;\r
 \r
   LogicalVolDesc = &Volume->LogicalVolDesc;\r
-  Lsn = GetLongAdLsn (Volume, &LogicalVolDesc->LogicalVolumeContentsUse);\r
+  Status = GetLongAdLsn (Volume, &LogicalVolDesc->LogicalVolumeContentsUse, &Lsn);\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
 \r
   //\r
   // As per UDF 2.60 specification:\r
@@ -732,34 +748,43 @@ GetAllocationDescriptor (
   @param[in]  Volume              Volume information pointer.\r
   @param[in]  ParentIcb           Long Allocation Descriptor pointer.\r
   @param[in]  Ad                  Allocation Descriptor pointer.\r
+  @param[out] Lsn                 Logical sector number pointer.\r
 \r
-  @return The logical sector number of the given Allocation Descriptor.\r
+  @retval EFI_SUCCESS             Logical sector number of the given Allocation\r
+                                  Descriptor successfully returned.\r
+  @retval EFI_UNSUPPORTED         Logical sector number of the given Allocation\r
+                                  Descriptor is not returned due to unrecognized\r
+                                  format.\r
 \r
 **/\r
-UINT64\r
+EFI_STATUS\r
 GetAllocationDescriptorLsn (\r
-  IN UDF_FE_RECORDING_FLAGS          RecordingFlags,\r
-  IN UDF_VOLUME_INFO                 *Volume,\r
-  IN UDF_LONG_ALLOCATION_DESCRIPTOR  *ParentIcb,\r
-  IN VOID                            *Ad\r
+  IN  UDF_FE_RECORDING_FLAGS          RecordingFlags,\r
+  IN  UDF_VOLUME_INFO                 *Volume,\r
+  IN  UDF_LONG_ALLOCATION_DESCRIPTOR  *ParentIcb,\r
+  IN  VOID                            *Ad,\r
+  OUT UINT64                          *Lsn\r
   )\r
 {\r
   UDF_PARTITION_DESCRIPTOR *PartitionDesc;\r
 \r
   if (RecordingFlags == LongAdsSequence) {\r
-    return GetLongAdLsn (Volume, (UDF_LONG_ALLOCATION_DESCRIPTOR *)Ad);\r
+    return GetLongAdLsn (Volume, (UDF_LONG_ALLOCATION_DESCRIPTOR *)Ad, Lsn);\r
   } else if (RecordingFlags == ShortAdsSequence) {\r
     PartitionDesc = GetPdFromLongAd (Volume, ParentIcb);\r
-    ASSERT (PartitionDesc != NULL);\r
+    if (PartitionDesc == NULL) {\r
+      return EFI_UNSUPPORTED;\r
+    }\r
 \r
-    return GetShortAdLsn (\r
-      Volume,\r
-      PartitionDesc,\r
-      (UDF_SHORT_ALLOCATION_DESCRIPTOR *)Ad\r
-      );\r
+    *Lsn = GetShortAdLsn (\r
+             Volume,\r
+             PartitionDesc,\r
+             (UDF_SHORT_ALLOCATION_DESCRIPTOR *)Ad\r
+             );\r
+    return EFI_SUCCESS;\r
   }\r
 \r
-  return 0;\r
+  return EFI_UNSUPPORTED;\r
 }\r
 \r
 /**\r
@@ -804,10 +829,14 @@ GetAedAdsOffset (
   UDF_DESCRIPTOR_TAG                *DescriptorTag;\r
 \r
   ExtentLength  = GET_EXTENT_LENGTH (RecordingFlags, Ad);\r
-  Lsn           = GetAllocationDescriptorLsn (RecordingFlags,\r
+  Status        = GetAllocationDescriptorLsn (RecordingFlags,\r
                                               Volume,\r
                                               ParentIcb,\r
-                                              Ad);\r
+                                              Ad,\r
+                                              &Lsn);\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
 \r
   Data = AllocatePool (ExtentLength);\r
   if (Data == NULL) {\r
@@ -1156,10 +1185,14 @@ ReadFile (
 \r
       ExtentLength = GET_EXTENT_LENGTH (RecordingFlags, Ad);\r
 \r
-      Lsn = GetAllocationDescriptorLsn (RecordingFlags,\r
-                                        Volume,\r
-                                        ParentIcb,\r
-                                        Ad);\r
+      Status = GetAllocationDescriptorLsn (RecordingFlags,\r
+                                           Volume,\r
+                                           ParentIcb,\r
+                                           Ad,\r
+                                           &Lsn);\r
+      if (EFI_ERROR (Status)) {\r
+        goto Done;\r
+      }\r
 \r
       switch (ReadFileInfo->Flags) {\r
       case ReadFileGetFileSize:\r
@@ -1630,7 +1663,11 @@ FindFileEntry (
   UDF_DESCRIPTOR_TAG  *DescriptorTag;\r
   VOID                *ReadBuffer;\r
 \r
-  Lsn               = GetLongAdLsn (Volume, Icb);\r
+  Status = GetLongAdLsn (Volume, Icb, &Lsn);\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+\r
   LogicalBlockSize  = Volume->LogicalVolDesc.LogicalBlockSize;\r
 \r
   ReadBuffer = AllocateZeroPool (Volume->FileEntrySize);\r