[edk2] [PATCH 5/5] MdeModulePkg/PartitionDxe: remove always false comparison

Laszlo Ersek posted 5 patches 7 years, 3 months ago
[edk2] [PATCH 5/5] MdeModulePkg/PartitionDxe: remove always false comparison
Posted by Laszlo Ersek 7 years, 3 months ago
In the expression

  (RemainderByMediaBlockSize != 0 ||
   Media->BlockSize > UDF_LOGICAL_SECTOR_SIZE)

the second expression is only evaluated if the first expression is false.

If the first expression is false, i.e.,

  RemainderByMediaBlockSize == 0

then UDF_LOGICAL_SECTOR_SIZE is a whole multiple of "Media->BlockSize",
which implies

  UDF_LOGICAL_SECTOR_SIZE >= Media->BlockSize.

Therefore whenever

  Media->BlockSize > UDF_LOGICAL_SECTOR_SIZE

is evaluated, it is false.

The expression

  ((expression) || FALSE)

is equivalent to

  (expression).

Cc: Ard Biesheuvel <ard.biesheuvel@linaro.org>
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.1
Signed-off-by: Laszlo Ersek <lersek@redhat.com>
---
 MdeModulePkg/Universal/Disk/PartitionDxe/Udf.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/MdeModulePkg/Universal/Disk/PartitionDxe/Udf.c b/MdeModulePkg/Universal/Disk/PartitionDxe/Udf.c
index c491ef25f47e..3347b48421a8 100644
--- a/MdeModulePkg/Universal/Disk/PartitionDxe/Udf.c
+++ b/MdeModulePkg/Universal/Disk/PartitionDxe/Udf.c
@@ -252,12 +252,11 @@ PartitionInstallUdfChildHandles (
   DivU64x32Remainder (
     UDF_LOGICAL_SECTOR_SIZE,   // Dividend
     Media->BlockSize,          // Divisor
     &RemainderByMediaBlockSize // Remainder
     );
-  if (RemainderByMediaBlockSize != 0 ||
-      Media->BlockSize > UDF_LOGICAL_SECTOR_SIZE) {
+  if (RemainderByMediaBlockSize != 0) {
     return EFI_NOT_FOUND;
   }
 
   DevicePathNode = DevicePath;
   while (!IsDevicePathEnd (DevicePathNode)) {
-- 
2.14.1.3.gb7cf6e02401b

_______________________________________________
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel
Re: [edk2] [PATCH 5/5] MdeModulePkg/PartitionDxe: remove always false comparison
Posted by Zeng, Star 7 years, 3 months ago
Reviewed-by: Star Zeng <star.zeng@intel.com>

-----Original Message-----
From: Laszlo Ersek [mailto:lersek@redhat.com] 
Sent: Sunday, September 10, 2017 8:13 AM
To: edk2-devel-01 <edk2-devel@lists.01.org>
Cc: Ard Biesheuvel <ard.biesheuvel@linaro.org>; 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 5/5] MdeModulePkg/PartitionDxe: remove always false comparison

In the expression

  (RemainderByMediaBlockSize != 0 ||
   Media->BlockSize > UDF_LOGICAL_SECTOR_SIZE)

the second expression is only evaluated if the first expression is false.

If the first expression is false, i.e.,

  RemainderByMediaBlockSize == 0

then UDF_LOGICAL_SECTOR_SIZE is a whole multiple of "Media->BlockSize", which implies

  UDF_LOGICAL_SECTOR_SIZE >= Media->BlockSize.

Therefore whenever

  Media->BlockSize > UDF_LOGICAL_SECTOR_SIZE

is evaluated, it is false.

The expression

  ((expression) || FALSE)

is equivalent to

  (expression).

Cc: Ard Biesheuvel <ard.biesheuvel@linaro.org>
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.1
Signed-off-by: Laszlo Ersek <lersek@redhat.com>
---
 MdeModulePkg/Universal/Disk/PartitionDxe/Udf.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/MdeModulePkg/Universal/Disk/PartitionDxe/Udf.c b/MdeModulePkg/Universal/Disk/PartitionDxe/Udf.c
index c491ef25f47e..3347b48421a8 100644
--- a/MdeModulePkg/Universal/Disk/PartitionDxe/Udf.c
+++ b/MdeModulePkg/Universal/Disk/PartitionDxe/Udf.c
@@ -252,12 +252,11 @@ PartitionInstallUdfChildHandles (
   DivU64x32Remainder (
     UDF_LOGICAL_SECTOR_SIZE,   // Dividend
     Media->BlockSize,          // Divisor
     &RemainderByMediaBlockSize // Remainder
     );
-  if (RemainderByMediaBlockSize != 0 ||
-      Media->BlockSize > UDF_LOGICAL_SECTOR_SIZE) {
+  if (RemainderByMediaBlockSize != 0) {
     return EFI_NOT_FOUND;
   }
 
   DevicePathNode = DevicePath;
   while (!IsDevicePathEnd (DevicePathNode)) {
--
2.14.1.3.gb7cf6e02401b

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