[edk2] [patch 1/3] MdeModulePkg/PartitionDxe: Don't use non-constant expression in array

Dandan Bi posted 3 patches 7 years, 3 months ago
[edk2] [patch 1/3] MdeModulePkg/PartitionDxe: Don't use non-constant expression in array
Posted by Dandan Bi 7 years, 3 months ago
Remove the DescriptorLBAs[] array with non-constant expression to fix
non-constant aggregate initializer warning in VS tool chains.

Cc: Eric Dong <eric.dong@intel.com>
Cc: Paulo Alcantara <pcacjr@zytor.com>
Cc: Ruiyu Ni <ruiyu.ni@intel.com>
Cc: Star Zeng <star.zeng@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Dandan Bi <dandan.bi@intel.com>
---
 MdeModulePkg/Universal/Disk/PartitionDxe/Udf.c | 93 ++++++++++++++++++++------
 1 file changed, 72 insertions(+), 21 deletions(-)

diff --git a/MdeModulePkg/Universal/Disk/PartitionDxe/Udf.c b/MdeModulePkg/Universal/Disk/PartitionDxe/Udf.c
index 3347b48..28385f0 100644
--- a/MdeModulePkg/Universal/Disk/PartitionDxe/Udf.c
+++ b/MdeModulePkg/Universal/Disk/PartitionDxe/Udf.c
@@ -46,34 +46,85 @@ FindAnchorVolumeDescriptorPointer (
   IN   EFI_DISK_IO_PROTOCOL                  *DiskIo,
   OUT  UDF_ANCHOR_VOLUME_DESCRIPTOR_POINTER  *AnchorPoint
   )
 {
   EFI_STATUS  Status;
-  UINT32      BlockSize = BlockIo->Media->BlockSize;
-  EFI_LBA     EndLBA = BlockIo->Media->LastBlock;
-  EFI_LBA     DescriptorLBAs[] = { 256, EndLBA - 256, EndLBA, 512 };
-  UINTN       Index;
+  UINT32      BlockSize;
+  EFI_LBA     EndLBA;
 
-  for (Index = 0; Index < ARRAY_SIZE (DescriptorLBAs); Index++) {
-    Status = DiskIo->ReadDisk (
-      DiskIo,
-      BlockIo->Media->MediaId,
-      MultU64x32 (DescriptorLBAs[Index], BlockSize),
-      sizeof (UDF_ANCHOR_VOLUME_DESCRIPTOR_POINTER),
-      (VOID *)AnchorPoint
-      );
-    if (EFI_ERROR (Status)) {
-      return Status;
-    }
-    //
-    // Check if read LBA has a valid AVDP descriptor.
-    //
-    if (IS_AVDP (AnchorPoint)) {
-      return EFI_SUCCESS;
-    }
+  BlockSize = BlockIo->Media->BlockSize;
+  EndLBA = BlockIo->Media->LastBlock;
+
+  Status = DiskIo->ReadDisk (
+    DiskIo,
+    BlockIo->Media->MediaId,
+    MultU64x32 (256, BlockSize),
+    sizeof (UDF_ANCHOR_VOLUME_DESCRIPTOR_POINTER),
+    (VOID *)AnchorPoint
+    );
+  if (EFI_ERROR (Status)) {
+    return Status;
+  }
+  //
+  // Check if read LBA has a valid AVDP descriptor.
+  //
+  if (IS_AVDP (AnchorPoint)) {
+    return EFI_SUCCESS;
+  }
+
+  Status = DiskIo->ReadDisk (
+    DiskIo,
+    BlockIo->Media->MediaId,
+    MultU64x32 (EndLBA - 256, BlockSize),
+    sizeof (UDF_ANCHOR_VOLUME_DESCRIPTOR_POINTER),
+    (VOID *)AnchorPoint
+    );
+  if (EFI_ERROR (Status)) {
+    return Status;
+  }
+  //
+  // Check if read LBA has a valid AVDP descriptor.
+  //
+  if (IS_AVDP (AnchorPoint)) {
+    return EFI_SUCCESS;
+  }
+
+  Status = DiskIo->ReadDisk (
+    DiskIo,
+    BlockIo->Media->MediaId,
+    MultU64x32 (EndLBA, BlockSize),
+    sizeof (UDF_ANCHOR_VOLUME_DESCRIPTOR_POINTER),
+    (VOID *)AnchorPoint
+    );
+  if (EFI_ERROR (Status)) {
+    return Status;
   }
   //
+  // Check if read LBA has a valid AVDP descriptor.
+  //
+  if (IS_AVDP (AnchorPoint)) {
+    return EFI_SUCCESS;
+  }
+
+  Status = DiskIo->ReadDisk (
+    DiskIo,
+    BlockIo->Media->MediaId,
+    MultU64x32 (512, BlockSize),
+    sizeof (UDF_ANCHOR_VOLUME_DESCRIPTOR_POINTER),
+    (VOID *)AnchorPoint
+    );
+  if (EFI_ERROR (Status)) {
+    return Status;
+  }
+  //
+  // Check if read LBA has a valid AVDP descriptor.
+  //
+  if (IS_AVDP (AnchorPoint)) {
+    return EFI_SUCCESS;
+  }
+
+  //
   // No AVDP found.
   //
   return EFI_VOLUME_CORRUPTED;
 }
 
-- 
1.9.5.msysgit.1

_______________________________________________
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel
Re: [edk2] [patch 1/3] MdeModulePkg/PartitionDxe: Don't use non-constant expression in array
Posted by Ni, Ruiyu 7 years, 3 months ago
Dandan,
Thanks for fixing this.
But, why not write code as below?
EFI_LBA     DescriptorLBAs[4];

DescriptorLBA[0] = 256;
DescriptorLBA[1] = EndLBA - 256;
...
 
Thanks/Ray

> -----Original Message-----
> From: Bi, Dandan
> Sent: Monday, September 11, 2017 1:45 PM
> To: edk2-devel@lists.01.org
> Cc: Dong, Eric <eric.dong@intel.com>; Paulo Alcantara <pcacjr@zytor.com>;
> Ni, Ruiyu <ruiyu.ni@intel.com>; Zeng, Star <star.zeng@intel.com>
> Subject: [patch 1/3] MdeModulePkg/PartitionDxe: Don't use non-constant
> expression in array
> 
> Remove the DescriptorLBAs[] array with non-constant expression to fix non-
> constant aggregate initializer warning in VS tool chains.
> 
> Cc: Eric Dong <eric.dong@intel.com>
> Cc: Paulo Alcantara <pcacjr@zytor.com>
> Cc: Ruiyu Ni <ruiyu.ni@intel.com>
> Cc: Star Zeng <star.zeng@intel.com>
> Contributed-under: TianoCore Contribution Agreement 1.0
> Signed-off-by: Dandan Bi <dandan.bi@intel.com>
> ---
>  MdeModulePkg/Universal/Disk/PartitionDxe/Udf.c | 93
> ++++++++++++++++++++------
>  1 file changed, 72 insertions(+), 21 deletions(-)
> 
> diff --git a/MdeModulePkg/Universal/Disk/PartitionDxe/Udf.c
> b/MdeModulePkg/Universal/Disk/PartitionDxe/Udf.c
> index 3347b48..28385f0 100644
> --- a/MdeModulePkg/Universal/Disk/PartitionDxe/Udf.c
> +++ b/MdeModulePkg/Universal/Disk/PartitionDxe/Udf.c
> @@ -46,34 +46,85 @@ FindAnchorVolumeDescriptorPointer (
>    IN   EFI_DISK_IO_PROTOCOL                  *DiskIo,
>    OUT  UDF_ANCHOR_VOLUME_DESCRIPTOR_POINTER  *AnchorPoint
>    )
>  {
>    EFI_STATUS  Status;
> -  UINT32      BlockSize = BlockIo->Media->BlockSize;
> -  EFI_LBA     EndLBA = BlockIo->Media->LastBlock;
> -  EFI_LBA     DescriptorLBAs[] = { 256, EndLBA - 256, EndLBA, 512 };
> -  UINTN       Index;
> +  UINT32      BlockSize;
> +  EFI_LBA     EndLBA;
> 
> -  for (Index = 0; Index < ARRAY_SIZE (DescriptorLBAs); Index++) {
> -    Status = DiskIo->ReadDisk (
> -      DiskIo,
> -      BlockIo->Media->MediaId,
> -      MultU64x32 (DescriptorLBAs[Index], BlockSize),
> -      sizeof (UDF_ANCHOR_VOLUME_DESCRIPTOR_POINTER),
> -      (VOID *)AnchorPoint
> -      );
> -    if (EFI_ERROR (Status)) {
> -      return Status;
> -    }
> -    //
> -    // Check if read LBA has a valid AVDP descriptor.
> -    //
> -    if (IS_AVDP (AnchorPoint)) {
> -      return EFI_SUCCESS;
> -    }
> +  BlockSize = BlockIo->Media->BlockSize;  EndLBA =
> + BlockIo->Media->LastBlock;
> +
> +  Status = DiskIo->ReadDisk (
> +    DiskIo,
> +    BlockIo->Media->MediaId,
> +    MultU64x32 (256, BlockSize),
> +    sizeof (UDF_ANCHOR_VOLUME_DESCRIPTOR_POINTER),
> +    (VOID *)AnchorPoint
> +    );
> +  if (EFI_ERROR (Status)) {
> +    return Status;
> +  }
> +  //
> +  // Check if read LBA has a valid AVDP descriptor.
> +  //
> +  if (IS_AVDP (AnchorPoint)) {
> +    return EFI_SUCCESS;
> +  }
> +
> +  Status = DiskIo->ReadDisk (
> +    DiskIo,
> +    BlockIo->Media->MediaId,
> +    MultU64x32 (EndLBA - 256, BlockSize),
> +    sizeof (UDF_ANCHOR_VOLUME_DESCRIPTOR_POINTER),
> +    (VOID *)AnchorPoint
> +    );
> +  if (EFI_ERROR (Status)) {
> +    return Status;
> +  }
> +  //
> +  // Check if read LBA has a valid AVDP descriptor.
> +  //
> +  if (IS_AVDP (AnchorPoint)) {
> +    return EFI_SUCCESS;
> +  }
> +
> +  Status = DiskIo->ReadDisk (
> +    DiskIo,
> +    BlockIo->Media->MediaId,
> +    MultU64x32 (EndLBA, BlockSize),
> +    sizeof (UDF_ANCHOR_VOLUME_DESCRIPTOR_POINTER),
> +    (VOID *)AnchorPoint
> +    );
> +  if (EFI_ERROR (Status)) {
> +    return Status;
>    }
>    //
> +  // Check if read LBA has a valid AVDP descriptor.
> +  //
> +  if (IS_AVDP (AnchorPoint)) {
> +    return EFI_SUCCESS;
> +  }
> +
> +  Status = DiskIo->ReadDisk (
> +    DiskIo,
> +    BlockIo->Media->MediaId,
> +    MultU64x32 (512, BlockSize),
> +    sizeof (UDF_ANCHOR_VOLUME_DESCRIPTOR_POINTER),
> +    (VOID *)AnchorPoint
> +    );
> +  if (EFI_ERROR (Status)) {
> +    return Status;
> +  }
> +  //
> +  // Check if read LBA has a valid AVDP descriptor.
> +  //
> +  if (IS_AVDP (AnchorPoint)) {
> +    return EFI_SUCCESS;
> +  }
> +
> +  //
>    // No AVDP found.
>    //
>    return EFI_VOLUME_CORRUPTED;
>  }
> 
> --
> 1.9.5.msysgit.1

_______________________________________________
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel