public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* [PATCH v3 00/12] Refine casting expression result to bigger size
@ 2017-02-25  5:12 Hao Wu
  2017-02-25  5:12 ` [PATCH v3 01/12] MdePkg: " Hao Wu
                   ` (11 more replies)
  0 siblings, 12 replies; 25+ messages in thread
From: Hao Wu @ 2017-02-25  5:12 UTC (permalink / raw)
  To: edk2-devel; +Cc: Hao Wu

V3:
Send the full patch serires for review. The series is also available at:
https://github.com/hwu25/edk2  branch: refine_cast_v3

This version of series also add two new rules (3 & 4) when refining type
casts:
1). When the expression is possible to overflow the range of unsigned int/
int:
c = (UINT64)a + b;

2). When the expression will not overflow within the rank of "int", remove
the explicit type casts:
c = a + b;

3). When the expression will be cast to pointer of possible greater size:
UINT32 a,b;
VOID *c;
c = (VOID *)(UINTN)(a + b); --> c = (VOID *)((UINTN)a + b);

4). When one side of a comparison expression contains only operands with
rank less than UINT32:
UINT8 a;
UINT16 b;
UINTN c;
if ((UINTN)(a + b) > c) {...} --> if (((UINT32)a + b) > c) {...}

For rule 4), if we remove the 'UINTN' type cast like:
if (a + b > c) {...}
The VS compiler will complain with warning C4018 (signed/unsigned
mismatch, level 3 warning) due to promoting 'a + b' to type 'int'.


V2:
Follow the below rules to refine codes:
1). When the expression will not overflow within the rank of "int", remove
the explicit type casts:
c = a + b;

2). When the expression is possible to overflow the range of unsigned int/
int:
c = (UINT64)a + b;

V1:
There are cases that the operands of an expression are all with rank less
than UINT64/INT64 and the result of the expression is casted to
UINT64/INT64 to fit the target size.

An example will be:
UINT32 a,b;
// a and b can be any unsigned int type with rank less than UINT64, like
// UINT8, UINT16, etc.
UINT64 c;
c = (UINT64) (a + b);

Some static code checkers may warn that the expression result might
overflow within the rank of int (integer promotions) and the result is
then cast to a bigger size.

For the consideration of generated binaries size, the commit will keep the
size of the operands as the size of int, and explitly add a type cast
before converting the result to UINT64/INT64.

1). When there is no operand with type UINTN
(UINTN)  (a + b) -> (UINTN)(UINT32)  (a + b) or
(UINT64) (a + b) -> (UINT64)(UINT32) (a + b)

2). Otherwise
(UINT64) (a + b) -> (UINT64)(UINTN)  (a + b)


Hao Wu (12):
  MdePkg: Refine casting expression result to bigger size
  MdeModulePkg: Refine casting expression result to bigger size
  FatPkg: Refine casting expression result to bigger size
  IntelFrameworkModulePkg: Refine casting expression result to bigger
    size
  IntelFsp2WrapperPkg: Refine casting expression result to bigger size
  IntelFspWrapperPkg: Refine casting expression result to bigger size
  NetworkPkg: Refine casting expression result to bigger size
  PcAtChipsetPkg: Refine casting expression result to bigger size
  SecurityPkg/Opal: Refine casting expression result to bigger size
  ShellPkg: Refine casting expression result to bigger size
  SourceLevelDebugPkg: Refine casting expression result to bigger size
  UefiCpuPkg: Refine casting expression result to bigger size

 FatPkg/EnhancedFatDxe/ReadWrite.c                                               |  4 ++--
 FatPkg/FatPei/FatLiteAccess.c                                                   |  4 ++--
 IntelFrameworkModulePkg/Csm/BiosThunk/KeyboardDxe/BiosKeyboard.c                |  4 ++--
 IntelFrameworkModulePkg/Csm/BiosThunk/Snp16Dxe/BiosSnp16.c                      |  4 ++--
 IntelFrameworkModulePkg/Csm/BiosThunk/Snp16Dxe/Misc.c                           | 14 +++++++-------
 IntelFrameworkModulePkg/Csm/BiosThunk/VideoDxe/BiosVideo.c                      |  4 ++--
 IntelFrameworkModulePkg/Csm/LegacyBiosDxe/LegacyBios.c                          |  6 +++---
 IntelFrameworkModulePkg/Csm/LegacyBiosDxe/LegacyBootSupport.c                   |  4 ++--
 IntelFrameworkModulePkg/Library/GenericBdsLib/BdsBoot.c                         |  2 +-
 IntelFrameworkModulePkg/Library/GenericBdsLib/BdsMisc.c                         |  4 ++--
 IntelFrameworkModulePkg/Library/LegacyBootManagerLib/LegacyBm.c                 |  2 +-
 IntelFrameworkModulePkg/Universal/BdsDxe/FrontPage.c                            |  4 ++--
 IntelFrameworkModulePkg/Universal/CpuIoDxe/CpuIo.c                              |  4 ++--
 IntelFsp2WrapperPkg/FspWrapperNotifyDxe/LoadBelow4G.c                           |  4 ++--
 IntelFsp2WrapperPkg/Library/BaseFspWrapperApiLib/FspWrapperApiLib.c             | 10 +++++-----
 IntelFspWrapperPkg/FspNotifyDxe/LoadBelow4G.c                                   |  4 ++--
 IntelFspWrapperPkg/Library/BaseFspApiLib/FspApiLib.c                            | 12 ++++++------
 MdeModulePkg/Application/UiApp/FrontPage.c                                      |  4 ++--
 MdeModulePkg/Bus/Pci/EhciDxe/EhciReg.c                                          |  8 ++++----
 MdeModulePkg/Bus/Pci/IdeBusPei/AtapiPeim.c                                      |  4 ++--
 MdeModulePkg/Bus/Pci/PciBusDxe/PciOptionRomSupport.c                            |  2 +-
 MdeModulePkg/Bus/Pci/XhciDxe/XhciReg.c                                          | 20 ++++++++++----------
 MdeModulePkg/Bus/Ufs/UfsBlockIoPei/UfsHci.c                                     |  6 +++---
 MdeModulePkg/Bus/Ufs/UfsPassThruDxe/UfsPassThruHci.c                            |  6 +++---
 MdeModulePkg/Core/Dxe/Image/Image.c                                             | 14 ++++++--------
 MdeModulePkg/Core/Dxe/Misc/DebugImageInfo.c                                     |  4 ++--
 MdeModulePkg/Core/Pei/Image/Image.c                                             | 12 +++++-------
 MdeModulePkg/Core/PiSmmCore/Dispatcher.c                                        | 18 ++++++++----------
 MdeModulePkg/Core/PiSmmCore/PiSmmIpl.c                                          | 12 +++++-------
 MdeModulePkg/Library/DxeCapsuleLibFmp/DxeCapsuleLib.c                           |  4 ++--
 MdeModulePkg/Library/DxeCoreMemoryAllocationLib/MemoryAllocationLib.c           |  4 ++--
 MdeModulePkg/Library/DxeNetLib/DxeNetLib.c                                      |  4 ++--
 MdeModulePkg/Library/PiDxeS3BootScriptLib/BootScriptSave.c                      |  4 ++--
 MdeModulePkg/Library/PiSmmCoreMemoryAllocationLib/MemoryAllocationLib.c         |  4 ++--
 MdeModulePkg/Library/SmmMemoryAllocationProfileLib/MemoryAllocationLib.c        |  4 ++--
 MdeModulePkg/Library/UefiBootManagerLib/BmMisc.c                                |  4 ++--
 MdeModulePkg/Library/UefiHiiLib/HiiLib.c                                        |  4 ++--
 MdeModulePkg/Library/UefiMemoryAllocationProfileLib/MemoryAllocationLib.c       |  4 ++--
 MdeModulePkg/Library/VarCheckHiiLib/VarCheckHiiLibNullClass.c                   |  6 +++---
 MdeModulePkg/Universal/Acpi/BootScriptExecutorDxe/ScriptExecute.c               |  4 ++--
 MdeModulePkg/Universal/Acpi/S3SaveStateDxe/AcpiS3ContextSave.c                  |  6 +++---
 MdeModulePkg/Universal/CapsulePei/Common/CapsuleCoalesce.c                      |  4 ++--
 MdeModulePkg/Universal/DisplayEngineDxe/FormDisplay.c                           |  8 ++++----
 MdeModulePkg/Universal/EbcDxe/EbcExecute.c                                      | 10 +++++-----
 MdeModulePkg/Universal/FaultTolerantWriteDxe/UpdateWorkingBlock.c               |  4 ++--
 MdeModulePkg/Universal/HiiDatabaseDxe/Font.c                                    | 20 ++++++++++----------
 MdeModulePkg/Universal/Network/UefiPxeBcDxe/PxeBcImpl.c                         |  6 +++---
 MdeModulePkg/Universal/PCD/Dxe/Service.c                                        |  4 ++--
 MdeModulePkg/Universal/PCD/Pei/Service.c                                        |  4 ++--
 MdeModulePkg/Universal/SmbiosDxe/SmbiosDxe.c                                    |  6 +++---
 MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.c                           |  6 +++---
 MdePkg/Library/BaseLib/String.c                                                 |  4 ++--
 MdePkg/Library/BasePeCoffLib/BasePeCoff.c                                       | 12 +++++-------
 MdePkg/Library/BaseS3PciLib/S3PciLib.c                                          |  4 ++--
 MdePkg/Library/SmmMemoryAllocationLib/MemoryAllocationLib.c                     |  4 ++--
 MdePkg/Library/UefiMemoryAllocationLib/MemoryAllocationLib.c                    |  4 ++--
 NetworkPkg/IpSecDxe/Ikev2/Payload.c                                             |  4 ++--
 NetworkPkg/IpSecDxe/IpSecConfigImpl.c                                           |  8 ++++----
 NetworkPkg/IpSecDxe/IpSecConfigImpl.h                                           |  4 ++--
 NetworkPkg/Mtftp6Dxe/Mtftp6Support.c                                            |  4 ++--
 NetworkPkg/UefiPxeBcDxe/PxeBcImpl.c                                             | 10 +++++-----
 PcAtChipsetPkg/Library/SerialIoLib/SerialPortLib.c                              | 18 +++++++++---------
 SecurityPkg/Tcg/Opal/OpalPasswordSmm/OpalNvmeMode.c                             |  4 ++--
 ShellPkg/Library/UefiShellDebug1CommandsLib/HexEdit/BufferImage.c               |  8 ++++----
 ShellPkg/Library/UefiShellDebug1CommandsLib/UefiShellDebug1CommandsLib.c        |  4 ++--
 ShellPkg/Library/UefiShellLib/UefiShellLib.c                                    |  4 ++--
 SourceLevelDebugPkg/Library/DebugAgent/DxeDebugAgent/DxeDebugAgentLib.c         |  6 +++---
 SourceLevelDebugPkg/Library/DebugAgent/SecPeiDebugAgent/SecPeiDebugAgentLib.c   |  8 ++++----
 SourceLevelDebugPkg/Library/DebugAgent/SmmDebugAgent/SmmDebugAgentLib.c         |  6 +++---
 SourceLevelDebugPkg/Library/DebugCommunicationLibUsb/DebugCommunicationLibUsb.c | 18 +++++++++---------
 UefiCpuPkg/CpuIo2Dxe/CpuIo2Dxe.c                                                |  4 ++--
 UefiCpuPkg/CpuIo2Smm/CpuIo2Smm.c                                                |  4 ++--
 UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmStm.c                                   |  8 ++++----
 UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.c                                      |  4 ++--
 UefiCpuPkg/PiSmmCpuDxeSmm/SmramSaveState.c                                      |  6 +++---
 75 files changed, 237 insertions(+), 247 deletions(-)

-- 
1.9.5.msysgit.0



^ permalink raw reply	[flat|nested] 25+ messages in thread

* [PATCH v3 01/12] MdePkg: Refine casting expression result to bigger size
  2017-02-25  5:12 [PATCH v3 00/12] Refine casting expression result to bigger size Hao Wu
@ 2017-02-25  5:12 ` Hao Wu
  2017-02-25  5:12 ` [PATCH v3 02/12] MdeModulePkg: " Hao Wu
                   ` (10 subsequent siblings)
  11 siblings, 0 replies; 25+ messages in thread
From: Hao Wu @ 2017-02-25  5:12 UTC (permalink / raw)
  To: edk2-devel; +Cc: Hao Wu, Michael Kinney, Liming Gao

There are cases that the operands of an expression are all with rank less
than UINT64/INT64 and the result of the expression is explicitly cast to
UINT64/INT64 to fit the target size.

An example will be:
UINT32 a,b;
// a and b can be any unsigned int type with rank less than UINT64, like
// UINT8, UINT16, etc.
UINT64 c;
c = (UINT64) (a + b);

Some static code checkers may warn that the expression result might
overflow within the rank of "int" (integer promotions) and the result is
then cast to a bigger size.

The commit refines codes by the following rules:
1). When the expression is possible to overflow the range of unsigned int/
int:
c = (UINT64)a + b;

2). When the expression will not overflow within the rank of "int", remove
the explicit type casts:
c = a + b;

3). When the expression will be cast to pointer of possible greater size:
UINT32 a,b;
VOID *c;
c = (VOID *)(UINTN)(a + b); --> c = (VOID *)((UINTN)a + b);

4). When one side of a comparison expression contains only operands with
rank less than UINT32:
UINT8 a;
UINT16 b;
UINTN c;
if ((UINTN)(a + b) > c) {...} --> if (((UINT32)a + b) > c) {...}

For rule 4), if we remove the 'UINTN' type cast like:
if (a + b > c) {...}
The VS compiler will complain with warning C4018 (signed/unsigned
mismatch, level 3 warning) due to promoting 'a + b' to type 'int'.

Cc: Michael Kinney <michael.d.kinney@intel.com>
Cc: Liming Gao <liming.gao@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Hao Wu <hao.a.wu@intel.com>
Reviewed-by: Laszlo Ersek <lersek@redhat.com>
---
 MdePkg/Library/BaseLib/String.c                              |  4 ++--
 MdePkg/Library/BasePeCoffLib/BasePeCoff.c                    | 12 +++++-------
 MdePkg/Library/BaseS3PciLib/S3PciLib.c                       |  4 ++--
 MdePkg/Library/SmmMemoryAllocationLib/MemoryAllocationLib.c  |  4 ++--
 MdePkg/Library/UefiMemoryAllocationLib/MemoryAllocationLib.c |  4 ++--
 5 files changed, 13 insertions(+), 15 deletions(-)

diff --git a/MdePkg/Library/BaseLib/String.c b/MdePkg/Library/BaseLib/String.c
index e84bf50..4151e0e 100644
--- a/MdePkg/Library/BaseLib/String.c
+++ b/MdePkg/Library/BaseLib/String.c
@@ -586,7 +586,7 @@ InternalHexCharToUintn (
     return Char - L'0';
   }
 
-  return (UINTN) (10 + InternalCharToUpper (Char) - L'A');
+  return (10 + InternalCharToUpper (Char) - L'A');
 }
 
 /**
@@ -1211,7 +1211,7 @@ InternalAsciiHexCharToUintn (
     return Char - '0';
   }
 
-  return (UINTN) (10 + InternalBaseLibAsciiToUpper (Char) - 'A');
+  return (10 + InternalBaseLibAsciiToUpper (Char) - 'A');
 }
 
 
diff --git a/MdePkg/Library/BasePeCoffLib/BasePeCoff.c b/MdePkg/Library/BasePeCoffLib/BasePeCoff.c
index 33cad23..8d1daba 100644
--- a/MdePkg/Library/BasePeCoffLib/BasePeCoff.c
+++ b/MdePkg/Library/BasePeCoffLib/BasePeCoff.c
@@ -15,7 +15,7 @@
   PeCoffLoaderGetPeHeader() routine will do basic check for PE/COFF header.
   PeCoffLoaderGetImageInfo() routine will do basic check for whole PE/COFF image.
 
-  Copyright (c) 2006 - 2014, Intel Corporation. All rights reserved.<BR>
+  Copyright (c) 2006 - 2017, Intel Corporation. All rights reserved.<BR>
   Portions copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
   This program and the accompanying materials
   are licensed and made available under the terms and conditions of the BSD License
@@ -703,12 +703,10 @@ PeCoffLoaderGetImageInfo (
       //
       DebugDirectoryEntryFileOffset = 0;
 
-      SectionHeaderOffset = (UINTN)(
-                               ImageContext->PeCoffHeaderOffset +
-                               sizeof (UINT32) +
-                               sizeof (EFI_IMAGE_FILE_HEADER) +
-                               Hdr.Pe32->FileHeader.SizeOfOptionalHeader
-                               );
+      SectionHeaderOffset = ImageContext->PeCoffHeaderOffset +
+                            sizeof (UINT32) +
+                            sizeof (EFI_IMAGE_FILE_HEADER) +
+                            Hdr.Pe32->FileHeader.SizeOfOptionalHeader;
 
       for (Index = 0; Index < Hdr.Pe32->FileHeader.NumberOfSections; Index++) {
         //
diff --git a/MdePkg/Library/BaseS3PciLib/S3PciLib.c b/MdePkg/Library/BaseS3PciLib/S3PciLib.c
index e29f7fe..27342b0 100644
--- a/MdePkg/Library/BaseS3PciLib/S3PciLib.c
+++ b/MdePkg/Library/BaseS3PciLib/S3PciLib.c
@@ -3,7 +3,7 @@
   the PCI operations to be replayed during an S3 resume. This library class
   maps directly on top of the PciLib class. 
 
-  Copyright (c) 2006 - 2012, Intel Corporation. All rights reserved.<BR>
+  Copyright (c) 2006 - 2017, Intel Corporation. All rights reserved.<BR>
 
   This program and the accompanying materials
   are licensed and made available under the terms and conditions
@@ -25,7 +25,7 @@
 #include <Library/S3PciLib.h>
 
 #define PCILIB_TO_COMMON_ADDRESS(Address) \
-        ((UINT64) ((((UINTN) ((Address>>20) & 0xff)) << 24) + (((UINTN) ((Address>>15) & 0x1f)) << 16) + (((UINTN) ((Address>>12) & 0x07)) << 8) + ((UINTN) (Address & 0xfff ))))
+        ((((UINTN) ((Address>>20) & 0xff)) << 24) + (((UINTN) ((Address>>15) & 0x1f)) << 16) + (((UINTN) ((Address>>12) & 0x07)) << 8) + ((UINTN) (Address & 0xfff )))
 
 /**
   Saves a PCI configuration value to the boot script.
diff --git a/MdePkg/Library/SmmMemoryAllocationLib/MemoryAllocationLib.c b/MdePkg/Library/SmmMemoryAllocationLib/MemoryAllocationLib.c
index 937165a..592cced 100644
--- a/MdePkg/Library/SmmMemoryAllocationLib/MemoryAllocationLib.c
+++ b/MdePkg/Library/SmmMemoryAllocationLib/MemoryAllocationLib.c
@@ -12,7 +12,7 @@
   allocation for the Reserved memory types are not supported and will always 
   return NULL.
 
-  Copyright (c) 2006 - 2015, Intel Corporation. All rights reserved.<BR>
+  Copyright (c) 2006 - 2017, Intel Corporation. All rights reserved.<BR>
   This program and the accompanying materials                          
   are licensed and made available under the terms and conditions of the BSD License         
   which accompanies this distribution.  The full text of the license may be found at        
@@ -343,7 +343,7 @@ InternalAllocateAlignedPages (
       Status = gSmst->SmmFreePages (Memory, UnalignedPages);
       ASSERT_EFI_ERROR (Status);
     }
-    Memory         = (EFI_PHYSICAL_ADDRESS) (AlignedMemory + EFI_PAGES_TO_SIZE (Pages));
+    Memory         = AlignedMemory + EFI_PAGES_TO_SIZE (Pages);
     UnalignedPages = RealPages - Pages - UnalignedPages;
     if (UnalignedPages > 0) {
       //
diff --git a/MdePkg/Library/UefiMemoryAllocationLib/MemoryAllocationLib.c b/MdePkg/Library/UefiMemoryAllocationLib/MemoryAllocationLib.c
index 3da5e211..3bd3aef 100644
--- a/MdePkg/Library/UefiMemoryAllocationLib/MemoryAllocationLib.c
+++ b/MdePkg/Library/UefiMemoryAllocationLib/MemoryAllocationLib.c
@@ -2,7 +2,7 @@
   Support routines for memory allocation routines based 
   on boot services for Dxe phase drivers.
 
-  Copyright (c) 2006 - 2015, Intel Corporation. All rights reserved.<BR>
+  Copyright (c) 2006 - 2017, Intel Corporation. All rights reserved.<BR>
   This program and the accompanying materials                          
   are licensed and made available under the terms and conditions of the BSD License         
   which accompanies this distribution.  The full text of the license may be found at        
@@ -216,7 +216,7 @@ InternalAllocateAlignedPages (
       Status = gBS->FreePages (Memory, UnalignedPages);
       ASSERT_EFI_ERROR (Status);
     }
-    Memory         = (EFI_PHYSICAL_ADDRESS) (AlignedMemory + EFI_PAGES_TO_SIZE (Pages));
+    Memory         = AlignedMemory + EFI_PAGES_TO_SIZE (Pages);
     UnalignedPages = RealPages - Pages - UnalignedPages;
     if (UnalignedPages > 0) {
       //
-- 
1.9.5.msysgit.0



^ permalink raw reply related	[flat|nested] 25+ messages in thread

* [PATCH v3 02/12] MdeModulePkg: Refine casting expression result to bigger size
  2017-02-25  5:12 [PATCH v3 00/12] Refine casting expression result to bigger size Hao Wu
  2017-02-25  5:12 ` [PATCH v3 01/12] MdePkg: " Hao Wu
@ 2017-02-25  5:12 ` Hao Wu
  2017-03-06  1:37   ` Tian, Feng
  2017-02-25  5:12 ` [PATCH v3 03/12] FatPkg: " Hao Wu
                   ` (9 subsequent siblings)
  11 siblings, 1 reply; 25+ messages in thread
From: Hao Wu @ 2017-02-25  5:12 UTC (permalink / raw)
  To: edk2-devel; +Cc: Hao Wu, Feng Tian, Star Zeng

There are cases that the operands of an expression are all with rank less
than UINT64/INT64 and the result of the expression is explicitly cast to
UINT64/INT64 to fit the target size.

An example will be:
UINT32 a,b;
// a and b can be any unsigned int type with rank less than UINT64, like
// UINT8, UINT16, etc.
UINT64 c;
c = (UINT64) (a + b);

Some static code checkers may warn that the expression result might
overflow within the rank of "int" (integer promotions) and the result is
then cast to a bigger size.

The commit refines codes by the following rules:
1). When the expression is possible to overflow the range of unsigned int/
int:
c = (UINT64)a + b;

2). When the expression will not overflow within the rank of "int", remove
the explicit type casts:
c = a + b;

3). When the expression will be cast to pointer of possible greater size:
UINT32 a,b;
VOID *c;
c = (VOID *)(UINTN)(a + b); --> c = (VOID *)((UINTN)a + b);

4). When one side of a comparison expression contains only operands with
rank less than UINT32:
UINT8 a;
UINT16 b;
UINTN c;
if ((UINTN)(a + b) > c) {...} --> if (((UINT32)a + b) > c) {...}

For rule 4), if we remove the 'UINTN' type cast like:
if (a + b > c) {...}
The VS compiler will complain with warning C4018 (signed/unsigned
mismatch, level 3 warning) due to promoting 'a + b' to type 'int'.

Cc: Feng Tian <feng.tian@intel.com>
Cc: Star Zeng <star.zeng@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Hao Wu <hao.a.wu@intel.com>
---
 MdeModulePkg/Application/UiApp/FrontPage.c                                |  4 ++--
 MdeModulePkg/Bus/Pci/EhciDxe/EhciReg.c                                    |  8 ++++----
 MdeModulePkg/Bus/Pci/IdeBusPei/AtapiPeim.c                                |  4 ++--
 MdeModulePkg/Bus/Pci/PciBusDxe/PciOptionRomSupport.c                      |  2 +-
 MdeModulePkg/Bus/Pci/XhciDxe/XhciReg.c                                    | 20 ++++++++++----------
 MdeModulePkg/Bus/Ufs/UfsBlockIoPei/UfsHci.c                               |  6 +++---
 MdeModulePkg/Bus/Ufs/UfsPassThruDxe/UfsPassThruHci.c                      |  6 +++---
 MdeModulePkg/Core/Dxe/Image/Image.c                                       | 14 ++++++--------
 MdeModulePkg/Core/Dxe/Misc/DebugImageInfo.c                               |  4 ++--
 MdeModulePkg/Core/Pei/Image/Image.c                                       | 12 +++++-------
 MdeModulePkg/Core/PiSmmCore/Dispatcher.c                                  | 18 ++++++++----------
 MdeModulePkg/Core/PiSmmCore/PiSmmIpl.c                                    | 12 +++++-------
 MdeModulePkg/Library/DxeCapsuleLibFmp/DxeCapsuleLib.c                     |  4 ++--
 MdeModulePkg/Library/DxeCoreMemoryAllocationLib/MemoryAllocationLib.c     |  4 ++--
 MdeModulePkg/Library/DxeNetLib/DxeNetLib.c                                |  4 ++--
 MdeModulePkg/Library/PiDxeS3BootScriptLib/BootScriptSave.c                |  4 ++--
 MdeModulePkg/Library/PiSmmCoreMemoryAllocationLib/MemoryAllocationLib.c   |  4 ++--
 MdeModulePkg/Library/SmmMemoryAllocationProfileLib/MemoryAllocationLib.c  |  4 ++--
 MdeModulePkg/Library/UefiBootManagerLib/BmMisc.c                          |  4 ++--
 MdeModulePkg/Library/UefiHiiLib/HiiLib.c                                  |  4 ++--
 MdeModulePkg/Library/UefiMemoryAllocationProfileLib/MemoryAllocationLib.c |  4 ++--
 MdeModulePkg/Library/VarCheckHiiLib/VarCheckHiiLibNullClass.c             |  6 +++---
 MdeModulePkg/Universal/Acpi/BootScriptExecutorDxe/ScriptExecute.c         |  4 ++--
 MdeModulePkg/Universal/Acpi/S3SaveStateDxe/AcpiS3ContextSave.c            |  6 +++---
 MdeModulePkg/Universal/CapsulePei/Common/CapsuleCoalesce.c                |  4 ++--
 MdeModulePkg/Universal/DisplayEngineDxe/FormDisplay.c                     |  8 ++++----
 MdeModulePkg/Universal/EbcDxe/EbcExecute.c                                | 10 +++++-----
 MdeModulePkg/Universal/FaultTolerantWriteDxe/UpdateWorkingBlock.c         |  4 ++--
 MdeModulePkg/Universal/HiiDatabaseDxe/Font.c                              | 20 ++++++++++----------
 MdeModulePkg/Universal/Network/UefiPxeBcDxe/PxeBcImpl.c                   |  6 +++---
 MdeModulePkg/Universal/PCD/Dxe/Service.c                                  |  4 ++--
 MdeModulePkg/Universal/PCD/Pei/Service.c                                  |  4 ++--
 MdeModulePkg/Universal/SmbiosDxe/SmbiosDxe.c                              |  6 +++---
 MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.c                     |  6 +++---
 34 files changed, 113 insertions(+), 121 deletions(-)

diff --git a/MdeModulePkg/Application/UiApp/FrontPage.c b/MdeModulePkg/Application/UiApp/FrontPage.c
index bda5ff9..c2393eb 100644
--- a/MdeModulePkg/Application/UiApp/FrontPage.c
+++ b/MdeModulePkg/Application/UiApp/FrontPage.c
@@ -1,7 +1,7 @@
 /** @file
   FrontPage routines to handle the callbacks and browser calls
 
-Copyright (c) 2004 - 2016, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2004 - 2017, Intel Corporation. All rights reserved.<BR>
 This program and the accompanying materials
 are licensed and made available under the terms and conditions of the BSD License
 which accompanies this distribution.  The full text of the license may be found at
@@ -399,7 +399,7 @@ ConvertProcessorToString (
 
   if (Base10Exponent >= 6) {
     FreqMhz = ProcessorFrequency;
-    for (Index = 0; Index < (UINTN) (Base10Exponent - 6); Index++) {
+    for (Index = 0; Index < (UINT32) Base10Exponent - 6; Index++) {
       FreqMhz *= 10;
     }
   } else {
diff --git a/MdeModulePkg/Bus/Pci/EhciDxe/EhciReg.c b/MdeModulePkg/Bus/Pci/EhciDxe/EhciReg.c
index 3a6ed02..34836ec 100644
--- a/MdeModulePkg/Bus/Pci/EhciDxe/EhciReg.c
+++ b/MdeModulePkg/Bus/Pci/EhciDxe/EhciReg.c
@@ -2,7 +2,7 @@
 
   The EHCI register operation routines.
 
-Copyright (c) 2007 - 2012, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2007 - 2017, Intel Corporation. All rights reserved.<BR>
 This program and the accompanying materials
 are licensed and made available under the terms and conditions of the BSD License
 which accompanies this distribution.  The full text of the license may be found at
@@ -76,7 +76,7 @@ EhcReadDbgRegister (
                              Ehc->PciIo,
                              EfiPciIoWidthUint32,
                              Ehc->DebugPortBarNum,
-                             (UINT64) (Ehc->DebugPortOffset + Offset),
+                             Ehc->DebugPortOffset + Offset,
                              1,
                              &Data
                              );
@@ -115,7 +115,7 @@ EhcReadOpReg (
                              Ehc->PciIo,
                              EfiPciIoWidthUint32,
                              EHC_BAR_INDEX,
-                             (UINT64) (Ehc->CapLen + Offset),
+                             Ehc->CapLen + Offset,
                              1,
                              &Data
                              );
@@ -152,7 +152,7 @@ EhcWriteOpReg (
                              Ehc->PciIo,
                              EfiPciIoWidthUint32,
                              EHC_BAR_INDEX,
-                             (UINT64) (Ehc->CapLen + Offset),
+                             Ehc->CapLen + Offset,
                              1,
                              &Data
                              );
diff --git a/MdeModulePkg/Bus/Pci/IdeBusPei/AtapiPeim.c b/MdeModulePkg/Bus/Pci/IdeBusPei/AtapiPeim.c
index be1b829..b1ab34d 100644
--- a/MdeModulePkg/Bus/Pci/IdeBusPei/AtapiPeim.c
+++ b/MdeModulePkg/Bus/Pci/IdeBusPei/AtapiPeim.c
@@ -5,7 +5,7 @@ ATA controllers in the platform.
 This PPI can be consumed by PEIM which produce gEfiPeiDeviceRecoveryModulePpiGuid
 for Atapi CD ROM device.
 
-Copyright (c) 2006 - 2015, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2006 - 2017, Intel Corporation. All rights reserved.<BR>
 
 This program and the accompanying materials
 are licensed and made available under the terms and conditions
@@ -593,7 +593,7 @@ AtapiEnumerateDevices (
       //
       // Pata & Sata, Primary & Secondary channel, Master & Slave device
       //
-      DevicePosition = (UINTN) (Index1 * 2 + Index2);
+      DevicePosition = Index1 * 2 + Index2;
 
       if (DiscoverAtapiDevice (AtapiBlkIoDev, DevicePosition, &MediaInfo, &MediaInfo2)) {
         //
diff --git a/MdeModulePkg/Bus/Pci/PciBusDxe/PciOptionRomSupport.c b/MdeModulePkg/Bus/Pci/PciBusDxe/PciOptionRomSupport.c
index d2ad94e..3713c07 100644
--- a/MdeModulePkg/Bus/Pci/PciBusDxe/PciOptionRomSupport.c
+++ b/MdeModulePkg/Bus/Pci/PciBusDxe/PciOptionRomSupport.c
@@ -305,7 +305,7 @@ GetOpRomInfo (
     return EFI_NOT_FOUND;
   }
 
-  PciIoDevice->RomSize = (UINT64) ((~AllOnes) + 1);
+  PciIoDevice->RomSize = (~AllOnes) + 1;
   return EFI_SUCCESS;
 }
 
diff --git a/MdeModulePkg/Bus/Pci/XhciDxe/XhciReg.c b/MdeModulePkg/Bus/Pci/XhciDxe/XhciReg.c
index 0e1c86c..4d5937d 100644
--- a/MdeModulePkg/Bus/Pci/XhciDxe/XhciReg.c
+++ b/MdeModulePkg/Bus/Pci/XhciDxe/XhciReg.c
@@ -2,7 +2,7 @@
 
   The XHCI register operation routines.
 
-Copyright (c) 2011 - 2016, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2011 - 2017, Intel Corporation. All rights reserved.<BR>
 This program and the accompanying materials
 are licensed and made available under the terms and conditions of the BSD License
 which accompanies this distribution.  The full text of the license may be found at
@@ -112,7 +112,7 @@ XhcReadOpReg (
                              Xhc->PciIo,
                              EfiPciIoWidthUint32,
                              XHC_BAR_INDEX,
-                             (UINT64) (Xhc->CapLength + Offset),
+                             Xhc->CapLength + Offset,
                              1,
                              &Data
                              );
@@ -148,7 +148,7 @@ XhcWriteOpReg (
                              Xhc->PciIo,
                              EfiPciIoWidthUint32,
                              XHC_BAR_INDEX,
-                             (UINT64) (Xhc->CapLength + Offset),
+                             Xhc->CapLength + Offset,
                              1,
                              &Data
                              );
@@ -181,7 +181,7 @@ XhcWriteOpReg16 (
                              Xhc->PciIo,
                              EfiPciIoWidthUint16,
                              XHC_BAR_INDEX,
-                             (UINT64) (Xhc->CapLength + Offset),
+                             Xhc->CapLength + Offset,
                              1,
                              &Data
                              );
@@ -215,7 +215,7 @@ XhcReadDoorBellReg (
                              Xhc->PciIo,
                              EfiPciIoWidthUint32,
                              XHC_BAR_INDEX,
-                             (UINT64) (Xhc->DBOff + Offset),
+                             Xhc->DBOff + Offset,
                              1,
                              &Data
                              );
@@ -251,7 +251,7 @@ XhcWriteDoorBellReg (
                              Xhc->PciIo,
                              EfiPciIoWidthUint32,
                              XHC_BAR_INDEX,
-                             (UINT64) (Xhc->DBOff + Offset),
+                             Xhc->DBOff + Offset,
                              1,
                              &Data
                              );
@@ -285,7 +285,7 @@ XhcReadRuntimeReg (
                              Xhc->PciIo,
                              EfiPciIoWidthUint32,
                              XHC_BAR_INDEX,
-                             (UINT64) (Xhc->RTSOff + Offset),
+                             Xhc->RTSOff + Offset,
                              1,
                              &Data
                              );
@@ -321,7 +321,7 @@ XhcWriteRuntimeReg (
                              Xhc->PciIo,
                              EfiPciIoWidthUint32,
                              XHC_BAR_INDEX,
-                             (UINT64) (Xhc->RTSOff + Offset),
+                             Xhc->RTSOff + Offset,
                              1,
                              &Data
                              );
@@ -355,7 +355,7 @@ XhcReadExtCapReg (
                              Xhc->PciIo,
                              EfiPciIoWidthUint32,
                              XHC_BAR_INDEX,
-                             (UINT64) (Xhc->ExtCapRegBase + Offset),
+                             Xhc->ExtCapRegBase + Offset,
                              1,
                              &Data
                              );
@@ -391,7 +391,7 @@ XhcWriteExtCapReg (
                              Xhc->PciIo,
                              EfiPciIoWidthUint32,
                              XHC_BAR_INDEX,
-                             (UINT64) (Xhc->ExtCapRegBase + Offset),
+                             Xhc->ExtCapRegBase + Offset,
                              1,
                              &Data
                              );
diff --git a/MdeModulePkg/Bus/Ufs/UfsBlockIoPei/UfsHci.c b/MdeModulePkg/Bus/Ufs/UfsBlockIoPei/UfsHci.c
index 332ce7e..1ef6c88 100644
--- a/MdeModulePkg/Bus/Ufs/UfsBlockIoPei/UfsHci.c
+++ b/MdeModulePkg/Bus/Ufs/UfsBlockIoPei/UfsHci.c
@@ -1,6 +1,6 @@
 /** @file
 
-  Copyright (c) 2014 - 2016, Intel Corporation. All rights reserved.<BR>
+  Copyright (c) 2014 - 2017, Intel Corporation. All rights reserved.<BR>
   This program and the accompanying materials
   are licensed and made available under the terms and conditions of the BSD License
   which accompanies this distribution.  The full text of the license may be found at
@@ -589,9 +589,9 @@ UfsCreateDMCommandDesc (
   Trd->UcdBaU = (UINT32)RShiftU64 ((UINT64)(UINTN)QueryReqUpiu, 32);
   if (Opcode == UtpQueryFuncOpcodeWrDesc) {
     Trd->RuL  = (UINT16)DivU64x32 ((UINT64)ROUNDUP8 (sizeof (UTP_QUERY_RESP_UPIU)), sizeof (UINT32));
-    Trd->RuO  = (UINT16)DivU64x32 ((UINT64)(ROUNDUP8 (sizeof (UTP_QUERY_REQ_UPIU)) + ROUNDUP8 (DataSize)), sizeof (UINT32));
+    Trd->RuO  = (UINT16)DivU64x32 ((UINT64)ROUNDUP8 (sizeof (UTP_QUERY_REQ_UPIU)) + ROUNDUP8 (DataSize), sizeof (UINT32));
   } else {
-    Trd->RuL  = (UINT16)DivU64x32 ((UINT64)(ROUNDUP8 (sizeof (UTP_QUERY_RESP_UPIU)) + ROUNDUP8 (DataSize)), sizeof (UINT32));
+    Trd->RuL  = (UINT16)DivU64x32 ((UINT64)ROUNDUP8 (sizeof (UTP_QUERY_RESP_UPIU)) + ROUNDUP8 (DataSize), sizeof (UINT32));
     Trd->RuO  = (UINT16)DivU64x32 ((UINT64)ROUNDUP8 (sizeof (UTP_QUERY_REQ_UPIU)), sizeof (UINT32));
   }
 
diff --git a/MdeModulePkg/Bus/Ufs/UfsPassThruDxe/UfsPassThruHci.c b/MdeModulePkg/Bus/Ufs/UfsPassThruDxe/UfsPassThruHci.c
index bc39cf8..3dd8cbf 100644
--- a/MdeModulePkg/Bus/Ufs/UfsPassThruDxe/UfsPassThruHci.c
+++ b/MdeModulePkg/Bus/Ufs/UfsPassThruDxe/UfsPassThruHci.c
@@ -2,7 +2,7 @@
   UfsPassThruDxe driver is used to produce EFI_EXT_SCSI_PASS_THRU protocol interface
   for upper layer application to execute UFS-supported SCSI cmds.
 
-  Copyright (c) 2014 - 2016, Intel Corporation. All rights reserved.<BR>
+  Copyright (c) 2014 - 2017, Intel Corporation. All rights reserved.<BR>
   This program and the accompanying materials
   are licensed and made available under the terms and conditions of the BSD License
   which accompanies this distribution.  The full text of the license may be found at
@@ -666,9 +666,9 @@ UfsCreateDMCommandDesc (
   Trd->UcdBaU = (UINT32)RShiftU64 ((UINT64)CmdDescPhyAddr, 32);
   if (Opcode == UtpQueryFuncOpcodeWrDesc) {
     Trd->RuL  = (UINT16)DivU64x32 ((UINT64)ROUNDUP8 (sizeof (UTP_QUERY_RESP_UPIU)), sizeof (UINT32));
-    Trd->RuO  = (UINT16)DivU64x32 ((UINT64)(ROUNDUP8 (sizeof (UTP_QUERY_REQ_UPIU)) + ROUNDUP8 (DataSize)), sizeof (UINT32));
+    Trd->RuO  = (UINT16)DivU64x32 ((UINT64)ROUNDUP8 (sizeof (UTP_QUERY_REQ_UPIU)) + ROUNDUP8 (DataSize), sizeof (UINT32));
   } else {
-    Trd->RuL  = (UINT16)DivU64x32 ((UINT64)(ROUNDUP8 (sizeof (UTP_QUERY_RESP_UPIU)) + ROUNDUP8 (DataSize)), sizeof (UINT32));
+    Trd->RuL  = (UINT16)DivU64x32 ((UINT64)ROUNDUP8 (sizeof (UTP_QUERY_RESP_UPIU)) + ROUNDUP8 (DataSize), sizeof (UINT32));
     Trd->RuO  = (UINT16)DivU64x32 ((UINT64)ROUNDUP8 (sizeof (UTP_QUERY_REQ_UPIU)), sizeof (UINT32));
   }
 
diff --git a/MdeModulePkg/Core/Dxe/Image/Image.c b/MdeModulePkg/Core/Dxe/Image/Image.c
index 652da8b..80128e7 100644
--- a/MdeModulePkg/Core/Dxe/Image/Image.c
+++ b/MdeModulePkg/Core/Dxe/Image/Image.c
@@ -313,8 +313,8 @@ CheckAndMarkFixLoadingMemoryUsageBitMap (
    //
    // Test if the memory is avalaible or not.
    // 
-   BaseOffsetPageNumber = (UINTN)EFI_SIZE_TO_PAGES((UINT32)(ImageBase - DxeCodeBase));
-   TopOffsetPageNumber  = (UINTN)EFI_SIZE_TO_PAGES((UINT32)(ImageBase + ImageSize - DxeCodeBase));
+   BaseOffsetPageNumber = EFI_SIZE_TO_PAGES((UINT32)(ImageBase - DxeCodeBase));
+   TopOffsetPageNumber  = EFI_SIZE_TO_PAGES((UINT32)(ImageBase + ImageSize - DxeCodeBase));
    for (Index = BaseOffsetPageNumber; Index < TopOffsetPageNumber; Index ++) {
      if ((mDxeCodeMemoryRangeUsageBitMap[Index / 64] & LShiftU64(1, (Index % 64))) != 0) {
        //
@@ -366,12 +366,10 @@ GetPeCoffImageFixLoadingAssignedAddress(
    //
    Handle = (IMAGE_FILE_HANDLE*)ImageContext->Handle;
    ImgHdr = (EFI_IMAGE_OPTIONAL_HEADER_UNION *)((CHAR8* )Handle->Source + ImageContext->PeCoffHeaderOffset);
-   SectionHeaderOffset = (UINTN)(
-                                 ImageContext->PeCoffHeaderOffset +
-                                 sizeof (UINT32) +
-                                 sizeof (EFI_IMAGE_FILE_HEADER) +
-                                 ImgHdr->Pe32.FileHeader.SizeOfOptionalHeader
-                                 );
+   SectionHeaderOffset = ImageContext->PeCoffHeaderOffset +
+                         sizeof (UINT32) +
+                         sizeof (EFI_IMAGE_FILE_HEADER) +
+                         ImgHdr->Pe32.FileHeader.SizeOfOptionalHeader;
    NumberOfSections = ImgHdr->Pe32.FileHeader.NumberOfSections;
 
    //
diff --git a/MdeModulePkg/Core/Dxe/Misc/DebugImageInfo.c b/MdeModulePkg/Core/Dxe/Misc/DebugImageInfo.c
index 4766072..fda6d44 100644
--- a/MdeModulePkg/Core/Dxe/Misc/DebugImageInfo.c
+++ b/MdeModulePkg/Core/Dxe/Misc/DebugImageInfo.c
@@ -2,7 +2,7 @@
   Support functions for managing debug image info table when loading and unloading
   images.
 
-Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2006 - 2017, Intel Corporation. All rights reserved.<BR>
 This program and the accompanying materials
 are licensed and made available under the terms and conditions of the BSD License
 which accompanies this distribution.  The full text of the license may be found at
@@ -103,7 +103,7 @@ CoreInitializeDebugImageInfoTable (
     Status = CoreFreePages (Memory, UnalignedPages);
     ASSERT_EFI_ERROR (Status);
   }
-  Memory         = (EFI_PHYSICAL_ADDRESS)(AlignedMemory + EFI_PAGES_TO_SIZE (Pages));
+  Memory         = AlignedMemory + EFI_PAGES_TO_SIZE (Pages);
   UnalignedPages = RealPages - Pages - UnalignedPages;
   if (UnalignedPages > 0) {
     //
diff --git a/MdeModulePkg/Core/Pei/Image/Image.c b/MdeModulePkg/Core/Pei/Image/Image.c
index d659de8..381a23f 100644
--- a/MdeModulePkg/Core/Pei/Image/Image.c
+++ b/MdeModulePkg/Core/Pei/Image/Image.c
@@ -1,7 +1,7 @@
 /** @file
   Pei Core Load Image Support
 
-Copyright (c) 2006 - 2016, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2006 - 2017, Intel Corporation. All rights reserved.<BR>
 This program and the accompanying materials
 are licensed and made available under the terms and conditions of the BSD License
 which accompanies this distribution.  The full text of the license may be found at
@@ -250,12 +250,10 @@ GetPeCoffImageFixLoadingAssignedAddress(
      SectionHeaderOffset = sizeof (EFI_TE_IMAGE_HEADER);
      NumberOfSections = ImgHdr->Te.NumberOfSections;
    } else {
-     SectionHeaderOffset = (UINTN)(
-                                 ImageContext->PeCoffHeaderOffset +
-                                 sizeof (UINT32) +
-                                 sizeof (EFI_IMAGE_FILE_HEADER) +
-                                 ImgHdr->Pe32.FileHeader.SizeOfOptionalHeader
-                                 );
+     SectionHeaderOffset = ImageContext->PeCoffHeaderOffset +
+                           sizeof (UINT32) +
+                           sizeof (EFI_IMAGE_FILE_HEADER) +
+                           ImgHdr->Pe32.FileHeader.SizeOfOptionalHeader;
       NumberOfSections = ImgHdr->Pe32.FileHeader.NumberOfSections;
    }
    //
diff --git a/MdeModulePkg/Core/PiSmmCore/Dispatcher.c b/MdeModulePkg/Core/PiSmmCore/Dispatcher.c
index 1bddaf1..b2a6822 100644
--- a/MdeModulePkg/Core/PiSmmCore/Dispatcher.c
+++ b/MdeModulePkg/Core/PiSmmCore/Dispatcher.c
@@ -28,7 +28,7 @@
   Depex - Dependency Expresion.
 
   Copyright (c) 2014, Hewlett-Packard Development Company, L.P.
-  Copyright (c) 2009 - 2016, Intel Corporation. All rights reserved.<BR>
+  Copyright (c) 2009 - 2017, Intel Corporation. All rights reserved.<BR>
   This program and the accompanying materials are licensed and made available 
   under the terms and conditions of the BSD License which accompanies this 
   distribution.  The full text of the license may be found at        
@@ -183,8 +183,8 @@ CheckAndMarkFixLoadingMemoryUsageBitMap (
    //
    // Test if the memory is avalaible or not.
    // 
-   BaseOffsetPageNumber = (UINTN)EFI_SIZE_TO_PAGES((UINT32)(ImageBase - SmmCodeBase));
-   TopOffsetPageNumber  = (UINTN)EFI_SIZE_TO_PAGES((UINT32)(ImageBase + ImageSize - SmmCodeBase));
+   BaseOffsetPageNumber = EFI_SIZE_TO_PAGES((UINT32)(ImageBase - SmmCodeBase));
+   TopOffsetPageNumber  = EFI_SIZE_TO_PAGES((UINT32)(ImageBase + ImageSize - SmmCodeBase));
    for (Index = BaseOffsetPageNumber; Index < TopOffsetPageNumber; Index ++) {
      if ((mSmmCodeMemoryRangeUsageBitMap[Index / 64] & LShiftU64(1, (Index % 64))) != 0) {
        //
@@ -234,12 +234,10 @@ GetPeCoffImageFixLoadingAssignedAddress(
   // Get PeHeader pointer
   //
   ImgHdr = (EFI_IMAGE_OPTIONAL_HEADER_UNION *)((CHAR8* )ImageContext->Handle + ImageContext->PeCoffHeaderOffset);
-  SectionHeaderOffset = (UINTN)(
-                                 ImageContext->PeCoffHeaderOffset +
-                                 sizeof (UINT32) +
-                                 sizeof (EFI_IMAGE_FILE_HEADER) +
-                                 ImgHdr->Pe32.FileHeader.SizeOfOptionalHeader
-                                 );
+  SectionHeaderOffset = ImageContext->PeCoffHeaderOffset +
+                        sizeof (UINT32) +
+                        sizeof (EFI_IMAGE_FILE_HEADER) +
+                        ImgHdr->Pe32.FileHeader.SizeOfOptionalHeader;
   NumberOfSections = ImgHdr->Pe32.FileHeader.NumberOfSections;
 
   //
@@ -520,7 +518,7 @@ SmmLoadImage (
   // Align buffer on section boundary
   //
   ImageContext.ImageAddress += ImageContext.SectionAlignment - 1;
-  ImageContext.ImageAddress &= ~((EFI_PHYSICAL_ADDRESS)(ImageContext.SectionAlignment - 1));
+  ImageContext.ImageAddress &= ~((EFI_PHYSICAL_ADDRESS)ImageContext.SectionAlignment - 1);
 
   //
   // Load the image to our new buffer
diff --git a/MdeModulePkg/Core/PiSmmCore/PiSmmIpl.c b/MdeModulePkg/Core/PiSmmCore/PiSmmIpl.c
index 26b71f1..feb846e 100644
--- a/MdeModulePkg/Core/PiSmmCore/PiSmmIpl.c
+++ b/MdeModulePkg/Core/PiSmmCore/PiSmmIpl.c
@@ -846,12 +846,10 @@ GetPeCoffImageFixLoadingAssignedAddress(
    // Get PeHeader pointer
    //
    ImgHdr = (EFI_IMAGE_OPTIONAL_HEADER_UNION *)((CHAR8* )ImageContext->Handle + ImageContext->PeCoffHeaderOffset);
-   SectionHeaderOffset = (UINTN)(
-                                 ImageContext->PeCoffHeaderOffset +
-                                 sizeof (UINT32) +
-                                 sizeof (EFI_IMAGE_FILE_HEADER) +
-                                 ImgHdr->Pe32.FileHeader.SizeOfOptionalHeader
-                                 );
+   SectionHeaderOffset = ImageContext->PeCoffHeaderOffset +
+                         sizeof (UINT32) +
+                         sizeof (EFI_IMAGE_FILE_HEADER) +
+                         ImgHdr->Pe32.FileHeader.SizeOfOptionalHeader;
    NumberOfSections = ImgHdr->Pe32.FileHeader.NumberOfSections;
 
    //
@@ -1022,7 +1020,7 @@ ExecuteSmmCoreFromSmram (
   }
   
   ImageContext.ImageAddress += ImageContext.SectionAlignment - 1;
-  ImageContext.ImageAddress &= ~((EFI_PHYSICAL_ADDRESS)(ImageContext.SectionAlignment - 1));
+  ImageContext.ImageAddress &= ~((EFI_PHYSICAL_ADDRESS)ImageContext.SectionAlignment - 1);
 
   //
   // Print debug message showing SMM Core load address.
diff --git a/MdeModulePkg/Library/DxeCapsuleLibFmp/DxeCapsuleLib.c b/MdeModulePkg/Library/DxeCapsuleLibFmp/DxeCapsuleLib.c
index d7abcc8..7f500a9 100644
--- a/MdeModulePkg/Library/DxeCapsuleLibFmp/DxeCapsuleLib.c
+++ b/MdeModulePkg/Library/DxeCapsuleLibFmp/DxeCapsuleLib.c
@@ -585,7 +585,7 @@ DisplayCapsuleImage (
   EFI_GRAPHICS_OUTPUT_PROTOCOL  *GraphicsOutput;
 
   ImagePayload = (DISPLAY_DISPLAY_PAYLOAD *)(CapsuleHeader + 1);
-  PayloadSize = (UINTN)(CapsuleHeader->CapsuleImageSize - sizeof(EFI_CAPSULE_HEADER));
+  PayloadSize = CapsuleHeader->CapsuleImageSize - sizeof(EFI_CAPSULE_HEADER);
 
   if (ImagePayload->Version != 1) {
     return EFI_UNSUPPORTED;
@@ -733,7 +733,7 @@ DumpFmpCapsule (
   for (Index = 0; Index < FmpCapsuleHeader->EmbeddedDriverCount; Index++) {
     DEBUG((DEBUG_VERBOSE, "  ItemOffsetList[%d]      - 0x%lx\n", Index, ItemOffsetList[Index]));
   }
-  for (; Index < (UINTN)(FmpCapsuleHeader->EmbeddedDriverCount + FmpCapsuleHeader->PayloadItemCount); Index++) {
+  for (; Index < (UINT32)FmpCapsuleHeader->EmbeddedDriverCount + FmpCapsuleHeader->PayloadItemCount; Index++) {
     DEBUG((DEBUG_VERBOSE, "  ItemOffsetList[%d]      - 0x%lx\n", Index, ItemOffsetList[Index]));
     ImageHeader = (EFI_FIRMWARE_MANAGEMENT_CAPSULE_IMAGE_HEADER *)((UINT8 *)FmpCapsuleHeader + ItemOffsetList[Index]);
 
diff --git a/MdeModulePkg/Library/DxeCoreMemoryAllocationLib/MemoryAllocationLib.c b/MdeModulePkg/Library/DxeCoreMemoryAllocationLib/MemoryAllocationLib.c
index 89c19e7..95725c8 100644
--- a/MdeModulePkg/Library/DxeCoreMemoryAllocationLib/MemoryAllocationLib.c
+++ b/MdeModulePkg/Library/DxeCoreMemoryAllocationLib/MemoryAllocationLib.c
@@ -3,7 +3,7 @@
   on DxeCore Memory Allocation services for DxeCore,
   with memory profile support.
 
-  Copyright (c) 2006 - 2016, Intel Corporation. All rights reserved.<BR>
+  Copyright (c) 2006 - 2017, Intel Corporation. All rights reserved.<BR>
   This program and the accompanying materials                          
   are licensed and made available under the terms and conditions of the BSD License         
   which accompanies this distribution.  The full text of the license may be found at        
@@ -258,7 +258,7 @@ InternalAllocateAlignedPages (
       Status = CoreFreePages (Memory, UnalignedPages);
       ASSERT_EFI_ERROR (Status);
     }
-    Memory         = (EFI_PHYSICAL_ADDRESS) (AlignedMemory + EFI_PAGES_TO_SIZE (Pages));
+    Memory         = AlignedMemory + EFI_PAGES_TO_SIZE (Pages);
     UnalignedPages = RealPages - Pages - UnalignedPages;
     if (UnalignedPages > 0) {
       //
diff --git a/MdeModulePkg/Library/DxeNetLib/DxeNetLib.c b/MdeModulePkg/Library/DxeNetLib/DxeNetLib.c
index 0a7117c..c015aa6 100644
--- a/MdeModulePkg/Library/DxeNetLib/DxeNetLib.c
+++ b/MdeModulePkg/Library/DxeNetLib/DxeNetLib.c
@@ -1,7 +1,7 @@
 /** @file
   Network library.
 
-Copyright (c) 2005 - 2016, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2005 - 2017, Intel Corporation. All rights reserved.<BR>
 (C) Copyright 2015 Hewlett Packard Enterprise Development LP<BR>
 This program and the accompanying materials
 are licensed and made available under the terms and conditions of the BSD License
@@ -3299,7 +3299,7 @@ NetLibGetSystemGuid (
       return EFI_NOT_FOUND;
     }
     Smbios.Hdr    = (SMBIOS_STRUCTURE *) (UINTN) SmbiosTable->TableAddress;
-    SmbiosEnd.Raw = (UINT8 *) (UINTN) (SmbiosTable->TableAddress + SmbiosTable->TableLength);
+    SmbiosEnd.Raw = (UINT8 *) ((UINTN) SmbiosTable->TableAddress + SmbiosTable->TableLength);
   }
 
   do {
diff --git a/MdeModulePkg/Library/PiDxeS3BootScriptLib/BootScriptSave.c b/MdeModulePkg/Library/PiDxeS3BootScriptLib/BootScriptSave.c
index 1f8aaf4..fe2d3a0 100644
--- a/MdeModulePkg/Library/PiDxeS3BootScriptLib/BootScriptSave.c
+++ b/MdeModulePkg/Library/PiDxeS3BootScriptLib/BootScriptSave.c
@@ -691,7 +691,7 @@ S3BootScriptGetBootTimeEntryAddAddress (
    // Here we do not count the reserved memory for runtime script table.
    PageNumber = (UINT16) (mS3BootScriptTablePtr->TableMemoryPageNumber - PcdGet16(PcdS3BootScriptRuntimeTableReservePageNumber));
    TableLength =  mS3BootScriptTablePtr->TableLength;
-   if ((UINTN) EFI_PAGES_TO_SIZE ((UINTN) PageNumber) < (UINTN) (TableLength + EntryLength + sizeof (EFI_BOOT_SCRIPT_TERMINATE))) {
+   if (EFI_PAGES_TO_SIZE ((UINTN) PageNumber) < (TableLength + EntryLength + sizeof (EFI_BOOT_SCRIPT_TERMINATE))) {
      //
      // The buffer is too small to hold the table, Reallocate the buffer
      //
@@ -752,7 +752,7 @@ S3BootScriptGetRuntimeEntryAddAddress (
    //
    // Check if the memory range reserved for S3 Boot Script table is large enough to hold the node.
    //
-   if ((UINTN) (mS3BootScriptTablePtr->TableLength + EntryLength + sizeof (EFI_BOOT_SCRIPT_TERMINATE)) <= (UINTN) EFI_PAGES_TO_SIZE ((UINTN) (mS3BootScriptTablePtr->TableMemoryPageNumber))) {
+   if ((mS3BootScriptTablePtr->TableLength + EntryLength + sizeof (EFI_BOOT_SCRIPT_TERMINATE)) <= EFI_PAGES_TO_SIZE ((UINTN) (mS3BootScriptTablePtr->TableMemoryPageNumber))) {
      NewEntryPtr = mS3BootScriptTablePtr->TableBase + mS3BootScriptTablePtr->TableLength;
      mS3BootScriptTablePtr->TableLength = mS3BootScriptTablePtr->TableLength + EntryLength;
      //
diff --git a/MdeModulePkg/Library/PiSmmCoreMemoryAllocationLib/MemoryAllocationLib.c b/MdeModulePkg/Library/PiSmmCoreMemoryAllocationLib/MemoryAllocationLib.c
index bd21468..96cb275 100644
--- a/MdeModulePkg/Library/PiSmmCoreMemoryAllocationLib/MemoryAllocationLib.c
+++ b/MdeModulePkg/Library/PiSmmCoreMemoryAllocationLib/MemoryAllocationLib.c
@@ -11,7 +11,7 @@
   In addition, allocation for the Reserved memory types are not supported and will 
   always return NULL.
 
-  Copyright (c) 2006 - 2016, Intel Corporation. All rights reserved.<BR>
+  Copyright (c) 2006 - 2017, Intel Corporation. All rights reserved.<BR>
   This program and the accompanying materials                          
   are licensed and made available under the terms and conditions of the BSD License         
   which accompanies this distribution.  The full text of the license may be found at        
@@ -293,7 +293,7 @@ InternalAllocateAlignedPages (
       Status = SmmFreePages (Memory, UnalignedPages);
       ASSERT_EFI_ERROR (Status);
     }
-    Memory         = (EFI_PHYSICAL_ADDRESS) (AlignedMemory + EFI_PAGES_TO_SIZE (Pages));
+    Memory         = AlignedMemory + EFI_PAGES_TO_SIZE (Pages);
     UnalignedPages = RealPages - Pages - UnalignedPages;
     if (UnalignedPages > 0) {
       //
diff --git a/MdeModulePkg/Library/SmmMemoryAllocationProfileLib/MemoryAllocationLib.c b/MdeModulePkg/Library/SmmMemoryAllocationProfileLib/MemoryAllocationLib.c
index e9bbf02..2a18155 100644
--- a/MdeModulePkg/Library/SmmMemoryAllocationProfileLib/MemoryAllocationLib.c
+++ b/MdeModulePkg/Library/SmmMemoryAllocationProfileLib/MemoryAllocationLib.c
@@ -12,7 +12,7 @@
   allocation for the Reserved memory types are not supported and will always 
   return NULL.
 
-  Copyright (c) 2006 - 2016, Intel Corporation. All rights reserved.<BR>
+  Copyright (c) 2006 - 2017, Intel Corporation. All rights reserved.<BR>
   This program and the accompanying materials                          
   are licensed and made available under the terms and conditions of the BSD License         
   which accompanies this distribution.  The full text of the license may be found at        
@@ -371,7 +371,7 @@ InternalAllocateAlignedPages (
       Status = gSmst->SmmFreePages (Memory, UnalignedPages);
       ASSERT_EFI_ERROR (Status);
     }
-    Memory         = (EFI_PHYSICAL_ADDRESS) (AlignedMemory + EFI_PAGES_TO_SIZE (Pages));
+    Memory         = AlignedMemory + EFI_PAGES_TO_SIZE (Pages);
     UnalignedPages = RealPages - Pages - UnalignedPages;
     if (UnalignedPages > 0) {
       //
diff --git a/MdeModulePkg/Library/UefiBootManagerLib/BmMisc.c b/MdeModulePkg/Library/UefiBootManagerLib/BmMisc.c
index e11d842..11ab867 100644
--- a/MdeModulePkg/Library/UefiBootManagerLib/BmMisc.c
+++ b/MdeModulePkg/Library/UefiBootManagerLib/BmMisc.c
@@ -413,11 +413,11 @@ BmCharToUint (
   )
 {
   if ((Char >= L'0') && (Char <= L'9')) {
-    return (UINTN) (Char - L'0');
+    return (Char - L'0');
   }
 
   if ((Char >= L'A') && (Char <= L'F')) {
-    return (UINTN) (Char - L'A' + 0xA);
+    return (Char - L'A' + 0xA);
   }
 
   ASSERT (FALSE);
diff --git a/MdeModulePkg/Library/UefiHiiLib/HiiLib.c b/MdeModulePkg/Library/UefiHiiLib/HiiLib.c
index 8579501..0b5b0a9 100644
--- a/MdeModulePkg/Library/UefiHiiLib/HiiLib.c
+++ b/MdeModulePkg/Library/UefiHiiLib/HiiLib.c
@@ -1,7 +1,7 @@
 /** @file
   HII Library implementation that uses DXE protocols and services.
 
-  Copyright (c) 2006 - 2016, Intel Corporation. All rights reserved.<BR>
+  Copyright (c) 2006 - 2017, Intel Corporation. All rights reserved.<BR>
   This program and the accompanying materials
   are licensed and made available under the terms and conditions of the BSD License
   which accompanies this distribution.  The full text of the license may be found at
@@ -1853,7 +1853,7 @@ GetBlockDataInfo (
     //
     // Check whether VarBuffer is enough
     //
-    if ((UINTN) (Offset + Width) > MaxBufferSize) {
+    if ((UINT32)Offset + Width > MaxBufferSize) {
       DataBuffer = ReallocatePool (
                     MaxBufferSize,
                     Offset + Width + HII_LIB_DEFAULT_VARSTORE_SIZE,
diff --git a/MdeModulePkg/Library/UefiMemoryAllocationProfileLib/MemoryAllocationLib.c b/MdeModulePkg/Library/UefiMemoryAllocationProfileLib/MemoryAllocationLib.c
index 370827d..cef7fc0 100644
--- a/MdeModulePkg/Library/UefiMemoryAllocationProfileLib/MemoryAllocationLib.c
+++ b/MdeModulePkg/Library/UefiMemoryAllocationProfileLib/MemoryAllocationLib.c
@@ -2,7 +2,7 @@
   Support routines for memory allocation routines based 
   on boot services for Dxe phase drivers, with memory profile support.
 
-  Copyright (c) 2006 - 2016, Intel Corporation. All rights reserved.<BR>
+  Copyright (c) 2006 - 2017, Intel Corporation. All rights reserved.<BR>
   This program and the accompanying materials                          
   are licensed and made available under the terms and conditions of the BSD License         
   which accompanies this distribution.  The full text of the license may be found at        
@@ -257,7 +257,7 @@ InternalAllocateAlignedPages (
       Status = gBS->FreePages (Memory, UnalignedPages);
       ASSERT_EFI_ERROR (Status);
     }
-    Memory         = (EFI_PHYSICAL_ADDRESS) (AlignedMemory + EFI_PAGES_TO_SIZE (Pages));
+    Memory         = AlignedMemory + EFI_PAGES_TO_SIZE (Pages);
     UnalignedPages = RealPages - Pages - UnalignedPages;
     if (UnalignedPages > 0) {
       //
diff --git a/MdeModulePkg/Library/VarCheckHiiLib/VarCheckHiiLibNullClass.c b/MdeModulePkg/Library/VarCheckHiiLib/VarCheckHiiLibNullClass.c
index b9ca908..93ff934 100644
--- a/MdeModulePkg/Library/VarCheckHiiLib/VarCheckHiiLibNullClass.c
+++ b/MdeModulePkg/Library/VarCheckHiiLib/VarCheckHiiLibNullClass.c
@@ -1,7 +1,7 @@
 /** @file
   Var Check Hii handler.
 
-Copyright (c) 2015, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2015 - 2017, Intel Corporation. All rights reserved.<BR>
 This program and the accompanying materials
 are licensed and made available under the terms and conditions of the BSD License
 which accompanies this distribution.  The full text of the license may be found at
@@ -94,7 +94,7 @@ VarCheckHiiQuestion (
   UINT8    Index;
   UINT8    MaxContainers;
 
-  if ((UINTN) (HiiQuestion->VarOffset + HiiQuestion->StorageWidth) > DataSize) {
+  if (((UINT32) HiiQuestion->VarOffset + HiiQuestion->StorageWidth) > DataSize) {
     DEBUG ((EFI_D_INFO, "VarCheckHiiQuestion fail: (VarOffset(0x%04x) + StorageWidth(0x%02x)) > Size(0x%x)\n", HiiQuestion->VarOffset, HiiQuestion->StorageWidth, DataSize));
     return FALSE;
   }
@@ -155,7 +155,7 @@ VarCheckHiiQuestion (
 
     case EFI_IFR_ORDERED_LIST_OP:
       MaxContainers = ((VAR_CHECK_HII_QUESTION_ORDEREDLIST *) HiiQuestion)->MaxContainers;
-      if ((UINTN) (HiiQuestion->VarOffset + HiiQuestion->StorageWidth * MaxContainers) > DataSize) {
+      if (((UINT32) HiiQuestion->VarOffset + HiiQuestion->StorageWidth * MaxContainers) > DataSize) {
         DEBUG ((EFI_D_INFO, "VarCheckHiiQuestion fail: (VarOffset(0x%04x) + StorageWidth(0x%02x) * MaxContainers(0x%02x)) > Size(0x%x)\n", HiiQuestion->VarOffset, HiiQuestion->StorageWidth, MaxContainers, DataSize));
         return FALSE;
       }
diff --git a/MdeModulePkg/Universal/Acpi/BootScriptExecutorDxe/ScriptExecute.c b/MdeModulePkg/Universal/Acpi/BootScriptExecutorDxe/ScriptExecute.c
index f67fbca..16551ae 100644
--- a/MdeModulePkg/Universal/Acpi/BootScriptExecutorDxe/ScriptExecute.c
+++ b/MdeModulePkg/Universal/Acpi/BootScriptExecutorDxe/ScriptExecute.c
@@ -4,7 +4,7 @@
   This driver is dispatched by Dxe core and the driver will reload itself to ACPI reserved memory
   in the entry point. The functionality is to interpret and restore the S3 boot script
 
-Copyright (c) 2006 - 2016, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2006 - 2017, Intel Corporation. All rights reserved.<BR>
 
 This program and the accompanying materials
 are licensed and made available under the terms and conditions of the BSD License
@@ -325,7 +325,7 @@ ReadyToLockEventNotify (
   // Align buffer on section boundary
   //
   ImageContext.ImageAddress += ImageContext.SectionAlignment - 1;
-  ImageContext.ImageAddress &= ~((EFI_PHYSICAL_ADDRESS)(ImageContext.SectionAlignment - 1));
+  ImageContext.ImageAddress &= ~((EFI_PHYSICAL_ADDRESS)ImageContext.SectionAlignment - 1);
   //
   // Load the image to our new buffer
   //
diff --git a/MdeModulePkg/Universal/Acpi/S3SaveStateDxe/AcpiS3ContextSave.c b/MdeModulePkg/Universal/Acpi/S3SaveStateDxe/AcpiS3ContextSave.c
index a973d2d..dcfd61c 100644
--- a/MdeModulePkg/Universal/Acpi/S3SaveStateDxe/AcpiS3ContextSave.c
+++ b/MdeModulePkg/Universal/Acpi/S3SaveStateDxe/AcpiS3ContextSave.c
@@ -1,7 +1,7 @@
 /** @file
   This is the implementation to save ACPI S3 Context.
 
-Copyright (c) 2006 - 2016, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2006 - 2017, Intel Corporation. All rights reserved.<BR>
 
 This program and the accompanying materials
 are licensed and made available under the terms and conditions
@@ -401,9 +401,9 @@ S3AllocatePageTablesBuffer (
     // We need calculate whole page size then allocate once, because S3 restore page table does not know each page in Nvs.
     //
     if (!Page1GSupport) {
-      TotalPageTableSize = (UINTN)(1 + NumberOfPml4EntriesNeeded + NumberOfPml4EntriesNeeded * NumberOfPdpEntriesNeeded);
+      TotalPageTableSize = 1 + NumberOfPml4EntriesNeeded + NumberOfPml4EntriesNeeded * NumberOfPdpEntriesNeeded;
     } else {
-      TotalPageTableSize = (UINTN)(1 + NumberOfPml4EntriesNeeded);
+      TotalPageTableSize = 1 + NumberOfPml4EntriesNeeded;
     }
 
     TotalPageTableSize += ExtraPageTablePages;
diff --git a/MdeModulePkg/Universal/CapsulePei/Common/CapsuleCoalesce.c b/MdeModulePkg/Universal/CapsulePei/Common/CapsuleCoalesce.c
index 9e8315e..3e7054c 100644
--- a/MdeModulePkg/Universal/CapsulePei/Common/CapsuleCoalesce.c
+++ b/MdeModulePkg/Universal/CapsulePei/Common/CapsuleCoalesce.c
@@ -10,7 +10,7 @@
   into memory.
 
 (C) Copyright 2014 Hewlett-Packard Development Company, L.P.<BR>
-Copyright (c) 2011 - 2016, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2011 - 2017, Intel Corporation. All rights reserved.<BR>
 This program and the accompanying materials
 are licensed and made available under the terms and conditions of the BSD License
 which accompanies this distribution.  The full text of the license may be found at
@@ -1247,7 +1247,7 @@ CapsuleDataCoalesce (
         //
         ASSERT (PrivateDataPtr->Signature == EFI_CAPSULE_PEIM_PRIVATE_DATA_SIGNATURE);
         ASSERT ((UINTN)DestPtr >= (UINTN)CapsuleImageBase);
-        PrivateDataPtr->CapsuleOffset[CapsuleIndex++] = (UINT64)((UINTN)DestPtr - (UINTN)CapsuleImageBase);
+        PrivateDataPtr->CapsuleOffset[CapsuleIndex++] = (UINTN)DestPtr - (UINTN)CapsuleImageBase;
       }
 
       //
diff --git a/MdeModulePkg/Universal/DisplayEngineDxe/FormDisplay.c b/MdeModulePkg/Universal/DisplayEngineDxe/FormDisplay.c
index 0eb7ddd..e1ac5a3 100644
--- a/MdeModulePkg/Universal/DisplayEngineDxe/FormDisplay.c
+++ b/MdeModulePkg/Universal/DisplayEngineDxe/FormDisplay.c
@@ -1,7 +1,7 @@
 /** @file
 Entry and initialization module for the browser.
 
-Copyright (c) 2007 - 2016, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2007 - 2017, Intel Corporation. All rights reserved.<BR>
 Copyright (c) 2014, Hewlett-Packard Development Company, L.P.<BR>
 This program and the accompanying materials
 are licensed and made available under the terms and conditions of the BSD License
@@ -540,7 +540,7 @@ GetLineByWidth (
   //
   // Need extra glyph info and '\0' info, so +2.
   //
-  *OutputString = AllocateZeroPool (((UINTN) (StrOffset + 2) * sizeof(CHAR16)));
+  *OutputString = AllocateZeroPool ((StrOffset + 2) * sizeof(CHAR16));
   if (*OutputString == NULL) {
     return 0;
   }
@@ -2972,7 +2972,7 @@ UiDisplayMenu (
         gST->ConOut->SetAttribute (gST->ConOut, GetInfoTextColor ());
         for (Index = 0; Index < HelpHeaderLine; Index++) {
           ASSERT (HelpHeaderLine == 1);
-          ASSERT (GetStringWidth (HelpHeaderString) / 2 < (UINTN) (gHelpBlockWidth - 1));
+          ASSERT (GetStringWidth (HelpHeaderString) / 2 < ((UINT32) gHelpBlockWidth - 1));
           PrintStringAtWithWidth (
             gStatementDimensions.RightColumn - gHelpBlockWidth,
             Index + TopRow,
@@ -3053,7 +3053,7 @@ UiDisplayMenu (
         gST->ConOut->SetAttribute (gST->ConOut, GetInfoTextColor ());
         for (Index = 0; Index < HelpBottomLine; Index++) {
           ASSERT (HelpBottomLine == 1);
-          ASSERT (GetStringWidth (HelpBottomString) / 2 < (UINTN) (gHelpBlockWidth - 1)); 
+          ASSERT (GetStringWidth (HelpBottomString) / 2 < ((UINT32) gHelpBlockWidth - 1));
           PrintStringAtWithWidth (
             gStatementDimensions.RightColumn - gHelpBlockWidth,
             BottomRow + Index - HelpBottomLine + 1,
diff --git a/MdeModulePkg/Universal/EbcDxe/EbcExecute.c b/MdeModulePkg/Universal/EbcDxe/EbcExecute.c
index e5d290a..2dfed8e 100644
--- a/MdeModulePkg/Universal/EbcDxe/EbcExecute.c
+++ b/MdeModulePkg/Universal/EbcDxe/EbcExecute.c
@@ -1,7 +1,7 @@
 /** @file
   Contains code that implements the virtual machine.
 
-Copyright (c) 2006 - 2014, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2006 - 2017, Intel Corporation. All rights reserved.<BR>
 This program and the accompanying materials
 are licensed and made available under the terms and conditions of the BSD License
 which accompanies this distribution.  The full text of the license may be found at
@@ -2867,7 +2867,7 @@ ExecutePOPn (
   if (OPERAND1_INDIRECT (Operands)) {
     VmWriteMemN (VmPtr, (UINTN) (VmPtr->Gpr[OPERAND1_REGNUM (Operands)] + Index16), DataN);
   } else {
-    VmPtr->Gpr[OPERAND1_REGNUM (Operands)] = (INT64) (UINT64) ((UINTN) DataN + Index16);
+    VmPtr->Gpr[OPERAND1_REGNUM (Operands)] = (INT64) (UINT64) (UINTN) (DataN + Index16);
   }
 
   return EFI_SUCCESS;
@@ -3592,7 +3592,7 @@ ExecuteSUB (
   if ((*VmPtr->Ip & DATAMANIP_M_64) != 0) {
     return (UINT64) ((INT64) ((INT64) Op1 - (INT64) Op2));
   } else {
-    return (UINT64) ((INT64) ((INT32) Op1 - (INT32) Op2));
+    return (UINT64) ((INT64) ((INT32) ((INT32) Op1 - (INT32) Op2)));
   }
 }
 
@@ -3620,7 +3620,7 @@ ExecuteMUL (
   if ((*VmPtr->Ip & DATAMANIP_M_64) != 0) {
     return MultS64x64 ((INT64)Op1, (INT64)Op2);
   } else {
-    return (UINT64) ((INT64) ((INT32) Op1 * (INT32) Op2));
+    return (UINT64) ((INT64) ((INT32) ((INT32) Op1 * (INT32) Op2)));
   }
 }
 
@@ -3648,7 +3648,7 @@ ExecuteMULU (
   if ((*VmPtr->Ip & DATAMANIP_M_64) != 0) {
     return MultU64x64 (Op1, Op2);
   } else {
-    return (UINT64) ((UINT32) Op1 * (UINT32) Op2);
+    return (UINT64) ((UINT32) ((UINT32) Op1 * (UINT32) Op2));
   }
 }
 
diff --git a/MdeModulePkg/Universal/FaultTolerantWriteDxe/UpdateWorkingBlock.c b/MdeModulePkg/Universal/FaultTolerantWriteDxe/UpdateWorkingBlock.c
index d46a37f..b4327b5 100644
--- a/MdeModulePkg/Universal/FaultTolerantWriteDxe/UpdateWorkingBlock.c
+++ b/MdeModulePkg/Universal/FaultTolerantWriteDxe/UpdateWorkingBlock.c
@@ -2,7 +2,7 @@
 
    Internal functions to operate Working Block Space.
 
-Copyright (c) 2006 - 2015, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2006 - 2017, Intel Corporation. All rights reserved.<BR>
 This program and the accompanying materials                          
 are licensed and made available under the terms and conditions of the BSD License         
 which accompanies this distribution.  The full text of the license may be found at        
@@ -55,7 +55,7 @@ InitializeLocalWorkSpaceHeader (
     &gEdkiiWorkingBlockSignatureGuid,
     sizeof (EFI_GUID)
     );
-  mWorkingBlockHeader.WriteQueueSize = (UINT64) (PcdGet32 (PcdFlashNvStorageFtwWorkingSize) - sizeof (EFI_FAULT_TOLERANT_WORKING_BLOCK_HEADER));
+  mWorkingBlockHeader.WriteQueueSize = PcdGet32 (PcdFlashNvStorageFtwWorkingSize) - sizeof (EFI_FAULT_TOLERANT_WORKING_BLOCK_HEADER);
 
   //
   // Crc is calculated with all the fields except Crc and STATE, so leave them as FTW_ERASED_BYTE.
diff --git a/MdeModulePkg/Universal/HiiDatabaseDxe/Font.c b/MdeModulePkg/Universal/HiiDatabaseDxe/Font.c
index 9bef064..b85cf88 100644
--- a/MdeModulePkg/Universal/HiiDatabaseDxe/Font.c
+++ b/MdeModulePkg/Universal/HiiDatabaseDxe/Font.c
@@ -2,7 +2,7 @@
 Implementation for EFI_HII_FONT_PROTOCOL.
 
 
-Copyright (c) 2007 - 2016, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2007 - 2017, Intel Corporation. All rights reserved.<BR>
 This program and the accompanying materials
 are licensed and made available under the terms and conditions of the BSD License
 which accompanies this distribution.  The full text of the license may be found at
@@ -411,7 +411,7 @@ GlyphToBlt (
   // The glyph's upper left hand corner pixel is the most significant bit of the
   // first bitmap byte.
   //
-  for (Ypos = 0; Ypos < Cell->Height && ((UINTN) (Ypos + YposOffset) < RowHeight); Ypos++) {
+  for (Ypos = 0; Ypos < Cell->Height && (((UINT32) Ypos + YposOffset) < RowHeight); Ypos++) {
     OffsetY = BITMAP_LEN_1_BIT (Cell->Width, Ypos);
 
     //
@@ -419,7 +419,7 @@ GlyphToBlt (
     //
     for (Xpos = 0; Xpos < Cell->Width / 8; Xpos++) {
       Data  = *(GlyphBuffer + OffsetY + Xpos);
-      for (Index = 0; Index < 8 && ((UINTN) (Xpos * 8 + Index + Cell->OffsetX) < RowWidth); Index++) {
+      for (Index = 0; Index < 8 && (((UINT32) Xpos * 8 + Index + Cell->OffsetX) < RowWidth); Index++) {
         if ((Data & (1 << (8 - Index - 1))) != 0) {
           BltBuffer[Ypos * ImageWidth + Xpos * 8 + Index] = Foreground;
         } else {
@@ -435,7 +435,7 @@ GlyphToBlt (
       // There are some padding bits in this byte. Ignore them.
       //
       Data  = *(GlyphBuffer + OffsetY + Xpos);
-      for (Index = 0; Index < Cell->Width % 8 && ((UINTN) (Xpos * 8 + Index + Cell->OffsetX) < RowWidth); Index++) {
+      for (Index = 0; Index < Cell->Width % 8 && (((UINT32) Xpos * 8 + Index + Cell->OffsetX) < RowWidth); Index++) {
         if ((Data & (1 << (8 - Index - 1))) != 0) {
           BltBuffer[Ypos * ImageWidth + Xpos * 8 + Index] = Foreground;
         } else {
@@ -1927,7 +1927,7 @@ HiiStringToImage (
     // If this character is the last character of a row, we need not
     // draw its (AdvanceX - Width - OffsetX) for next character.
     //
-    LineWidth -= (UINTN) (Cell[Index].AdvanceX - Cell[Index].Width - Cell[Index].OffsetX);
+    LineWidth -= (Cell[Index].AdvanceX - Cell[Index].Width - Cell[Index].OffsetX);
 
     //
     // Clip the right-most character if cannot fit when EFI_HII_OUT_FLAG_CLEAN_X is set.
@@ -1950,8 +1950,8 @@ HiiStringToImage (
         //
         // Don't draw the last char on this row. And, don't draw the second last char (AdvanceX - Width - OffsetX).
         //
-        LineWidth -= (UINTN) (Cell[Index].Width + Cell[Index].OffsetX);
-        LineWidth -= (UINTN) (Cell[Index - 1].AdvanceX - Cell[Index - 1].Width - Cell[Index - 1].OffsetX);
+        LineWidth -= (Cell[Index].Width + Cell[Index].OffsetX);
+        LineWidth -= (Cell[Index - 1].AdvanceX - Cell[Index - 1].Width - Cell[Index - 1].OffsetX);
         RowInfo[RowIndex].EndIndex       = Index - 1;
         RowInfo[RowIndex].LineWidth      = LineWidth;
         RowInfo[RowIndex].LineHeight     = LineHeight;
@@ -2008,7 +2008,7 @@ HiiStringToImage (
           if (Index1 == RowInfo[RowIndex].StartIndex) {
             LineWidth = 0;
           } else {
-            LineWidth -= (UINTN) (Cell[Index1 - 1].AdvanceX - Cell[Index1 - 1].Width - Cell[Index1 - 1].OffsetX);
+            LineWidth -= (Cell[Index1 - 1].AdvanceX - Cell[Index1 - 1].Width - Cell[Index1 - 1].OffsetX);
           }
           RowInfo[RowIndex].LineWidth = LineWidth;
         }
@@ -2025,8 +2025,8 @@ HiiStringToImage (
             //
             // Don't draw the last char on this row. And, don't draw the second last char (AdvanceX - Width - OffsetX).
             //
-            LineWidth -= (UINTN) (Cell[Index1].Width + Cell[Index1].OffsetX);
-            LineWidth -= (UINTN) (Cell[Index1 - 1].AdvanceX - Cell[Index1 - 1].Width - Cell[Index1 - 1].OffsetX);
+            LineWidth -= (Cell[Index1].Width + Cell[Index1].OffsetX);
+            LineWidth -= (Cell[Index1 - 1].AdvanceX - Cell[Index1 - 1].Width - Cell[Index1 - 1].OffsetX);
             RowInfo[RowIndex].EndIndex       = Index1 - 1;
             RowInfo[RowIndex].LineWidth      = LineWidth;
           } else {
diff --git a/MdeModulePkg/Universal/Network/UefiPxeBcDxe/PxeBcImpl.c b/MdeModulePkg/Universal/Network/UefiPxeBcDxe/PxeBcImpl.c
index 639da48..cd00f5c 100644
--- a/MdeModulePkg/Universal/Network/UefiPxeBcDxe/PxeBcImpl.c
+++ b/MdeModulePkg/Universal/Network/UefiPxeBcDxe/PxeBcImpl.c
@@ -1,7 +1,7 @@
 /** @file
   Interface routines for PxeBc.
 
-Copyright (c) 2007 - 2016, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2007 - 2017, Intel Corporation. All rights reserved.<BR>
 This program and the accompanying materials
 are licensed and made available under the terms and conditions of the BSD License
 which accompanies this distribution.  The full text of the license may be found at
@@ -353,8 +353,8 @@ EfiPxeBcStart (
   //
   // Configure block size for TFTP as a default value to handle all link layers.
   // 
-  Private->BlockSize   = (UINTN) (MIN (Private->Ip4MaxPacketSize, PXEBC_DEFAULT_PACKET_SIZE) - 
-                           PXEBC_DEFAULT_UDP_OVERHEAD_SIZE - PXEBC_DEFAULT_TFTP_OVERHEAD_SIZE);
+  Private->BlockSize   = MIN (Private->Ip4MaxPacketSize, PXEBC_DEFAULT_PACKET_SIZE) -
+                           PXEBC_DEFAULT_UDP_OVERHEAD_SIZE - PXEBC_DEFAULT_TFTP_OVERHEAD_SIZE;
   //
   // If PcdTftpBlockSize is set to non-zero, override the default value.
   //
diff --git a/MdeModulePkg/Universal/PCD/Dxe/Service.c b/MdeModulePkg/Universal/PCD/Dxe/Service.c
index bf77130..efe7248 100644
--- a/MdeModulePkg/Universal/PCD/Dxe/Service.c
+++ b/MdeModulePkg/Universal/PCD/Dxe/Service.c
@@ -2,7 +2,7 @@
     Help functions used by PCD DXE driver.
 
 Copyright (c) 2014, Hewlett-Packard Development Company, L.P.<BR>
-Copyright (c) 2006 - 2016, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2006 - 2017, Intel Corporation. All rights reserved.<BR>
 (C) Copyright 2016 Hewlett Packard Enterprise Development LP<BR>
 This program and the accompanying materials
 are licensed and made available under the terms and conditions of the BSD License
@@ -452,7 +452,7 @@ GetWorker (
   switch (LocalTokenNumber & PCD_TYPE_ALL_SET) {
     case PCD_TYPE_VPD:
       VpdHead = (VPD_HEAD *) ((UINT8 *) PcdDb + Offset);
-      RetPtr = (VOID *) (UINTN) (PcdGet32 (PcdVpdBaseAddress) + VpdHead->Offset);
+      RetPtr = (VOID *) ((UINTN) PcdGet32 (PcdVpdBaseAddress) + VpdHead->Offset);
 
       break;
 
diff --git a/MdeModulePkg/Universal/PCD/Pei/Service.c b/MdeModulePkg/Universal/PCD/Pei/Service.c
index 66ca892..5e1cb72 100644
--- a/MdeModulePkg/Universal/PCD/Pei/Service.c
+++ b/MdeModulePkg/Universal/PCD/Pei/Service.c
@@ -2,7 +2,7 @@
   The driver internal functions are implmented here.
   They build Pei PCD database, and provide access service to PCD database.
 
-Copyright (c) 2006 - 2016, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2006 - 2017, Intel Corporation. All rights reserved.<BR>
 This program and the accompanying materials
 are licensed and made available under the terms and conditions of the BSD License
 which accompanies this distribution.  The full text of the license may be found at
@@ -985,7 +985,7 @@ GetWorker (
     {
       VPD_HEAD *VpdHead;
       VpdHead = (VPD_HEAD *) ((UINT8 *)PeiPcdDb + Offset);
-      return (VOID *) (UINTN) (PcdGet32 (PcdVpdBaseAddress) + VpdHead->Offset);
+      return (VOID *) ((UINTN) PcdGet32 (PcdVpdBaseAddress) + VpdHead->Offset);
     }
       
     case PCD_TYPE_HII|PCD_TYPE_STRING:
diff --git a/MdeModulePkg/Universal/SmbiosDxe/SmbiosDxe.c b/MdeModulePkg/Universal/SmbiosDxe/SmbiosDxe.c
index ea762d5..4e757e1 100644
--- a/MdeModulePkg/Universal/SmbiosDxe/SmbiosDxe.c
+++ b/MdeModulePkg/Universal/SmbiosDxe/SmbiosDxe.c
@@ -2,7 +2,7 @@
   This code produces the Smbios protocol. It also responsible for constructing 
   SMBIOS table into system table.
   
-Copyright (c) 2009 - 2016, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2009 - 2017, Intel Corporation. All rights reserved.<BR>
 This program and the accompanying materials                          
 are licensed and made available under the terms and conditions of the BSD License         
 which accompanies this distribution.  The full text of the license may be found at        
@@ -1138,7 +1138,7 @@ SmbiosCreateTable (
     EntryPointStructure->MaxStructureSize = (UINT16) sizeof (EndStructure);
   }
 
-  if ((UINTN) EFI_SIZE_TO_PAGES (EntryPointStructure->TableLength) > mPreAllocatedPages) {
+  if (EFI_SIZE_TO_PAGES ((UINT32) EntryPointStructure->TableLength) > mPreAllocatedPages) {
     //
     // If new SMBIOS table size exceeds the previous allocated page, 
     // it is time to re-allocate memory (below 4GB).
@@ -1307,7 +1307,7 @@ SmbiosCreate64BitTable (
   EndStructure.Tailing[1] = 0;
   Smbios30EntryPointStructure->TableMaximumSize = (UINT32) (Smbios30EntryPointStructure->TableMaximumSize + sizeof (EndStructure));
 
-  if ((UINTN) EFI_SIZE_TO_PAGES (Smbios30EntryPointStructure->TableMaximumSize) > mPre64BitAllocatedPages) {
+  if (EFI_SIZE_TO_PAGES (Smbios30EntryPointStructure->TableMaximumSize) > mPre64BitAllocatedPages) {
     //
     // If new SMBIOS table size exceeds the previous allocated page, 
     // it is time to re-allocate memory at anywhere.
diff --git a/MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.c b/MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.c
index b0c7434..0a325de 100644
--- a/MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.c
+++ b/MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.c
@@ -3754,8 +3754,8 @@ InitNonVolatileVariableStore (
     return EFI_VOLUME_CORRUPTED;
   }
 
-  VariableStoreBase = (EFI_PHYSICAL_ADDRESS) ((UINTN) FvHeader + FvHeader->HeaderLength);
-  VariableStoreLength = (UINT64) (NvStorageSize - FvHeader->HeaderLength);
+  VariableStoreBase = (UINTN) FvHeader + FvHeader->HeaderLength;
+  VariableStoreLength = NvStorageSize - FvHeader->HeaderLength;
 
   mNvFvHeaderCache = FvHeader;
   mVariableModuleGlobal->VariableGlobal.NonVolatileVariableBase = VariableStoreBase;
@@ -4099,7 +4099,7 @@ VariableCommonInitialize (
   GuidHob = GetFirstGuidHob (VariableGuid);
   if (GuidHob != NULL) {
     VariableStoreHeader = GET_GUID_HOB_DATA (GuidHob);
-    VariableStoreLength = (UINT64) (GuidHob->Header.HobLength - sizeof (EFI_HOB_GUID_TYPE));
+    VariableStoreLength = GuidHob->Header.HobLength - sizeof (EFI_HOB_GUID_TYPE);
     if (GetVariableStoreStatus (VariableStoreHeader) == EfiValid) {
       mVariableModuleGlobal->VariableGlobal.HobVariableBase = (EFI_PHYSICAL_ADDRESS) (UINTN) AllocateRuntimeCopyPool ((UINTN) VariableStoreLength, (VOID *) VariableStoreHeader);
       if (mVariableModuleGlobal->VariableGlobal.HobVariableBase == 0) {
-- 
1.9.5.msysgit.0



^ permalink raw reply related	[flat|nested] 25+ messages in thread

* [PATCH v3 03/12] FatPkg: Refine casting expression result to bigger size
  2017-02-25  5:12 [PATCH v3 00/12] Refine casting expression result to bigger size Hao Wu
  2017-02-25  5:12 ` [PATCH v3 01/12] MdePkg: " Hao Wu
  2017-02-25  5:12 ` [PATCH v3 02/12] MdeModulePkg: " Hao Wu
@ 2017-02-25  5:12 ` Hao Wu
  2017-02-27  5:07   ` Ni, Ruiyu
  2017-02-25  5:12 ` [PATCH v3 04/12] IntelFrameworkModulePkg: " Hao Wu
                   ` (8 subsequent siblings)
  11 siblings, 1 reply; 25+ messages in thread
From: Hao Wu @ 2017-02-25  5:12 UTC (permalink / raw)
  To: edk2-devel; +Cc: Hao Wu, Ruiyu Ni

There are cases that the operands of an expression are all with rank less
than UINT64/INT64 and the result of the expression is explicitly cast to
UINT64/INT64 to fit the target size.

An example will be:
UINT32 a,b;
// a and b can be any unsigned int type with rank less than UINT64, like
// UINT8, UINT16, etc.
UINT64 c;
c = (UINT64) (a + b);

Some static code checkers may warn that the expression result might
overflow within the rank of "int" (integer promotions) and the result is
then cast to a bigger size.

The commit refines codes by the following rules:
1). When the expression is possible to overflow the range of unsigned int/
int:
c = (UINT64)a + b;

2). When the expression will not overflow within the rank of "int", remove
the explicit type casts:
c = a + b;

3). When the expression will be cast to pointer of possible greater size:
UINT32 a,b;
VOID *c;
c = (VOID *)(UINTN)(a + b); --> c = (VOID *)((UINTN)a + b);

4). When one side of a comparison expression contains only operands with
rank less than UINT32:
UINT8 a;
UINT16 b;
UINTN c;
if ((UINTN)(a + b) > c) {...} --> if (((UINT32)a + b) > c) {...}

For rule 4), if we remove the 'UINTN' type cast like:
if (a + b > c) {...}
The VS compiler will complain with warning C4018 (signed/unsigned
mismatch, level 3 warning) due to promoting 'a + b' to type 'int'.

Cc: Ruiyu Ni <ruiyu.ni@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Hao Wu <hao.a.wu@intel.com>
---
 FatPkg/EnhancedFatDxe/ReadWrite.c | 4 ++--
 FatPkg/FatPei/FatLiteAccess.c     | 4 ++--
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/FatPkg/EnhancedFatDxe/ReadWrite.c b/FatPkg/EnhancedFatDxe/ReadWrite.c
index a6e0ec4..ad3c260 100644
--- a/FatPkg/EnhancedFatDxe/ReadWrite.c
+++ b/FatPkg/EnhancedFatDxe/ReadWrite.c
@@ -1,7 +1,7 @@
 /** @file
   Functions that perform file read/write.
 
-Copyright (c) 2005 - 2015, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2005 - 2017, Intel Corporation. All rights reserved.<BR>
 This program and the accompanying materials are licensed and made available
 under the terms and conditions of the BSD License which accompanies this
 distribution. The full text of the license may be found at
@@ -173,7 +173,7 @@ Done:
     // Update IFile->Position, if everything is all right
     //
     CurrentPos      = ODir->CurrentPos;
-    IFile->Position = (UINT64) (CurrentPos * sizeof (FAT_DIRECTORY_ENTRY));
+    IFile->Position = CurrentPos * sizeof (FAT_DIRECTORY_ENTRY);
   }
 
   return Status;
diff --git a/FatPkg/FatPei/FatLiteAccess.c b/FatPkg/FatPei/FatLiteAccess.c
index 1106345..a92c5bf 100644
--- a/FatPkg/FatPei/FatLiteAccess.c
+++ b/FatPkg/FatPei/FatLiteAccess.c
@@ -1,7 +1,7 @@
 /** @file
   FAT file system access routines for FAT recovery PEIM
 
-Copyright (c) 2006 - 2013, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2006 - 2017, Intel Corporation. All rights reserved.<BR>
 
 This program and the accompanying materials are licensed and made available
 under the terms and conditions of the BSD License which accompanies this
@@ -393,7 +393,7 @@ FatReadFile (
   } else {
 
     if ((File->Attributes & FAT_ATTR_DIRECTORY) == 0) {
-      Size = Size < (File->FileSize - File->CurrentPos) ? Size : (UINTN) (File->FileSize - File->CurrentPos);
+      Size = Size < (File->FileSize - File->CurrentPos) ? Size : (File->FileSize - File->CurrentPos);
     }
     //
     // This is a normal cluster based file
-- 
1.9.5.msysgit.0



^ permalink raw reply related	[flat|nested] 25+ messages in thread

* [PATCH v3 04/12] IntelFrameworkModulePkg: Refine casting expression result to bigger size
  2017-02-25  5:12 [PATCH v3 00/12] Refine casting expression result to bigger size Hao Wu
                   ` (2 preceding siblings ...)
  2017-02-25  5:12 ` [PATCH v3 03/12] FatPkg: " Hao Wu
@ 2017-02-25  5:12 ` Hao Wu
  2017-02-27  7:06   ` Fan, Jeff
  2017-02-25  5:12 ` [PATCH v3 05/12] IntelFsp2WrapperPkg: " Hao Wu
                   ` (7 subsequent siblings)
  11 siblings, 1 reply; 25+ messages in thread
From: Hao Wu @ 2017-02-25  5:12 UTC (permalink / raw)
  To: edk2-devel; +Cc: Hao Wu, Jeff Fan

There are cases that the operands of an expression are all with rank less
than UINT64/INT64 and the result of the expression is explicitly cast to
UINT64/INT64 to fit the target size.

An example will be:
UINT32 a,b;
// a and b can be any unsigned int type with rank less than UINT64, like
// UINT8, UINT16, etc.
UINT64 c;
c = (UINT64) (a + b);

Some static code checkers may warn that the expression result might
overflow within the rank of "int" (integer promotions) and the result is
then cast to a bigger size.

The commit refines codes by the following rules:
1). When the expression is possible to overflow the range of unsigned int/
int:
c = (UINT64)a + b;

2). When the expression will not overflow within the rank of "int", remove
the explicit type casts:
c = a + b;

3). When the expression will be cast to pointer of possible greater size:
UINT32 a,b;
VOID *c;
c = (VOID *)(UINTN)(a + b); --> c = (VOID *)((UINTN)a + b);

4). When one side of a comparison expression contains only operands with
rank less than UINT32:
UINT8 a;
UINT16 b;
UINTN c;
if ((UINTN)(a + b) > c) {...} --> if (((UINT32)a + b) > c) {...}

For rule 4), if we remove the 'UINTN' type cast like:
if (a + b > c) {...}
The VS compiler will complain with warning C4018 (signed/unsigned
mismatch, level 3 warning) due to promoting 'a + b' to type 'int'.

Cc: Jeff Fan <jeff.fan@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Hao Wu <hao.a.wu@intel.com>
---
 IntelFrameworkModulePkg/Csm/BiosThunk/KeyboardDxe/BiosKeyboard.c |  4 ++--
 IntelFrameworkModulePkg/Csm/BiosThunk/Snp16Dxe/BiosSnp16.c       |  4 ++--
 IntelFrameworkModulePkg/Csm/BiosThunk/Snp16Dxe/Misc.c            | 14 +++++++-------
 IntelFrameworkModulePkg/Csm/BiosThunk/VideoDxe/BiosVideo.c       |  4 ++--
 IntelFrameworkModulePkg/Csm/LegacyBiosDxe/LegacyBios.c           |  6 +++---
 IntelFrameworkModulePkg/Csm/LegacyBiosDxe/LegacyBootSupport.c    |  4 ++--
 IntelFrameworkModulePkg/Library/GenericBdsLib/BdsBoot.c          |  2 +-
 IntelFrameworkModulePkg/Library/GenericBdsLib/BdsMisc.c          |  4 ++--
 IntelFrameworkModulePkg/Library/LegacyBootManagerLib/LegacyBm.c  |  2 +-
 IntelFrameworkModulePkg/Universal/BdsDxe/FrontPage.c             |  4 ++--
 IntelFrameworkModulePkg/Universal/CpuIoDxe/CpuIo.c               |  4 ++--
 11 files changed, 26 insertions(+), 26 deletions(-)

diff --git a/IntelFrameworkModulePkg/Csm/BiosThunk/KeyboardDxe/BiosKeyboard.c b/IntelFrameworkModulePkg/Csm/BiosThunk/KeyboardDxe/BiosKeyboard.c
index a597d99..742d009 100644
--- a/IntelFrameworkModulePkg/Csm/BiosThunk/KeyboardDxe/BiosKeyboard.c
+++ b/IntelFrameworkModulePkg/Csm/BiosThunk/KeyboardDxe/BiosKeyboard.c
@@ -1,7 +1,7 @@
 /** @file
   ConsoleOut Routines that speak VGA.
 
-Copyright (c) 2006 - 2016, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2006 - 2017, Intel Corporation. All rights reserved.<BR>
 
 This program and the accompanying materials
 are licensed and made available under the terms and conditions
@@ -418,7 +418,7 @@ BiosKeyboardDriverBindingStart (
     // Check bit 6 of Feature Byte 2.
     // If it is set, then Int 16 Func 09 is supported
     //
-    if (*(UINT8 *)(UINTN) ((Regs.X.ES << 4) + Regs.X.BX + 0x06) & 0x40) {
+    if (*(UINT8 *) (((UINTN) Regs.X.ES << 4) + Regs.X.BX + 0x06) & 0x40) {
       //
       // Get Keyboard Functionality
       //
diff --git a/IntelFrameworkModulePkg/Csm/BiosThunk/Snp16Dxe/BiosSnp16.c b/IntelFrameworkModulePkg/Csm/BiosThunk/Snp16Dxe/BiosSnp16.c
index a2a7797..b586a91 100644
--- a/IntelFrameworkModulePkg/Csm/BiosThunk/Snp16Dxe/BiosSnp16.c
+++ b/IntelFrameworkModulePkg/Csm/BiosThunk/Snp16Dxe/BiosSnp16.c
@@ -1,6 +1,6 @@
 /** @file
 
-Copyright (c) 1999 - 2014, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 1999 - 2017, Intel Corporation. All rights reserved.<BR>
 
 This program and the accompanying materials
 are licensed and made available under the terms and conditions
@@ -1858,7 +1858,7 @@ Undi16SimpleNetworkIsr (
 
       CopyMem (
         Frame,
-        (VOID *)(UINTN) ((SimpleNetworkDevice->Isr.FrameSegSel << 4) + SimpleNetworkDevice->Isr.FrameOffset),
+        (VOID *) (((UINTN) SimpleNetworkDevice->Isr.FrameSegSel << 4) + SimpleNetworkDevice->Isr.FrameOffset),
         SimpleNetworkDevice->Isr.BufferLength
         );
       Frame = Frame + SimpleNetworkDevice->Isr.BufferLength;
diff --git a/IntelFrameworkModulePkg/Csm/BiosThunk/Snp16Dxe/Misc.c b/IntelFrameworkModulePkg/Csm/BiosThunk/Snp16Dxe/Misc.c
index 4750b2f..a1dc867 100644
--- a/IntelFrameworkModulePkg/Csm/BiosThunk/Snp16Dxe/Misc.c
+++ b/IntelFrameworkModulePkg/Csm/BiosThunk/Snp16Dxe/Misc.c
@@ -1,7 +1,7 @@
 /** @file
   Helper Routines that use a PXE-enabled NIC option ROM.
  
-Copyright (c) 1999 - 2014, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 1999 - 2017, Intel Corporation. All rights reserved.<BR>
 
 This program and the accompanying materials
 are licensed and made available under the terms and conditions
@@ -49,7 +49,7 @@ CacheVectorAddress (
 {
   UINT32  *Address;
 
-  Address                          = (UINT32 *)(UINTN) (IVT_BASE + VectorNumber * 4);
+  Address                          = (UINT32 *) ((UINTN) IVT_BASE + VectorNumber * 4);
   CachedVectorAddress[VectorNumber] = *Address;
   return EFI_SUCCESS;
 }
@@ -68,7 +68,7 @@ RestoreCachedVectorAddress (
 {
   UINT32  *Address;
 
-  Address  = (UINT32 *)(UINTN) (IVT_BASE + VectorNumber * 4);
+  Address  = (UINT32 *) ((UINTN) IVT_BASE + VectorNumber * 4);
   *Address = CachedVectorAddress[VectorNumber];
   return EFI_SUCCESS;
 }
@@ -469,7 +469,7 @@ LaunchBaseCode (
 
   RomIdTableAddress = (UNDI_ROMID_T *) (RomAddress + OPTION_ROM_PTR->PxeRomIdOffset);
 
-  if ((UINTN) (OPTION_ROM_PTR->PxeRomIdOffset + RomIdTableAddress->StructLength) > RomLength) {
+  if (((UINT32)OPTION_ROM_PTR->PxeRomIdOffset + RomIdTableAddress->StructLength) > RomLength) {
     DEBUG ((DEBUG_ERROR, "ROM ID Offset Error\n\r"));
     return EFI_NOT_FOUND;
   }
@@ -754,10 +754,10 @@ LaunchBaseCode (
   Print_Undi_Loader_Table (UndiLoaderTable);
 
   DEBUG ((DEBUG_NET, "Display the PXENV+ and !PXE tables exported by NIC\n\r"));
-  Print_PXENV_Table ((VOID *)(UINTN)((UndiLoaderTable->PXENVptr.Segment << 4) | UndiLoaderTable->PXENVptr.Offset));
-  Print_PXE_Table ((VOID *)(UINTN)((UndiLoaderTable->PXEptr.Segment << 4) + UndiLoaderTable->PXEptr.Offset));
+  Print_PXENV_Table ((VOID *)(((UINTN)UndiLoaderTable->PXENVptr.Segment << 4) | UndiLoaderTable->PXENVptr.Offset));
+  Print_PXE_Table ((VOID *)(((UINTN)UndiLoaderTable->PXEptr.Segment << 4) + UndiLoaderTable->PXEptr.Offset));
 
-  Pxe = (PXE_T *)(UINTN)((UndiLoaderTable->PXEptr.Segment << 4) + UndiLoaderTable->PXEptr.Offset);
+  Pxe = (PXE_T *)(((UINTN)UndiLoaderTable->PXEptr.Segment << 4) + UndiLoaderTable->PXEptr.Offset);
   SimpleNetworkDevice->Nii.Id = (UINT64)(UINTN) Pxe;
 
   gBS->FreePool (Buffer);
diff --git a/IntelFrameworkModulePkg/Csm/BiosThunk/VideoDxe/BiosVideo.c b/IntelFrameworkModulePkg/Csm/BiosThunk/VideoDxe/BiosVideo.c
index f1c8b29..08672cf 100644
--- a/IntelFrameworkModulePkg/Csm/BiosThunk/VideoDxe/BiosVideo.c
+++ b/IntelFrameworkModulePkg/Csm/BiosThunk/VideoDxe/BiosVideo.c
@@ -1,7 +1,7 @@
 /** @file
   ConsoleOut Routines that speak VGA.
 
-Copyright (c) 2007 - 2014, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2007 - 2017, Intel Corporation. All rights reserved.<BR>
 
 This program and the accompanying materials
 are licensed and made available under the terms and conditions
@@ -1714,7 +1714,7 @@ BiosVideoCheckForVbe (
     //
     // Make sure the FrameBufferSize does not exceed the max available frame buffer size reported by VEB.
     //
-    ASSERT (CurrentModeData->FrameBufferSize <= (UINTN)(BiosVideoPrivate->VbeInformationBlock->TotalMemory * 64 * 1024));
+    ASSERT (CurrentModeData->FrameBufferSize <= ((UINT32)BiosVideoPrivate->VbeInformationBlock->TotalMemory * 64 * 1024));
     
     BiosVideoPrivate->ModeData = ModeBuffer;
   }
diff --git a/IntelFrameworkModulePkg/Csm/LegacyBiosDxe/LegacyBios.c b/IntelFrameworkModulePkg/Csm/LegacyBiosDxe/LegacyBios.c
index dd2e2b9..3ead2d9 100644
--- a/IntelFrameworkModulePkg/Csm/LegacyBiosDxe/LegacyBios.c
+++ b/IntelFrameworkModulePkg/Csm/LegacyBiosDxe/LegacyBios.c
@@ -1,6 +1,6 @@
 /** @file
 
-Copyright (c) 2006 - 2013, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2006 - 2017, Intel Corporation. All rights reserved.<BR>
 
 This program and the accompanying materials
 are licensed and made available under the terms and conditions
@@ -144,7 +144,7 @@ LegacyBiosGetLegacyRegion (
      );
 
   if (Regs.X.AX == 0) {
-    *LegacyMemoryAddress  = (VOID *) (UINTN) ((Regs.X.DS << 4) + Regs.X.BX);
+    *LegacyMemoryAddress  = (VOID *) (((UINTN) Regs.X.DS << 4) + Regs.X.BX);
     Status = EFI_SUCCESS;
   } else {
     Status = EFI_OUT_OF_RESOURCES;
@@ -728,7 +728,7 @@ InstallSmbiosEventCallback (
   }
   
   if ((mStructureTableAddress != 0) && 
-      (mStructureTablePages < (UINTN) EFI_SIZE_TO_PAGES (EntryPointStructure->TableLength))) {
+      (mStructureTablePages < EFI_SIZE_TO_PAGES ((UINT32)EntryPointStructure->TableLength))) {
     //
     // If original buffer is not enough for the new SMBIOS table, free original buffer and re-allocate
     //
diff --git a/IntelFrameworkModulePkg/Csm/LegacyBiosDxe/LegacyBootSupport.c b/IntelFrameworkModulePkg/Csm/LegacyBiosDxe/LegacyBootSupport.c
index 52bcae2..1e098b3 100644
--- a/IntelFrameworkModulePkg/Csm/LegacyBiosDxe/LegacyBootSupport.c
+++ b/IntelFrameworkModulePkg/Csm/LegacyBiosDxe/LegacyBootSupport.c
@@ -1,6 +1,6 @@
 /** @file
 
-Copyright (c) 2006 - 2015, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2006 - 2017, Intel Corporation. All rights reserved.<BR>
 
 This program and the accompanying materials
 are licensed and made available under the terms and conditions
@@ -91,7 +91,7 @@ PrintBbsTable (
     //
     // Print DescString
     //
-    String = (CHAR8 *)(UINTN)((BbsTable[Index].DescStringSegment << 4) + BbsTable[Index].DescStringOffset);
+    String = (CHAR8 *)(((UINTN)BbsTable[Index].DescStringSegment << 4) + BbsTable[Index].DescStringOffset);
     if (String != NULL) {
       DEBUG ((EFI_D_INFO," ("));
       for (SubIndex = 0; String[SubIndex] != 0; SubIndex++) {
diff --git a/IntelFrameworkModulePkg/Library/GenericBdsLib/BdsBoot.c b/IntelFrameworkModulePkg/Library/GenericBdsLib/BdsBoot.c
index 628424d..d1da635 100644
--- a/IntelFrameworkModulePkg/Library/GenericBdsLib/BdsBoot.c
+++ b/IntelFrameworkModulePkg/Library/GenericBdsLib/BdsBoot.c
@@ -227,7 +227,7 @@ BdsBuildLegacyDevNameString (
   //
   // If current BBS entry has its description then use it.
   //
-  StringDesc = (UINT8 *) (UINTN) ((CurBBSEntry->DescStringSegment << 4) + CurBBSEntry->DescStringOffset);
+  StringDesc = (UINT8 *) (((UINTN) CurBBSEntry->DescStringSegment << 4) + CurBBSEntry->DescStringOffset);
   if (NULL != StringDesc) {
     //
     // Only get fisrt 32 characters, this is suggested by BBS spec
diff --git a/IntelFrameworkModulePkg/Library/GenericBdsLib/BdsMisc.c b/IntelFrameworkModulePkg/Library/GenericBdsLib/BdsMisc.c
index 2ba511a..48938b0 100644
--- a/IntelFrameworkModulePkg/Library/GenericBdsLib/BdsMisc.c
+++ b/IntelFrameworkModulePkg/Library/GenericBdsLib/BdsMisc.c
@@ -569,11 +569,11 @@ CharToUint (
   )
 {
   if ((Char >= L'0') && (Char <= L'9')) {
-    return (UINTN) (Char - L'0');
+    return (Char - L'0');
   }
 
   if ((Char >= L'A') && (Char <= L'F')) {
-    return (UINTN) (Char - L'A' + 0xA);
+    return (Char - L'A' + 0xA);
   }
 
   ASSERT (FALSE);
diff --git a/IntelFrameworkModulePkg/Library/LegacyBootManagerLib/LegacyBm.c b/IntelFrameworkModulePkg/Library/LegacyBootManagerLib/LegacyBm.c
index 080a436..76902ec 100644
--- a/IntelFrameworkModulePkg/Library/LegacyBootManagerLib/LegacyBm.c
+++ b/IntelFrameworkModulePkg/Library/LegacyBootManagerLib/LegacyBm.c
@@ -176,7 +176,7 @@ LegacyBmBuildLegacyDevNameString (
   //
   // If current BBS entry has its description then use it.
   //
-  StringDesc = (CHAR8 *) (UINTN) ((CurBBSEntry->DescStringSegment << 4) + CurBBSEntry->DescStringOffset);
+  StringDesc = (CHAR8 *) (((UINTN) CurBBSEntry->DescStringSegment << 4) + CurBBSEntry->DescStringOffset);
   if (NULL != StringDesc) {
     //
     // Only get fisrt 32 characters, this is suggested by BBS spec
diff --git a/IntelFrameworkModulePkg/Universal/BdsDxe/FrontPage.c b/IntelFrameworkModulePkg/Universal/BdsDxe/FrontPage.c
index c771974..3bae0be 100644
--- a/IntelFrameworkModulePkg/Universal/BdsDxe/FrontPage.c
+++ b/IntelFrameworkModulePkg/Universal/BdsDxe/FrontPage.c
@@ -1,7 +1,7 @@
 /** @file
   FrontPage routines to handle the callbacks and browser calls
 
-Copyright (c) 2004 - 2016, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2004 - 2017, Intel Corporation. All rights reserved.<BR>
 This program and the accompanying materials
 are licensed and made available under the terms and conditions of the BSD License
 which accompanies this distribution.  The full text of the license may be found at
@@ -620,7 +620,7 @@ ConvertProcessorToString (
 
   if (Base10Exponent >= 6) {
     FreqMhz = ProcessorFrequency;
-    for (Index = 0; Index < (UINTN) (Base10Exponent - 6); Index++) {
+    for (Index = 0; Index < ((UINT32)Base10Exponent - 6); Index++) {
       FreqMhz *= 10;
     }
   } else {
diff --git a/IntelFrameworkModulePkg/Universal/CpuIoDxe/CpuIo.c b/IntelFrameworkModulePkg/Universal/CpuIoDxe/CpuIo.c
index 9db9dbe..9474606 100644
--- a/IntelFrameworkModulePkg/Universal/CpuIoDxe/CpuIo.c
+++ b/IntelFrameworkModulePkg/Universal/CpuIoDxe/CpuIo.c
@@ -1,7 +1,7 @@
 /** @file
   Uses the services of the I/O Library to produce the CPU I/O Protocol
 
-Copyright (c) 2004 - 2012, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2004 - 2017, Intel Corporation. All rights reserved.<BR>
 Copyright (c) 2017, AMD Incorporated. All rights reserved.<BR>
 
 This program and the accompanying materials                          
@@ -141,7 +141,7 @@ CpuIoCheckParameter (
   //
   // Check to see if Address is aligned
   //
-  if ((Address & (UINT64)(mInStride[Width] - 1)) != 0) {
+  if ((Address & ((UINT64)mInStride[Width] - 1)) != 0) {
     return EFI_UNSUPPORTED;
   }
 
-- 
1.9.5.msysgit.0



^ permalink raw reply related	[flat|nested] 25+ messages in thread

* [PATCH v3 05/12] IntelFsp2WrapperPkg: Refine casting expression result to bigger size
  2017-02-25  5:12 [PATCH v3 00/12] Refine casting expression result to bigger size Hao Wu
                   ` (3 preceding siblings ...)
  2017-02-25  5:12 ` [PATCH v3 04/12] IntelFrameworkModulePkg: " Hao Wu
@ 2017-02-25  5:12 ` Hao Wu
  2017-02-25  5:51   ` Yao, Jiewen
  2017-02-25  5:12 ` [PATCH v3 06/12] IntelFspWrapperPkg: " Hao Wu
                   ` (6 subsequent siblings)
  11 siblings, 1 reply; 25+ messages in thread
From: Hao Wu @ 2017-02-25  5:12 UTC (permalink / raw)
  To: edk2-devel; +Cc: Hao Wu, Jiewen Yao

There are cases that the operands of an expression are all with rank less
than UINT64/INT64 and the result of the expression is explicitly cast to
UINT64/INT64 to fit the target size.

An example will be:
UINT32 a,b;
// a and b can be any unsigned int type with rank less than UINT64, like
// UINT8, UINT16, etc.
UINT64 c;
c = (UINT64) (a + b);

Some static code checkers may warn that the expression result might
overflow within the rank of "int" (integer promotions) and the result is
then cast to a bigger size.

The commit refines codes by the following rules:
1). When the expression is possible to overflow the range of unsigned int/
int:
c = (UINT64)a + b;

2). When the expression will not overflow within the rank of "int", remove
the explicit type casts:
c = a + b;

3). When the expression will be cast to pointer of possible greater size:
UINT32 a,b;
VOID *c;
c = (VOID *)(UINTN)(a + b); --> c = (VOID *)((UINTN)a + b);

4). When one side of a comparison expression contains only operands with
rank less than UINT32:
UINT8 a;
UINT16 b;
UINTN c;
if ((UINTN)(a + b) > c) {...} --> if (((UINT32)a + b) > c) {...}

For rule 4), if we remove the 'UINTN' type cast like:
if (a + b > c) {...}
The VS compiler will complain with warning C4018 (signed/unsigned
mismatch, level 3 warning) due to promoting 'a + b' to type 'int'.

Cc: Jiewen Yao <jiewen.yao@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Hao Wu <hao.a.wu@intel.com>
---
 IntelFsp2WrapperPkg/FspWrapperNotifyDxe/LoadBelow4G.c               |  4 ++--
 IntelFsp2WrapperPkg/Library/BaseFspWrapperApiLib/FspWrapperApiLib.c | 10 +++++-----
 2 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/IntelFsp2WrapperPkg/FspWrapperNotifyDxe/LoadBelow4G.c b/IntelFsp2WrapperPkg/FspWrapperNotifyDxe/LoadBelow4G.c
index ff2f563..dc5ef89 100644
--- a/IntelFsp2WrapperPkg/FspWrapperNotifyDxe/LoadBelow4G.c
+++ b/IntelFsp2WrapperPkg/FspWrapperNotifyDxe/LoadBelow4G.c
@@ -1,6 +1,6 @@
 /** @file
 
-Copyright (c) 2015 - 2016, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2015 - 2017, Intel Corporation. All rights reserved.<BR>
 
 This program and the accompanying materials
 are licensed and made available under the terms and conditions
@@ -115,7 +115,7 @@ RelocateImageUnder4GIfNeeded (
   // Align buffer on section boundary
   //
   ImageContext.ImageAddress += ImageContext.SectionAlignment - 1;
-  ImageContext.ImageAddress &= ~((EFI_PHYSICAL_ADDRESS)(ImageContext.SectionAlignment - 1));
+  ImageContext.ImageAddress &= ~((EFI_PHYSICAL_ADDRESS)ImageContext.SectionAlignment - 1);
   //
   // Load the image to our new buffer
   //
diff --git a/IntelFsp2WrapperPkg/Library/BaseFspWrapperApiLib/FspWrapperApiLib.c b/IntelFsp2WrapperPkg/Library/BaseFspWrapperApiLib/FspWrapperApiLib.c
index 8cf136f..38de415 100644
--- a/IntelFsp2WrapperPkg/Library/BaseFspWrapperApiLib/FspWrapperApiLib.c
+++ b/IntelFsp2WrapperPkg/Library/BaseFspWrapperApiLib/FspWrapperApiLib.c
@@ -1,7 +1,7 @@
 /** @file
   Provide FSP API related function.
 
-  Copyright (c) 2014 - 2016, Intel Corporation. All rights reserved.<BR>
+  Copyright (c) 2014 - 2017, Intel Corporation. All rights reserved.<BR>
   This program and the accompanying materials
   are licensed and made available under the terms and conditions of the BSD License
   which accompanies this distribution.  The full text of the license may be found at
@@ -99,7 +99,7 @@ CallFspNotifyPhase (
     return EFI_DEVICE_ERROR;
   }
 
-  NotifyPhaseApi = (FSP_NOTIFY_PHASE)(UINTN)(FspHeader->ImageBase + FspHeader->NotifyPhaseEntryOffset);
+  NotifyPhaseApi = (FSP_NOTIFY_PHASE)((UINTN)FspHeader->ImageBase + FspHeader->NotifyPhaseEntryOffset);
   InterruptState = SaveAndDisableInterrupts ();
   Status = Execute32BitCode ((UINTN)NotifyPhaseApi, (UINTN)NotifyPhaseParams, (UINTN)NULL);
   SetInterruptState (InterruptState);
@@ -132,7 +132,7 @@ CallFspMemoryInit (
     return EFI_DEVICE_ERROR;
   }
 
-  FspMemoryInitApi = (FSP_MEMORY_INIT)(UINTN)(FspHeader->ImageBase + FspHeader->FspMemoryInitEntryOffset);
+  FspMemoryInitApi = (FSP_MEMORY_INIT)((UINTN)FspHeader->ImageBase + FspHeader->FspMemoryInitEntryOffset);
   InterruptState = SaveAndDisableInterrupts ();
   Status = Execute32BitCode ((UINTN)FspMemoryInitApi, (UINTN)FspmUpdDataPtr, (UINTN)HobListPtr);
   SetInterruptState (InterruptState);
@@ -163,7 +163,7 @@ CallTempRamExit (
     return EFI_DEVICE_ERROR;
   }
 
-  TempRamExitApi = (FSP_TEMP_RAM_EXIT)(UINTN)(FspHeader->ImageBase + FspHeader->TempRamExitEntryOffset);
+  TempRamExitApi = (FSP_TEMP_RAM_EXIT)((UINTN)FspHeader->ImageBase + FspHeader->TempRamExitEntryOffset);
   InterruptState = SaveAndDisableInterrupts ();
   Status = Execute32BitCode ((UINTN)TempRamExitApi, (UINTN)TempRamExitParam, (UINTN)NULL);
   SetInterruptState (InterruptState);
@@ -194,7 +194,7 @@ CallFspSiliconInit (
     return EFI_DEVICE_ERROR;
   }
 
-  FspSiliconInitApi = (FSP_SILICON_INIT)(UINTN)(FspHeader->ImageBase + FspHeader->FspSiliconInitEntryOffset);
+  FspSiliconInitApi = (FSP_SILICON_INIT)((UINTN)FspHeader->ImageBase + FspHeader->FspSiliconInitEntryOffset);
   InterruptState = SaveAndDisableInterrupts ();
   Status = Execute32BitCode ((UINTN)FspSiliconInitApi, (UINTN)FspsUpdDataPtr, (UINTN)NULL);
   SetInterruptState (InterruptState);
-- 
1.9.5.msysgit.0



^ permalink raw reply related	[flat|nested] 25+ messages in thread

* [PATCH v3 06/12] IntelFspWrapperPkg: Refine casting expression result to bigger size
  2017-02-25  5:12 [PATCH v3 00/12] Refine casting expression result to bigger size Hao Wu
                   ` (4 preceding siblings ...)
  2017-02-25  5:12 ` [PATCH v3 05/12] IntelFsp2WrapperPkg: " Hao Wu
@ 2017-02-25  5:12 ` Hao Wu
  2017-02-25  5:51   ` Yao, Jiewen
  2017-02-25  5:12 ` [PATCH v3 07/12] NetworkPkg: " Hao Wu
                   ` (5 subsequent siblings)
  11 siblings, 1 reply; 25+ messages in thread
From: Hao Wu @ 2017-02-25  5:12 UTC (permalink / raw)
  To: edk2-devel; +Cc: Hao Wu, Jiewen Yao

There are cases that the operands of an expression are all with rank less
than UINT64/INT64 and the result of the expression is explicitly cast to
UINT64/INT64 to fit the target size.

An example will be:
UINT32 a,b;
// a and b can be any unsigned int type with rank less than UINT64, like
// UINT8, UINT16, etc.
UINT64 c;
c = (UINT64) (a + b);

Some static code checkers may warn that the expression result might
overflow within the rank of "int" (integer promotions) and the result is
then cast to a bigger size.

The commit refines codes by the following rules:
1). When the expression is possible to overflow the range of unsigned int/
int:
c = (UINT64)a + b;

2). When the expression will not overflow within the rank of "int", remove
the explicit type casts:
c = a + b;

3). When the expression will be cast to pointer of possible greater size:
UINT32 a,b;
VOID *c;
c = (VOID *)(UINTN)(a + b); --> c = (VOID *)((UINTN)a + b);

4). When one side of a comparison expression contains only operands with
rank less than UINT32:
UINT8 a;
UINT16 b;
UINTN c;
if ((UINTN)(a + b) > c) {...} --> if (((UINT32)a + b) > c) {...}

For rule 4), if we remove the 'UINTN' type cast like:
if (a + b > c) {...}
The VS compiler will complain with warning C4018 (signed/unsigned
mismatch, level 3 warning) due to promoting 'a + b' to type 'int'.

Cc: Jiewen Yao <jiewen.yao@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Hao Wu <hao.a.wu@intel.com>
---
 IntelFspWrapperPkg/FspNotifyDxe/LoadBelow4G.c        |  4 ++--
 IntelFspWrapperPkg/Library/BaseFspApiLib/FspApiLib.c | 12 ++++++------
 2 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/IntelFspWrapperPkg/FspNotifyDxe/LoadBelow4G.c b/IntelFspWrapperPkg/FspNotifyDxe/LoadBelow4G.c
index 6f06e24..089413c 100644
--- a/IntelFspWrapperPkg/FspNotifyDxe/LoadBelow4G.c
+++ b/IntelFspWrapperPkg/FspNotifyDxe/LoadBelow4G.c
@@ -1,6 +1,6 @@
 /** @file
 
-Copyright (c) 2015, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2015 - 2017, Intel Corporation. All rights reserved.<BR>
 
 This program and the accompanying materials
 are licensed and made available under the terms and conditions
@@ -115,7 +115,7 @@ RelocateImageUnder4GIfNeeded (
   // Align buffer on section boundary
   //
   ImageContext.ImageAddress += ImageContext.SectionAlignment - 1;
-  ImageContext.ImageAddress &= ~((EFI_PHYSICAL_ADDRESS)(ImageContext.SectionAlignment - 1));
+  ImageContext.ImageAddress &= ~((EFI_PHYSICAL_ADDRESS)ImageContext.SectionAlignment - 1);
   //
   // Load the image to our new buffer
   //
diff --git a/IntelFspWrapperPkg/Library/BaseFspApiLib/FspApiLib.c b/IntelFspWrapperPkg/Library/BaseFspApiLib/FspApiLib.c
index 162d244..accd6e4 100644
--- a/IntelFspWrapperPkg/Library/BaseFspApiLib/FspApiLib.c
+++ b/IntelFspWrapperPkg/Library/BaseFspApiLib/FspApiLib.c
@@ -1,7 +1,7 @@
 /** @file
   Provide FSP API related function.
 
-  Copyright (c) 2014 - 2015, Intel Corporation. All rights reserved.<BR>
+  Copyright (c) 2014 - 2017, Intel Corporation. All rights reserved.<BR>
   This program and the accompanying materials
   are licensed and made available under the terms and conditions of the BSD License
   which accompanies this distribution.  The full text of the license may be found at
@@ -98,7 +98,7 @@ CallFspInit (
   EFI_STATUS          Status;
   BOOLEAN             InterruptState;
 
-  FspInitApi = (FSP_INIT)(UINTN)(FspHeader->ImageBase + FspHeader->FspInitEntryOffset);
+  FspInitApi = (FSP_INIT)((UINTN)FspHeader->ImageBase + FspHeader->FspInitEntryOffset);
   InterruptState = SaveAndDisableInterrupts ();
   Status = Execute32BitCode ((UINTN)FspInitApi, (UINTN)FspInitParams);
   SetInterruptState (InterruptState);
@@ -125,7 +125,7 @@ CallFspNotifyPhase (
   EFI_STATUS          Status;
   BOOLEAN             InterruptState;
 
-  NotifyPhaseApi = (FSP_NOTIFY_PHASE)(UINTN)(FspHeader->ImageBase + FspHeader->NotifyPhaseEntryOffset);
+  NotifyPhaseApi = (FSP_NOTIFY_PHASE)((UINTN)FspHeader->ImageBase + FspHeader->NotifyPhaseEntryOffset);
   InterruptState = SaveAndDisableInterrupts ();
   Status = Execute32BitCode ((UINTN)NotifyPhaseApi, (UINTN)NotifyPhaseParams);
   SetInterruptState (InterruptState);
@@ -152,7 +152,7 @@ CallFspMemoryInit (
   EFI_STATUS          Status;
   BOOLEAN             InterruptState;
 
-  FspMemoryInitApi = (FSP_MEMORY_INIT)(UINTN)(FspHeader->ImageBase + FspHeader->FspMemoryInitEntryOffset);
+  FspMemoryInitApi = (FSP_MEMORY_INIT)((UINTN)FspHeader->ImageBase + FspHeader->FspMemoryInitEntryOffset);
   InterruptState = SaveAndDisableInterrupts ();
   Status = Execute32BitCode ((UINTN)FspMemoryInitApi, (UINTN)FspMemoryInitParams);
   SetInterruptState (InterruptState);
@@ -179,7 +179,7 @@ CallTempRamExit (
   EFI_STATUS          Status;
   BOOLEAN             InterruptState;
 
-  TempRamExitApi = (FSP_TEMP_RAM_EXIT)(UINTN)(FspHeader->ImageBase + FspHeader->TempRamExitEntryOffset);
+  TempRamExitApi = (FSP_TEMP_RAM_EXIT)((UINTN)FspHeader->ImageBase + FspHeader->TempRamExitEntryOffset);
   InterruptState = SaveAndDisableInterrupts ();
   Status = Execute32BitCode ((UINTN)TempRamExitApi, (UINTN)TempRamExitParam);
   SetInterruptState (InterruptState);
@@ -206,7 +206,7 @@ CallFspSiliconInit (
   EFI_STATUS          Status;
   BOOLEAN             InterruptState;
 
-  FspSiliconInitApi = (FSP_SILICON_INIT)(UINTN)(FspHeader->ImageBase + FspHeader->FspSiliconInitEntryOffset);
+  FspSiliconInitApi = (FSP_SILICON_INIT)((UINTN)FspHeader->ImageBase + FspHeader->FspSiliconInitEntryOffset);
   InterruptState = SaveAndDisableInterrupts ();
   Status = Execute32BitCode ((UINTN)FspSiliconInitApi, (UINTN)FspSiliconInitParam);
   SetInterruptState (InterruptState);
-- 
1.9.5.msysgit.0



^ permalink raw reply related	[flat|nested] 25+ messages in thread

* [PATCH v3 07/12] NetworkPkg: Refine casting expression result to bigger size
  2017-02-25  5:12 [PATCH v3 00/12] Refine casting expression result to bigger size Hao Wu
                   ` (5 preceding siblings ...)
  2017-02-25  5:12 ` [PATCH v3 06/12] IntelFspWrapperPkg: " Hao Wu
@ 2017-02-25  5:12 ` Hao Wu
  2017-02-27  2:21   ` Wu, Jiaxin
  2017-02-25  5:12 ` [PATCH v3 08/12] PcAtChipsetPkg: " Hao Wu
                   ` (4 subsequent siblings)
  11 siblings, 1 reply; 25+ messages in thread
From: Hao Wu @ 2017-02-25  5:12 UTC (permalink / raw)
  To: edk2-devel; +Cc: Hao Wu, Siyuan Fu, Jiaxin Wu

There are cases that the operands of an expression are all with rank less
than UINT64/INT64 and the result of the expression is explicitly cast to
UINT64/INT64 to fit the target size.

An example will be:
UINT32 a,b;
// a and b can be any unsigned int type with rank less than UINT64, like
// UINT8, UINT16, etc.
UINT64 c;
c = (UINT64) (a + b);

Some static code checkers may warn that the expression result might
overflow within the rank of "int" (integer promotions) and the result is
then cast to a bigger size.

The commit refines codes by the following rules:
1). When the expression is possible to overflow the range of unsigned int/
int:
c = (UINT64)a + b;

2). When the expression will not overflow within the rank of "int", remove
the explicit type casts:
c = a + b;

3). When the expression will be cast to pointer of possible greater size:
UINT32 a,b;
VOID *c;
c = (VOID *)(UINTN)(a + b); --> c = (VOID *)((UINTN)a + b);

4). When one side of a comparison expression contains only operands with
rank less than UINT32:
UINT8 a;
UINT16 b;
UINTN c;
if ((UINTN)(a + b) > c) {...} --> if (((UINT32)a + b) > c) {...}

For rule 4), if we remove the 'UINTN' type cast like:
if (a + b > c) {...}
The VS compiler will complain with warning C4018 (signed/unsigned
mismatch, level 3 warning) due to promoting 'a + b' to type 'int'.

Cc: Siyuan Fu <siyuan.fu@intel.com>
Cc: Jiaxin Wu <jiaxin.wu@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Hao Wu <hao.a.wu@intel.com>
---
 NetworkPkg/IpSecDxe/Ikev2/Payload.c   |  4 ++--
 NetworkPkg/IpSecDxe/IpSecConfigImpl.c |  8 ++++----
 NetworkPkg/IpSecDxe/IpSecConfigImpl.h |  4 ++--
 NetworkPkg/Mtftp6Dxe/Mtftp6Support.c  |  4 ++--
 NetworkPkg/UefiPxeBcDxe/PxeBcImpl.c   | 10 +++++-----
 5 files changed, 15 insertions(+), 15 deletions(-)

diff --git a/NetworkPkg/IpSecDxe/Ikev2/Payload.c b/NetworkPkg/IpSecDxe/Ikev2/Payload.c
index f32b3a8..237743b 100644
--- a/NetworkPkg/IpSecDxe/Ikev2/Payload.c
+++ b/NetworkPkg/IpSecDxe/Ikev2/Payload.c
@@ -2,7 +2,7 @@
   The implementation of Payloads Creation.
 
   (C) Copyright 2015 Hewlett-Packard Development Company, L.P.<BR>
-  Copyright (c) 2010 - 2016, Intel Corporation. All rights reserved.<BR>
+  Copyright (c) 2010 - 2017, Intel Corporation. All rights reserved.<BR>
 
   This program and the accompanying materials
   are licensed and made available under the terms and conditions of the BSD License
@@ -1748,7 +1748,7 @@ Ikev2EncodeSa (
       Transform->Header.NextPayload   = IKE_TRANSFORM_NEXT_PAYLOAD_MORE;
       Transform->Header.PayloadLength = HTONS ((UINT16)TransformSize);
 
-      if (TransformIndex == (UINTN)(ProposalData->NumTransforms - 1)) {
+      if (TransformIndex == ((UINT32)ProposalData->NumTransforms - 1)) {
         Transform->Header.NextPayload = IKE_TRANSFORM_NEXT_PAYLOAD_NONE;
       }
 
diff --git a/NetworkPkg/IpSecDxe/IpSecConfigImpl.c b/NetworkPkg/IpSecDxe/IpSecConfigImpl.c
index cfee978..4a51bff 100644
--- a/NetworkPkg/IpSecDxe/IpSecConfigImpl.c
+++ b/NetworkPkg/IpSecDxe/IpSecConfigImpl.c
@@ -1,7 +1,7 @@
 /** @file
   The implementation of IPSEC_CONFIG_PROTOCOL.
 
-  Copyright (c) 2009 - 2016, Intel Corporation. All rights reserved.<BR>
+  Copyright (c) 2009 - 2017, Intel Corporation. All rights reserved.<BR>
 
   This program and the accompanying materials
   are licensed and made available under the terms and conditions of the BSD License
@@ -1152,7 +1152,7 @@ SetSpdEntry (
   // Do Padding for the different Arch.
   //
   SpdEntrySize  = ALIGN_VARIABLE (sizeof (IPSEC_SPD_ENTRY));
-  SpdEntrySize  = ALIGN_VARIABLE (SpdEntrySize + (UINTN)SIZE_OF_SPD_SELECTOR (SpdSel));
+  SpdEntrySize  = ALIGN_VARIABLE (SpdEntrySize + SIZE_OF_SPD_SELECTOR (SpdSel));
   SpdEntrySize += IpSecGetSizeOfEfiSpdData (SpdData);
 
   SpdEntry = AllocateZeroPool (SpdEntrySize);
@@ -1357,7 +1357,7 @@ SetSadEntry (
   }
 
   if (SaData->SpdSelector != NULL) {
-    SadEntrySize += SadEntrySize + (UINTN)SIZE_OF_SPD_SELECTOR (SaData->SpdSelector);
+    SadEntrySize += SadEntrySize + SIZE_OF_SPD_SELECTOR (SaData->SpdSelector);
   }
   SadEntry      = AllocateZeroPool (SadEntrySize);
 
@@ -1458,7 +1458,7 @@ SetSadEntry (
       SadEntry->Data->SpdEntry = SpdEntry;
       SadEntry->Data->SpdSelector = (EFI_IPSEC_SPD_SELECTOR *)((UINT8 *)SadEntry +
                                                                 SadEntrySize -
-                                                                (UINTN)SIZE_OF_SPD_SELECTOR (SaData->SpdSelector)
+                                                                SIZE_OF_SPD_SELECTOR (SaData->SpdSelector)
                                                                 );
       DuplicateSpdSelector (
        (EFI_IPSEC_CONFIG_SELECTOR *) SadEntry->Data->SpdSelector,
diff --git a/NetworkPkg/IpSecDxe/IpSecConfigImpl.h b/NetworkPkg/IpSecDxe/IpSecConfigImpl.h
index 3e365da..23e6880 100644
--- a/NetworkPkg/IpSecDxe/IpSecConfigImpl.h
+++ b/NetworkPkg/IpSecDxe/IpSecConfigImpl.h
@@ -1,7 +1,7 @@
 /** @file
   Definitions related to IPSEC_CONFIG_PROTOCOL implementations.
 
-  Copyright (c) 2009 - 2011, Intel Corporation. All rights reserved.<BR>
+  Copyright (c) 2009 - 2017, Intel Corporation. All rights reserved.<BR>
 
   This program and the accompanying materials
   are licensed and made available under the terms and conditions of the BSD License
@@ -38,7 +38,7 @@
 #define IPSECCONFIG_VARIABLE_NAME       L"IpSecConfig"
 #define IPSECCONFIG_STATUS_NAME         L"IpSecStatus"
 
-#define SIZE_OF_SPD_SELECTOR(x) (UINTN) (sizeof (EFI_IPSEC_SPD_SELECTOR) \
+#define SIZE_OF_SPD_SELECTOR(x) (sizeof (EFI_IPSEC_SPD_SELECTOR) \
        + sizeof (EFI_IP_ADDRESS_INFO) * ((x)->LocalAddressCount + (x)->RemoteAddressCount))
 
 #define FIX_REF_BUF_ADDR(addr, base)    addr = (VOID *) ((UINTN) (addr) - (UINTN) (base))
diff --git a/NetworkPkg/Mtftp6Dxe/Mtftp6Support.c b/NetworkPkg/Mtftp6Dxe/Mtftp6Support.c
index 64df901..e6b4127 100644
--- a/NetworkPkg/Mtftp6Dxe/Mtftp6Support.c
+++ b/NetworkPkg/Mtftp6Dxe/Mtftp6Support.c
@@ -1,7 +1,7 @@
 /** @file
   Mtftp6 support functions implementation.
 
-  Copyright (c) 2009 - 2016, Intel Corporation. All rights reserved.<BR>
+  Copyright (c) 2009 - 2017, Intel Corporation. All rights reserved.<BR>
 
   This program and the accompanying materials
   are licensed and made available under the terms and conditions of the BSD License
@@ -223,7 +223,7 @@ Mtftp6RemoveBlockNum (
       *TotalBlock  = Num;
 
       if (Range->Round > 0) {
-        *TotalBlock += Range->Bound +  MultU64x32 ((UINT64) (Range->Round -1), (UINT32)(Range->Bound + 1)) + 1;
+        *TotalBlock += Range->Bound +  MultU64x32 (Range->Round - 1, (UINT32)(Range->Bound + 1)) + 1;
       }
 
       if (Range->Start > Range->Bound) {
diff --git a/NetworkPkg/UefiPxeBcDxe/PxeBcImpl.c b/NetworkPkg/UefiPxeBcDxe/PxeBcImpl.c
index e24c573..36477e9 100644
--- a/NetworkPkg/UefiPxeBcDxe/PxeBcImpl.c
+++ b/NetworkPkg/UefiPxeBcDxe/PxeBcImpl.c
@@ -1,7 +1,7 @@
 /** @file
   This implementation of EFI_PXE_BASE_CODE_PROTOCOL and EFI_LOAD_FILE_PROTOCOL.
 
-  Copyright (c) 2007 - 2016, Intel Corporation. All rights reserved.<BR>
+  Copyright (c) 2007 - 2017, Intel Corporation. All rights reserved.<BR>
 
   This program and the accompanying materials
   are licensed and made available under the terms and conditions of the BSD License
@@ -95,8 +95,8 @@ EfiPxeBcStart (
     //
     // Configure block size for TFTP as a default value to handle all link layers.
     //
-    Private->BlockSize = (UINTN) (Private->Ip6MaxPacketSize -
-                           PXEBC_DEFAULT_UDP_OVERHEAD_SIZE - PXEBC_DEFAULT_TFTP_OVERHEAD_SIZE);
+    Private->BlockSize = Private->Ip6MaxPacketSize -
+                           PXEBC_DEFAULT_UDP_OVERHEAD_SIZE - PXEBC_DEFAULT_TFTP_OVERHEAD_SIZE;
 
     //
     // PXE over IPv6 starts here, initialize the fields and list header.
@@ -148,8 +148,8 @@ EfiPxeBcStart (
     //
     // Configure block size for TFTP as a default value to handle all link layers.
     //
-    Private->BlockSize = (UINTN) (Private->Ip4MaxPacketSize -
-                           PXEBC_DEFAULT_UDP_OVERHEAD_SIZE - PXEBC_DEFAULT_TFTP_OVERHEAD_SIZE);
+    Private->BlockSize = Private->Ip4MaxPacketSize -
+                           PXEBC_DEFAULT_UDP_OVERHEAD_SIZE - PXEBC_DEFAULT_TFTP_OVERHEAD_SIZE;
 
     //
     // PXE over IPv4 starts here, initialize the fields.
-- 
1.9.5.msysgit.0



^ permalink raw reply related	[flat|nested] 25+ messages in thread

* [PATCH v3 08/12] PcAtChipsetPkg: Refine casting expression result to bigger size
  2017-02-25  5:12 [PATCH v3 00/12] Refine casting expression result to bigger size Hao Wu
                   ` (6 preceding siblings ...)
  2017-02-25  5:12 ` [PATCH v3 07/12] NetworkPkg: " Hao Wu
@ 2017-02-25  5:12 ` Hao Wu
  2017-02-27  7:24   ` Ni, Ruiyu
  2017-02-25  5:12 ` [PATCH v3 09/12] SecurityPkg/Opal: " Hao Wu
                   ` (3 subsequent siblings)
  11 siblings, 1 reply; 25+ messages in thread
From: Hao Wu @ 2017-02-25  5:12 UTC (permalink / raw)
  To: edk2-devel; +Cc: Hao Wu, Ruiyu Ni

There are cases that the operands of an expression are all with rank less
than UINT64/INT64 and the result of the expression is explicitly cast to
UINT64/INT64 to fit the target size.

An example will be:
UINT32 a,b;
// a and b can be any unsigned int type with rank less than UINT64, like
// UINT8, UINT16, etc.
UINT64 c;
c = (UINT64) (a + b);

Some static code checkers may warn that the expression result might
overflow within the rank of "int" (integer promotions) and the result is
then cast to a bigger size.

The commit refines codes by the following rules:
1). When the expression is possible to overflow the range of unsigned int/
int:
c = (UINT64)a + b;

2). When the expression will not overflow within the rank of "int", remove
the explicit type casts:
c = a + b;

3). When the expression will be cast to pointer of possible greater size:
UINT32 a,b;
VOID *c;
c = (VOID *)(UINTN)(a + b); --> c = (VOID *)((UINTN)a + b);

4). When one side of a comparison expression contains only operands with
rank less than UINT32:
UINT8 a;
UINT16 b;
UINTN c;
if ((UINTN)(a + b) > c) {...} --> if (((UINT32)a + b) > c) {...}

For rule 4), if we remove the 'UINTN' type cast like:
if (a + b > c) {...}
The VS compiler will complain with warning C4018 (signed/unsigned
mismatch, level 3 warning) due to promoting 'a + b' to type 'int'.

Cc: Ruiyu Ni <ruiyu.ni@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Hao Wu <hao.a.wu@intel.com>
---
 PcAtChipsetPkg/Library/SerialIoLib/SerialPortLib.c | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/PcAtChipsetPkg/Library/SerialIoLib/SerialPortLib.c b/PcAtChipsetPkg/Library/SerialIoLib/SerialPortLib.c
index dcb43fa..95e0db7 100644
--- a/PcAtChipsetPkg/Library/SerialIoLib/SerialPortLib.c
+++ b/PcAtChipsetPkg/Library/SerialIoLib/SerialPortLib.c
@@ -1,7 +1,7 @@
 /** @file
   UART Serial Port library functions
 
-  Copyright (c) 2006 - 2016, Intel Corporation. All rights reserved.<BR>
+  Copyright (c) 2006 - 2017, Intel Corporation. All rights reserved.<BR>
   This program and the accompanying materials
   are licensed and made available under the terms and conditions of the BSD License
   which accompanies this distribution.  The full text of the license may be found at
@@ -91,19 +91,19 @@ SerialPortInitialize (
   // Set communications format
   //
   OutputData = (UINT8) ((DLAB << 7) | (gBreakSet << 6) | (gParity << 3) | (gStop << 2) | Data);
-  IoWrite8 ((UINTN) (gUartBase + LCR_OFFSET), OutputData);
+  IoWrite8 (gUartBase + LCR_OFFSET, OutputData);
 
   //
   // Configure baud rate
   //
-  IoWrite8 ((UINTN) (gUartBase + BAUD_HIGH_OFFSET), (UINT8) (Divisor >> 8));
-  IoWrite8 ((UINTN) (gUartBase + BAUD_LOW_OFFSET), (UINT8) (Divisor & 0xff));
+  IoWrite8 (gUartBase + BAUD_HIGH_OFFSET, (UINT8) (Divisor >> 8));
+  IoWrite8 (gUartBase + BAUD_LOW_OFFSET, (UINT8) (Divisor & 0xff));
 
   //
   // Switch back to bank 0
   //
   OutputData = (UINT8) ((~DLAB << 7) | (gBreakSet << 6) | (gParity << 3) | (gStop << 2) | Data);
-  IoWrite8 ((UINTN) (gUartBase + LCR_OFFSET), OutputData);
+  IoWrite8 (gUartBase + LCR_OFFSET, OutputData);
 
   return RETURN_SUCCESS;
 }
@@ -470,19 +470,19 @@ SerialPortSetAttributes (
   // Set communications format
   //
   OutputData = (UINT8) ((DLAB << 7) | (gBreakSet << 6) | (LcrParity << 3) | (LcrStop << 2) | LcrData);
-  IoWrite8 ((UINTN) (gUartBase + LCR_OFFSET), OutputData);
+  IoWrite8 (gUartBase + LCR_OFFSET, OutputData);
 
   //
   // Configure baud rate
   //
-  IoWrite8 ((UINTN) (gUartBase + BAUD_HIGH_OFFSET), (UINT8) (Divisor >> 8));
-  IoWrite8 ((UINTN) (gUartBase + BAUD_LOW_OFFSET), (UINT8) (Divisor & 0xff));
+  IoWrite8 (gUartBase + BAUD_HIGH_OFFSET, (UINT8) (Divisor >> 8));
+  IoWrite8 (gUartBase + BAUD_LOW_OFFSET, (UINT8) (Divisor & 0xff));
 
   //
   // Switch back to bank 0
   //
   OutputData = (UINT8) ((~DLAB << 7) | (gBreakSet << 6) | (LcrParity << 3) | (LcrStop << 2) | LcrData);
-  IoWrite8 ((UINTN) (gUartBase + LCR_OFFSET), OutputData);
+  IoWrite8 (gUartBase + LCR_OFFSET, OutputData);
 
   return RETURN_SUCCESS;
 }
-- 
1.9.5.msysgit.0



^ permalink raw reply related	[flat|nested] 25+ messages in thread

* [PATCH v3 09/12] SecurityPkg/Opal: Refine casting expression result to bigger size
  2017-02-25  5:12 [PATCH v3 00/12] Refine casting expression result to bigger size Hao Wu
                   ` (7 preceding siblings ...)
  2017-02-25  5:12 ` [PATCH v3 08/12] PcAtChipsetPkg: " Hao Wu
@ 2017-02-25  5:12 ` Hao Wu
  2017-03-06  1:40   ` Dong, Eric
  2017-02-25  5:12 ` [PATCH v3 10/12] ShellPkg: " Hao Wu
                   ` (2 subsequent siblings)
  11 siblings, 1 reply; 25+ messages in thread
From: Hao Wu @ 2017-02-25  5:12 UTC (permalink / raw)
  To: edk2-devel; +Cc: Hao Wu, Eric Dong, Feng Tian, Chao Zhang

There are cases that the operands of an expression are all with rank less
than UINT64/INT64 and the result of the expression is explicitly cast to
UINT64/INT64 to fit the target size.

An example will be:
UINT32 a,b;
// a and b can be any unsigned int type with rank less than UINT64, like
// UINT8, UINT16, etc.
UINT64 c;
c = (UINT64) (a + b);

Some static code checkers may warn that the expression result might
overflow within the rank of "int" (integer promotions) and the result is
then cast to a bigger size.

The commit refines codes by the following rules:
1). When the expression is possible to overflow the range of unsigned int/
int:
c = (UINT64)a + b;

2). When the expression will not overflow within the rank of "int", remove
the explicit type casts:
c = a + b;

3). When the expression will be cast to pointer of possible greater size:
UINT32 a,b;
VOID *c;
c = (VOID *)(UINTN)(a + b); --> c = (VOID *)((UINTN)a + b);

4). When one side of a comparison expression contains only operands with
rank less than UINT32:
UINT8 a;
UINT16 b;
UINTN c;
if ((UINTN)(a + b) > c) {...} --> if (((UINT32)a + b) > c) {...}

For rule 4), if we remove the 'UINTN' type cast like:
if (a + b > c) {...}
The VS compiler will complain with warning C4018 (signed/unsigned
mismatch, level 3 warning) due to promoting 'a + b' to type 'int'.

Cc: Eric Dong <eric.dong@intel.com>
Cc: Feng Tian <feng.tian@intel.com>
Cc: Chao Zhang <chao.b.zhang@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Hao Wu <hao.a.wu@intel.com>
---
 SecurityPkg/Tcg/Opal/OpalPasswordSmm/OpalNvmeMode.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/SecurityPkg/Tcg/Opal/OpalPasswordSmm/OpalNvmeMode.c b/SecurityPkg/Tcg/Opal/OpalPasswordSmm/OpalNvmeMode.c
index 9e90d54..a47d276 100644
--- a/SecurityPkg/Tcg/Opal/OpalPasswordSmm/OpalNvmeMode.c
+++ b/SecurityPkg/Tcg/Opal/OpalPasswordSmm/OpalNvmeMode.c
@@ -1,7 +1,7 @@
 /** @file
   Provide functions to initialize NVME controller and perform NVME commands
 
-Copyright (c) 2016, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2016 - 2017, Intel Corporation. All rights reserved.<BR>
 This program and the accompanying materials
 are licensed and made available under the terms and conditions of the BSD License
 which accompanies this distribution.  The full text of the license may be found at
@@ -52,7 +52,7 @@ enum {
 ///
 /// All of base memories are 4K(0x1000) alignment
 ///
-#define NVME_MEM_BASE(Nvme)                 (Nvme->BaseMem)
+#define NVME_MEM_BASE(Nvme)                 ((UINTN)(Nvme->BaseMem))
 #define NVME_CONTROL_DATA_BASE(Nvme)        (ALIGN (NVME_MEM_BASE(Nvme) + ((NvmeGetBaseMemPages (BASEMEM_CONTROLLER_DATA))                        * EFI_PAGE_SIZE), EFI_PAGE_SIZE))
 #define NVME_NAMESPACE_DATA_BASE(Nvme)      (ALIGN (NVME_MEM_BASE(Nvme) + ((NvmeGetBaseMemPages (BASEMEM_IDENTIFY_DATA))                          * EFI_PAGE_SIZE), EFI_PAGE_SIZE))
 #define NVME_ASQ_BASE(Nvme)                 (ALIGN (NVME_MEM_BASE(Nvme) + ((NvmeGetBaseMemPages (BASEMEM_ASQ))                                    * EFI_PAGE_SIZE), EFI_PAGE_SIZE))
-- 
1.9.5.msysgit.0



^ permalink raw reply related	[flat|nested] 25+ messages in thread

* [PATCH v3 10/12] ShellPkg: Refine casting expression result to bigger size
  2017-02-25  5:12 [PATCH v3 00/12] Refine casting expression result to bigger size Hao Wu
                   ` (8 preceding siblings ...)
  2017-02-25  5:12 ` [PATCH v3 09/12] SecurityPkg/Opal: " Hao Wu
@ 2017-02-25  5:12 ` Hao Wu
  2017-02-27  2:22   ` Ni, Ruiyu
  2017-02-27 16:38   ` Carsey, Jaben
  2017-02-25  5:12 ` [PATCH v3 11/12] SourceLevelDebugPkg: " Hao Wu
  2017-02-25  5:12 ` [PATCH v3 12/12] UefiCpuPkg: " Hao Wu
  11 siblings, 2 replies; 25+ messages in thread
From: Hao Wu @ 2017-02-25  5:12 UTC (permalink / raw)
  To: edk2-devel; +Cc: Hao Wu, Jaben Carsey, Ruiyu Ni

There are cases that the operands of an expression are all with rank less
than UINT64/INT64 and the result of the expression is explicitly cast to
UINT64/INT64 to fit the target size.

An example will be:
UINT32 a,b;
// a and b can be any unsigned int type with rank less than UINT64, like
// UINT8, UINT16, etc.
UINT64 c;
c = (UINT64) (a + b);

Some static code checkers may warn that the expression result might
overflow within the rank of "int" (integer promotions) and the result is
then cast to a bigger size.

The commit refines codes by the following rules:
1). When the expression is possible to overflow the range of unsigned int/
int:
c = (UINT64)a + b;

2). When the expression will not overflow within the rank of "int", remove
the explicit type casts:
c = a + b;

3). When the expression will be cast to pointer of possible greater size:
UINT32 a,b;
VOID *c;
c = (VOID *)(UINTN)(a + b); --> c = (VOID *)((UINTN)a + b);

4). When one side of a comparison expression contains only operands with
rank less than UINT32:
UINT8 a;
UINT16 b;
UINTN c;
if ((UINTN)(a + b) > c) {...} --> if (((UINT32)a + b) > c) {...}

For rule 4), if we remove the 'UINTN' type cast like:
if (a + b > c) {...}
The VS compiler will complain with warning C4018 (signed/unsigned
mismatch, level 3 warning) due to promoting 'a + b' to type 'int'.

Cc: Jaben Carsey <jaben.carsey@intel.com>
Cc: Ruiyu Ni <ruiyu.ni@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Hao Wu <hao.a.wu@intel.com>
---
 ShellPkg/Library/UefiShellDebug1CommandsLib/HexEdit/BufferImage.c        | 8 ++++----
 ShellPkg/Library/UefiShellDebug1CommandsLib/UefiShellDebug1CommandsLib.c | 4 ++--
 ShellPkg/Library/UefiShellLib/UefiShellLib.c                             | 4 ++--
 3 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/ShellPkg/Library/UefiShellDebug1CommandsLib/HexEdit/BufferImage.c b/ShellPkg/Library/UefiShellDebug1CommandsLib/HexEdit/BufferImage.c
index 68d2443..1048ecd 100644
--- a/ShellPkg/Library/UefiShellDebug1CommandsLib/HexEdit/BufferImage.c
+++ b/ShellPkg/Library/UefiShellDebug1CommandsLib/HexEdit/BufferImage.c
@@ -2,7 +2,7 @@
   Defines HBufferImage - the view of the file that is visible at any point,
   as well as the event handlers for editing the file
   
-  Copyright (c) 2005 - 2014, Intel Corporation. All rights reserved. <BR>
+  Copyright (c) 2005 - 2017, Intel Corporation. All rights reserved. <BR>
   This program and the accompanying materials
   are licensed and made available under the terms and conditions of the BSD License
   which accompanies this distribution.  The full text of the license may be found at
@@ -1108,15 +1108,15 @@ HBufferImageCharToHex (
   // change the character to hex
   //
   if (Char >= L'0' && Char <= L'9') {
-    return (INTN) (Char - L'0');
+    return (Char - L'0');
   }
 
   if (Char >= L'a' && Char <= L'f') {
-    return (INTN) (Char - L'a' + 10);
+    return (Char - L'a' + 10);
   }
 
   if (Char >= L'A' && Char <= L'F') {
-    return (INTN) (Char - L'A' + 10);
+    return (Char - L'A' + 10);
   }
 
   return -1;
diff --git a/ShellPkg/Library/UefiShellDebug1CommandsLib/UefiShellDebug1CommandsLib.c b/ShellPkg/Library/UefiShellDebug1CommandsLib/UefiShellDebug1CommandsLib.c
index 6ebf002..a0e249e 100644
--- a/ShellPkg/Library/UefiShellDebug1CommandsLib/UefiShellDebug1CommandsLib.c
+++ b/ShellPkg/Library/UefiShellDebug1CommandsLib/UefiShellDebug1CommandsLib.c
@@ -1,7 +1,7 @@
 /** @file
   Main file for NULL named library for debug1 profile shell command functions.
 
-  Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>
+  Copyright (c) 2010 - 2017, Intel Corporation. All rights reserved.<BR>
   This program and the accompanying materials
   are licensed and made available under the terms and conditions of the BSD License
   which accompanies this distribution.  The full text of the license may be found at
@@ -193,7 +193,7 @@ HexCharToUintn (
     return Char - L'0';
   }
 
-  return (UINTN) (10 + CharToUpper (Char) - L'A');
+  return (10 + CharToUpper (Char) - L'A');
 }
 
 /**
diff --git a/ShellPkg/Library/UefiShellLib/UefiShellLib.c b/ShellPkg/Library/UefiShellLib/UefiShellLib.c
index 536db3c..55e8a67 100644
--- a/ShellPkg/Library/UefiShellLib/UefiShellLib.c
+++ b/ShellPkg/Library/UefiShellLib/UefiShellLib.c
@@ -3,7 +3,7 @@
 
   (C) Copyright 2016 Hewlett Packard Enterprise Development LP<BR>
   Copyright 2016 Dell Inc.
-  Copyright (c) 2006 - 2016, Intel Corporation. All rights reserved.<BR>
+  Copyright (c) 2006 - 2017, Intel Corporation. All rights reserved.<BR>
   This program and the accompanying materials
   are licensed and made available under the terms and conditions of the BSD License
   which accompanies this distribution.  The full text of the license may be found at
@@ -3755,7 +3755,7 @@ InternalShellHexCharToUintn (
     return Char - L'0';
   }
 
-  return (UINTN) (10 + InternalShellCharToUpper (Char) - L'A');
+  return (10 + InternalShellCharToUpper (Char) - L'A');
 }
 
 /**
-- 
1.9.5.msysgit.0



^ permalink raw reply related	[flat|nested] 25+ messages in thread

* [PATCH v3 11/12] SourceLevelDebugPkg: Refine casting expression result to bigger size
  2017-02-25  5:12 [PATCH v3 00/12] Refine casting expression result to bigger size Hao Wu
                   ` (9 preceding siblings ...)
  2017-02-25  5:12 ` [PATCH v3 10/12] ShellPkg: " Hao Wu
@ 2017-02-25  5:12 ` Hao Wu
  2017-02-27  7:27   ` Fan, Jeff
  2017-02-25  5:12 ` [PATCH v3 12/12] UefiCpuPkg: " Hao Wu
  11 siblings, 1 reply; 25+ messages in thread
From: Hao Wu @ 2017-02-25  5:12 UTC (permalink / raw)
  To: edk2-devel; +Cc: Hao Wu, Jeff Fan

There are cases that the operands of an expression are all with rank less
than UINT64/INT64 and the result of the expression is explicitly cast to
UINT64/INT64 to fit the target size.

An example will be:
UINT32 a,b;
// a and b can be any unsigned int type with rank less than UINT64, like
// UINT8, UINT16, etc.
UINT64 c;
c = (UINT64) (a + b);

Some static code checkers may warn that the expression result might
overflow within the rank of "int" (integer promotions) and the result is
then cast to a bigger size.

The commit refines codes by the following rules:
1). When the expression is possible to overflow the range of unsigned int/
int:
c = (UINT64)a + b;

2). When the expression will not overflow within the rank of "int", remove
the explicit type casts:
c = a + b;

3). When the expression will be cast to pointer of possible greater size:
UINT32 a,b;
VOID *c;
c = (VOID *)(UINTN)(a + b); --> c = (VOID *)((UINTN)a + b);

4). When one side of a comparison expression contains only operands with
rank less than UINT32:
UINT8 a;
UINT16 b;
UINTN c;
if ((UINTN)(a + b) > c) {...} --> if (((UINT32)a + b) > c) {...}

For rule 4), if we remove the 'UINTN' type cast like:
if (a + b > c) {...}
The VS compiler will complain with warning C4018 (signed/unsigned
mismatch, level 3 warning) due to promoting 'a + b' to type 'int'.

Cc: Jeff Fan <jeff.fan@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Hao Wu <hao.a.wu@intel.com>
---
 SourceLevelDebugPkg/Library/DebugAgent/DxeDebugAgent/DxeDebugAgentLib.c         |  6 +++---
 SourceLevelDebugPkg/Library/DebugAgent/SecPeiDebugAgent/SecPeiDebugAgentLib.c   |  8 ++++----
 SourceLevelDebugPkg/Library/DebugAgent/SmmDebugAgent/SmmDebugAgentLib.c         |  6 +++---
 SourceLevelDebugPkg/Library/DebugCommunicationLibUsb/DebugCommunicationLibUsb.c | 18 +++++++++---------
 4 files changed, 19 insertions(+), 19 deletions(-)

diff --git a/SourceLevelDebugPkg/Library/DebugAgent/DxeDebugAgent/DxeDebugAgentLib.c b/SourceLevelDebugPkg/Library/DebugAgent/DxeDebugAgent/DxeDebugAgentLib.c
index a63932c..c74a1f6 100644
--- a/SourceLevelDebugPkg/Library/DebugAgent/DxeDebugAgent/DxeDebugAgentLib.c
+++ b/SourceLevelDebugPkg/Library/DebugAgent/DxeDebugAgent/DxeDebugAgentLib.c
@@ -1,7 +1,7 @@
 /** @file
   Debug Agent library implementition for Dxe Core and Dxr modules.
 
-  Copyright (c) 2010 - 2015, Intel Corporation. All rights reserved.<BR>
+  Copyright (c) 2010 - 2017, Intel Corporation. All rights reserved.<BR>
   This program and the accompanying materials
   are licensed and made available under the terms and conditions of the BSD License
   which accompanies this distribution.  The full text of the license may be found at
@@ -512,8 +512,8 @@ InitializeDebugAgent (
     if (Context != NULL) {
       Ia32Idtr =  (IA32_DESCRIPTOR *) Context;
       Ia32IdtEntry = (IA32_IDT_ENTRY *)(Ia32Idtr->Base);
-      MailboxLocation = (UINT64 *) (UINTN) (Ia32IdtEntry[DEBUG_MAILBOX_VECTOR].Bits.OffsetLow +
-                                  (UINT32) (Ia32IdtEntry[DEBUG_MAILBOX_VECTOR].Bits.OffsetHigh << 16));
+      MailboxLocation = (UINT64 *) ((UINTN) Ia32IdtEntry[DEBUG_MAILBOX_VECTOR].Bits.OffsetLow +
+                                   ((UINTN) Ia32IdtEntry[DEBUG_MAILBOX_VECTOR].Bits.OffsetHigh << 16));
       Mailbox = (DEBUG_AGENT_MAILBOX *)(UINTN)(*MailboxLocation);
       VerifyMailboxChecksum (Mailbox);
     }
diff --git a/SourceLevelDebugPkg/Library/DebugAgent/SecPeiDebugAgent/SecPeiDebugAgentLib.c b/SourceLevelDebugPkg/Library/DebugAgent/SecPeiDebugAgent/SecPeiDebugAgentLib.c
index 128c69f..b717e33 100644
--- a/SourceLevelDebugPkg/Library/DebugAgent/SecPeiDebugAgent/SecPeiDebugAgentLib.c
+++ b/SourceLevelDebugPkg/Library/DebugAgent/SecPeiDebugAgent/SecPeiDebugAgentLib.c
@@ -1,7 +1,7 @@
 /** @file
   SEC Core Debug Agent Library instance implementition.
 
-  Copyright (c) 2010 - 2015, Intel Corporation. All rights reserved.<BR>
+  Copyright (c) 2010 - 2017, Intel Corporation. All rights reserved.<BR>
   This program and the accompanying materials
   are licensed and made available under the terms and conditions of the BSD License
   which accompanies this distribution.  The full text of the license may be found at
@@ -213,7 +213,7 @@ GetMailboxPointer (
     // Fix up Debug Port handler and save new mailbox in IDT entry
     //
     Mailbox = (DEBUG_AGENT_MAILBOX *)((UINTN)Mailbox + ((UINTN)(MailboxLocationInHob) - (UINTN)MailboxLocationInIdt));
-    DebugPortHandle = (UINT64)((UINTN)Mailbox->DebugPortHandle + ((UINTN)(MailboxLocationInHob) - (UINTN)MailboxLocationInIdt));
+    DebugPortHandle = (UINTN)Mailbox->DebugPortHandle + ((UINTN)(MailboxLocationInHob) - (UINTN)MailboxLocationInIdt);
     UpdateMailboxContent (Mailbox, DEBUG_MAILBOX_DEBUG_PORT_HANDLE_INDEX, DebugPortHandle);
     *MailboxLocationInHob = (UINT64)(UINTN)Mailbox;
     SetLocationSavedMailboxPointerInIdtEntry (MailboxLocationInHob);
@@ -582,8 +582,8 @@ InitializeDebugAgent (
     } else {
       Ia32Idtr =  (IA32_DESCRIPTOR *) Context;
       Ia32IdtEntry = (IA32_IDT_ENTRY *)(Ia32Idtr->Base);
-      MailboxLocationPointer = (UINT64 *) (UINTN) (Ia32IdtEntry[DEBUG_MAILBOX_VECTOR].Bits.OffsetLow +
-                                         (UINT32) (Ia32IdtEntry[DEBUG_MAILBOX_VECTOR].Bits.OffsetHigh << 16));
+      MailboxLocationPointer = (UINT64 *) ((UINTN) Ia32IdtEntry[DEBUG_MAILBOX_VECTOR].Bits.OffsetLow +
+                                          ((UINTN) Ia32IdtEntry[DEBUG_MAILBOX_VECTOR].Bits.OffsetHigh << 16));
       Mailbox = (DEBUG_AGENT_MAILBOX *) (UINTN)(*MailboxLocationPointer);
       //
       // Mailbox should valid and setup before executing thunk code
diff --git a/SourceLevelDebugPkg/Library/DebugAgent/SmmDebugAgent/SmmDebugAgentLib.c b/SourceLevelDebugPkg/Library/DebugAgent/SmmDebugAgent/SmmDebugAgentLib.c
index 6216142..11afd32 100644
--- a/SourceLevelDebugPkg/Library/DebugAgent/SmmDebugAgent/SmmDebugAgentLib.c
+++ b/SourceLevelDebugPkg/Library/DebugAgent/SmmDebugAgent/SmmDebugAgentLib.c
@@ -1,7 +1,7 @@
 /** @file
   Debug Agent library implementition.
 
-  Copyright (c) 2010 - 2016, Intel Corporation. All rights reserved.<BR>
+  Copyright (c) 2010 - 2017, Intel Corporation. All rights reserved.<BR>
   This program and the accompanying materials
   are licensed and made available under the terms and conditions of the BSD License
   which accompanies this distribution.  The full text of the license may be found at
@@ -336,8 +336,8 @@ InitializeDebugAgent (
     } else {
       Ia32Idtr =  (IA32_DESCRIPTOR *) Context;
       Ia32IdtEntry = (IA32_IDT_ENTRY *)(Ia32Idtr->Base);
-      MailboxLocation = (UINT64 *) (UINTN) (Ia32IdtEntry[DEBUG_MAILBOX_VECTOR].Bits.OffsetLow + 
-                                  (UINT32) (Ia32IdtEntry[DEBUG_MAILBOX_VECTOR].Bits.OffsetHigh << 16));
+      MailboxLocation = (UINT64 *) ((UINTN) Ia32IdtEntry[DEBUG_MAILBOX_VECTOR].Bits.OffsetLow +
+                                   ((UINTN) Ia32IdtEntry[DEBUG_MAILBOX_VECTOR].Bits.OffsetHigh << 16));
       mMailboxPointer = (DEBUG_AGENT_MAILBOX *)(UINTN)(*MailboxLocation);
       VerifyMailboxChecksum (mMailboxPointer);
       //
diff --git a/SourceLevelDebugPkg/Library/DebugCommunicationLibUsb/DebugCommunicationLibUsb.c b/SourceLevelDebugPkg/Library/DebugCommunicationLibUsb/DebugCommunicationLibUsb.c
index d7829c2..d996f80 100644
--- a/SourceLevelDebugPkg/Library/DebugCommunicationLibUsb/DebugCommunicationLibUsb.c
+++ b/SourceLevelDebugPkg/Library/DebugCommunicationLibUsb/DebugCommunicationLibUsb.c
@@ -1,7 +1,7 @@
 /** @file
   Debug Port Library implementation based on usb debug port.
 
-  Copyright (c) 2010 - 2015, Intel Corporation. All rights reserved.<BR>
+  Copyright (c) 2010 - 2017, Intel Corporation. All rights reserved.<BR>
   This program and the accompanying materials
   are licensed and made available under the terms and conditions of the BSD License
   which accompanies this distribution.  The full text of the license may be found at
@@ -559,7 +559,7 @@ NeedReinitializeHardware(
   //
   // If the owner and in_use bit is not set, it means system is doing cold/warm boot or EHCI host controller is reset by system software.
   //
-  UsbDebugPortRegister = (USB_DEBUG_PORT_REGISTER *)(UINTN)(Handle->UsbDebugPortMemoryBase + Handle->DebugPortOffset);
+  UsbDebugPortRegister = (USB_DEBUG_PORT_REGISTER *)((UINTN)Handle->UsbDebugPortMemoryBase + Handle->DebugPortOffset);
   if ((MmioRead32((UINTN)&UsbDebugPortRegister->ControlStatus) & (USB_DEBUG_PORT_OWNER | USB_DEBUG_PORT_ENABLE | USB_DEBUG_PORT_IN_USE))
        != (USB_DEBUG_PORT_OWNER | USB_DEBUG_PORT_ENABLE | USB_DEBUG_PORT_IN_USE)) {
     Status = TRUE;
@@ -604,10 +604,10 @@ InitializeUsbDebugHardware (
   UINT8                     DebugPortNumber;
   UINT8                     Length;
 
-  UsbDebugPortRegister = (USB_DEBUG_PORT_REGISTER *)(UINTN)(Handle->UsbDebugPortMemoryBase + Handle->DebugPortOffset);
-  UsbHCSParam = (UINT32 *)(UINTN)(Handle->EhciMemoryBase + 0x04);
-  UsbCmd      = (UINT32 *)(UINTN)(Handle->EhciMemoryBase + 0x20);
-  UsbStatus   = (UINT32 *)(UINTN)(Handle->EhciMemoryBase + 0x24);
+  UsbDebugPortRegister = (USB_DEBUG_PORT_REGISTER *)((UINTN)Handle->UsbDebugPortMemoryBase + Handle->DebugPortOffset);
+  UsbHCSParam = (UINT32 *)((UINTN)Handle->EhciMemoryBase + 0x04);
+  UsbCmd      = (UINT32 *)((UINTN)Handle->EhciMemoryBase + 0x20);
+  UsbStatus   = (UINT32 *)((UINTN)Handle->EhciMemoryBase + 0x24);
 
   //
   // Check if the debug port is enabled and owned by myself.
@@ -652,7 +652,7 @@ InitializeUsbDebugHardware (
   //
   // Should find a device is connected at debug port
   //
-  PortStatus = (UINT32 *)(UINTN)(Handle->EhciMemoryBase + 0x64 + (DebugPortNumber - 1) * 4);
+  PortStatus = (UINT32 *)((UINTN)Handle->EhciMemoryBase + 0x64 + (DebugPortNumber - 1) * 4);
   if (!(MmioRead32((UINTN)PortStatus) & BIT0)) {
     Handle->Initialized = USBDBG_NO_DEV;
     return RETURN_NOT_FOUND;
@@ -870,7 +870,7 @@ DebugPortWriteBuffer (
     }
   }
 
-  UsbDebugPortRegister = (USB_DEBUG_PORT_REGISTER *)(UINTN)(UsbDebugPortHandle->UsbDebugPortMemoryBase + UsbDebugPortHandle->DebugPortOffset);
+  UsbDebugPortRegister = (USB_DEBUG_PORT_REGISTER *)((UINTN)UsbDebugPortHandle->UsbDebugPortMemoryBase + UsbDebugPortHandle->DebugPortOffset);
 
   while ((Total < NumberOfBytes)) {
     if (NumberOfBytes - Total > USB_DEBUG_PORT_MAX_PACKET_SIZE) {
@@ -950,7 +950,7 @@ DebugPortPollBuffer (
     return TRUE;
   }
 
-  UsbDebugPortRegister = (USB_DEBUG_PORT_REGISTER *)(UINTN)(UsbDebugPortHandle->UsbDebugPortMemoryBase + UsbDebugPortHandle->DebugPortOffset);
+  UsbDebugPortRegister = (USB_DEBUG_PORT_REGISTER *)((UINTN)UsbDebugPortHandle->UsbDebugPortMemoryBase + UsbDebugPortHandle->DebugPortOffset);
 
   UsbDebugPortRegister->TokenPid = INPUT_PID;
   if (UsbDebugPortHandle->BulkInToggle == 0) {
-- 
1.9.5.msysgit.0



^ permalink raw reply related	[flat|nested] 25+ messages in thread

* [PATCH v3 12/12] UefiCpuPkg: Refine casting expression result to bigger size
  2017-02-25  5:12 [PATCH v3 00/12] Refine casting expression result to bigger size Hao Wu
                   ` (10 preceding siblings ...)
  2017-02-25  5:12 ` [PATCH v3 11/12] SourceLevelDebugPkg: " Hao Wu
@ 2017-02-25  5:12 ` Hao Wu
  2017-02-27  7:27   ` Fan, Jeff
  11 siblings, 1 reply; 25+ messages in thread
From: Hao Wu @ 2017-02-25  5:12 UTC (permalink / raw)
  To: edk2-devel; +Cc: Hao Wu, Jeff Fan

There are cases that the operands of an expression are all with rank less
than UINT64/INT64 and the result of the expression is explicitly cast to
UINT64/INT64 to fit the target size.

An example will be:
UINT32 a,b;
// a and b can be any unsigned int type with rank less than UINT64, like
// UINT8, UINT16, etc.
UINT64 c;
c = (UINT64) (a + b);

Some static code checkers may warn that the expression result might
overflow within the rank of "int" (integer promotions) and the result is
then cast to a bigger size.

The commit refines codes by the following rules:
1). When the expression is possible to overflow the range of unsigned int/
int:
c = (UINT64)a + b;

2). When the expression will not overflow within the rank of "int", remove
the explicit type casts:
c = a + b;

3). When the expression will be cast to pointer of possible greater size:
UINT32 a,b;
VOID *c;
c = (VOID *)(UINTN)(a + b); --> c = (VOID *)((UINTN)a + b);

4). When one side of a comparison expression contains only operands with
rank less than UINT32:
UINT8 a;
UINT16 b;
UINTN c;
if ((UINTN)(a + b) > c) {...} --> if (((UINT32)a + b) > c) {...}

For rule 4), if we remove the 'UINTN' type cast like:
if (a + b > c) {...}
The VS compiler will complain with warning C4018 (signed/unsigned
mismatch, level 3 warning) due to promoting 'a + b' to type 'int'.

Cc: Jeff Fan <jeff.fan@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Hao Wu <hao.a.wu@intel.com>
---
 UefiCpuPkg/CpuIo2Dxe/CpuIo2Dxe.c              | 4 ++--
 UefiCpuPkg/CpuIo2Smm/CpuIo2Smm.c              | 4 ++--
 UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmStm.c | 8 ++++----
 UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.c    | 4 ++--
 UefiCpuPkg/PiSmmCpuDxeSmm/SmramSaveState.c    | 6 +++---
 5 files changed, 13 insertions(+), 13 deletions(-)

diff --git a/UefiCpuPkg/CpuIo2Dxe/CpuIo2Dxe.c b/UefiCpuPkg/CpuIo2Dxe/CpuIo2Dxe.c
index 60f4bbc..d19349d 100644
--- a/UefiCpuPkg/CpuIo2Dxe/CpuIo2Dxe.c
+++ b/UefiCpuPkg/CpuIo2Dxe/CpuIo2Dxe.c
@@ -1,7 +1,7 @@
 /** @file
   Produces the CPU I/O 2 Protocol.
 
-Copyright (c) 2009 - 2012, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2009 - 2017, Intel Corporation. All rights reserved.<BR>
 Copyright (c) 2017, AMD Incorporated. All rights reserved.<BR>
 
 This program and the accompanying materials                          
@@ -141,7 +141,7 @@ CpuIoCheckParameter (
   //
   // Check to see if Address is aligned
   //
-  if ((Address & (UINT64)(mInStride[Width] - 1)) != 0) {
+  if ((Address & ((UINT64)mInStride[Width] - 1)) != 0) {
     return EFI_UNSUPPORTED;
   }
 
diff --git a/UefiCpuPkg/CpuIo2Smm/CpuIo2Smm.c b/UefiCpuPkg/CpuIo2Smm/CpuIo2Smm.c
index 7b1ad37..20b8350 100644
--- a/UefiCpuPkg/CpuIo2Smm/CpuIo2Smm.c
+++ b/UefiCpuPkg/CpuIo2Smm/CpuIo2Smm.c
@@ -1,7 +1,7 @@
 /** @file
   Produces the SMM CPU I/O Protocol.
 
-Copyright (c) 2009 - 2012, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2009 - 2017, Intel Corporation. All rights reserved.<BR>
 This program and the accompanying materials                          
 are licensed and made available under the terms and conditions of the BSD License         
 which accompanies this distribution.  The full text of the license may be found at        
@@ -126,7 +126,7 @@ CpuIoCheckParameter (
   //
   // Check to see if Address is aligned
   //
-  if ((Address & (UINT64)(mStride[Width] - 1)) != 0) {
+  if ((Address & ((UINT64)mStride[Width] - 1)) != 0) {
     return EFI_UNSUPPORTED;
   }
 
diff --git a/UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmStm.c b/UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmStm.c
index bb123ba..03937dc 100644
--- a/UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmStm.c
+++ b/UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmStm.c
@@ -1,7 +1,7 @@
 /** @file
   SMM STM support functions
 
-  Copyright (c) 2015 - 2016, Intel Corporation. All rights reserved.<BR>
+  Copyright (c) 2015 - 2017, Intel Corporation. All rights reserved.<BR>
   This program and the accompanying materials
   are licensed and made available under the terms and conditions of the BSD License
   which accompanies this distribution.  The full text of the license may be found at
@@ -276,8 +276,8 @@ SmmCpuFeaturesInstallSmiHandler (
   UINT32                         RegEdx;
   EFI_PROCESSOR_INFORMATION      ProcessorInfo;
 
-  CopyMem ((VOID *)(UINTN)(SmBase + TXT_SMM_PSD_OFFSET), &gcStmPsd, sizeof (gcStmPsd));
-  Psd = (TXT_PROCESSOR_SMM_DESCRIPTOR *)(VOID *)(UINTN)(SmBase + TXT_SMM_PSD_OFFSET);
+  CopyMem ((VOID *)((UINTN)SmBase + TXT_SMM_PSD_OFFSET), &gcStmPsd, sizeof (gcStmPsd));
+  Psd = (TXT_PROCESSOR_SMM_DESCRIPTOR *)(VOID *)((UINTN)SmBase + TXT_SMM_PSD_OFFSET);
   Psd->SmmGdtPtr = GdtBase;
   Psd->SmmGdtSize = (UINT32)GdtSize;
 
@@ -317,7 +317,7 @@ SmmCpuFeaturesInstallSmiHandler (
   // Copy template to CPU specific SMI handler location
   //
   CopyMem (
-    (VOID*)(UINTN)(SmBase + SMM_HANDLER_OFFSET),
+    (VOID*)((UINTN)SmBase + SMM_HANDLER_OFFSET),
     (VOID*)gcStmSmiHandlerTemplate,
     gcStmSmiHandlerSize
     );
diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.c b/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.c
index fc7714a..2519e28 100644
--- a/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.c
+++ b/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.c
@@ -1,7 +1,7 @@
 /** @file
 Agent Module to load other modules to deploy SMM Entry Vector for X86 CPU.
 
-Copyright (c) 2009 - 2016, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2009 - 2017, Intel Corporation. All rights reserved.<BR>
 This program and the accompanying materials
 are licensed and made available under the terms and conditions of the BSD License
 which accompanies this distribution.  The full text of the license may be found at
@@ -1268,7 +1268,7 @@ AllocateAlignedCodePages (
       Status = gSmst->SmmFreePages (Memory, UnalignedPages);
       ASSERT_EFI_ERROR (Status);
     }
-    Memory         = (EFI_PHYSICAL_ADDRESS) (AlignedMemory + EFI_PAGES_TO_SIZE (Pages));
+    Memory         = AlignedMemory + EFI_PAGES_TO_SIZE (Pages);
     UnalignedPages = RealPages - Pages - UnalignedPages;
     if (UnalignedPages > 0) {
       //
diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/SmramSaveState.c b/UefiCpuPkg/PiSmmCpuDxeSmm/SmramSaveState.c
index b4bc0ec..3188d43 100644
--- a/UefiCpuPkg/PiSmmCpuDxeSmm/SmramSaveState.c
+++ b/UefiCpuPkg/PiSmmCpuDxeSmm/SmramSaveState.c
@@ -1,7 +1,7 @@
 /** @file
 Provides services to access SMRAM Save State Map
 
-Copyright (c) 2010 - 2016, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2010 - 2017, Intel Corporation. All rights reserved.<BR>
 This program and the accompanying materials
 are licensed and made available under the terms and conditions of the BSD License
 which accompanies this distribution.  The full text of the license may be found at
@@ -690,7 +690,7 @@ InstallSmiHandler (
   //
   // Initialize PROCESSOR_SMM_DESCRIPTOR
   //
-  Psd = (PROCESSOR_SMM_DESCRIPTOR *)(VOID *)(UINTN)(SmBase + SMM_PSD_OFFSET);
+  Psd = (PROCESSOR_SMM_DESCRIPTOR *)(VOID *)((UINTN)SmBase + SMM_PSD_OFFSET);
   CopyMem (Psd, &gcPsd, sizeof (gcPsd));
   Psd->SmmGdtPtr = (UINT64)GdtBase;
   Psd->SmmGdtSize = (UINT32)GdtSize;
@@ -731,7 +731,7 @@ InstallSmiHandler (
   // Copy template to CPU specific SMI handler location
   //
   CopyMem (
-    (VOID*)(UINTN)(SmBase + SMM_HANDLER_OFFSET),
+    (VOID*)((UINTN)SmBase + SMM_HANDLER_OFFSET),
     (VOID*)gcSmiHandlerTemplate,
     gcSmiHandlerSize
     );
-- 
1.9.5.msysgit.0



^ permalink raw reply related	[flat|nested] 25+ messages in thread

* Re: [PATCH v3 06/12] IntelFspWrapperPkg: Refine casting expression result to bigger size
  2017-02-25  5:12 ` [PATCH v3 06/12] IntelFspWrapperPkg: " Hao Wu
@ 2017-02-25  5:51   ` Yao, Jiewen
  0 siblings, 0 replies; 25+ messages in thread
From: Yao, Jiewen @ 2017-02-25  5:51 UTC (permalink / raw)
  To: Wu, Hao A, edk2-devel@lists.01.org

Reviewed-by: jiewen.yao@intel.com

> -----Original Message-----
> From: Wu, Hao A
> Sent: Saturday, February 25, 2017 1:12 PM
> To: edk2-devel@lists.01.org
> Cc: Wu, Hao A <hao.a.wu@intel.com>; Yao, Jiewen <jiewen.yao@intel.com>
> Subject: [PATCH v3 06/12] IntelFspWrapperPkg: Refine casting expression result
> to bigger size
> 
> There are cases that the operands of an expression are all with rank less
> than UINT64/INT64 and the result of the expression is explicitly cast to
> UINT64/INT64 to fit the target size.
> 
> An example will be:
> UINT32 a,b;
> // a and b can be any unsigned int type with rank less than UINT64, like
> // UINT8, UINT16, etc.
> UINT64 c;
> c = (UINT64) (a + b);
> 
> Some static code checkers may warn that the expression result might
> overflow within the rank of "int" (integer promotions) and the result is
> then cast to a bigger size.
> 
> The commit refines codes by the following rules:
> 1). When the expression is possible to overflow the range of unsigned int/
> int:
> c = (UINT64)a + b;
> 
> 2). When the expression will not overflow within the rank of "int", remove
> the explicit type casts:
> c = a + b;
> 
> 3). When the expression will be cast to pointer of possible greater size:
> UINT32 a,b;
> VOID *c;
> c = (VOID *)(UINTN)(a + b); --> c = (VOID *)((UINTN)a + b);
> 
> 4). When one side of a comparison expression contains only operands with
> rank less than UINT32:
> UINT8 a;
> UINT16 b;
> UINTN c;
> if ((UINTN)(a + b) > c) {...} --> if (((UINT32)a + b) > c) {...}
> 
> For rule 4), if we remove the 'UINTN' type cast like:
> if (a + b > c) {...}
> The VS compiler will complain with warning C4018 (signed/unsigned
> mismatch, level 3 warning) due to promoting 'a + b' to type 'int'.
> 
> Cc: Jiewen Yao <jiewen.yao@intel.com>
> Contributed-under: TianoCore Contribution Agreement 1.0
> Signed-off-by: Hao Wu <hao.a.wu@intel.com>
> ---
>  IntelFspWrapperPkg/FspNotifyDxe/LoadBelow4G.c        |  4 ++--
>  IntelFspWrapperPkg/Library/BaseFspApiLib/FspApiLib.c | 12 ++++++------
>  2 files changed, 8 insertions(+), 8 deletions(-)
> 
> diff --git a/IntelFspWrapperPkg/FspNotifyDxe/LoadBelow4G.c
> b/IntelFspWrapperPkg/FspNotifyDxe/LoadBelow4G.c
> index 6f06e24..089413c 100644
> --- a/IntelFspWrapperPkg/FspNotifyDxe/LoadBelow4G.c
> +++ b/IntelFspWrapperPkg/FspNotifyDxe/LoadBelow4G.c
> @@ -1,6 +1,6 @@
>  /** @file
> 
> -Copyright (c) 2015, Intel Corporation. All rights reserved.<BR>
> +Copyright (c) 2015 - 2017, Intel Corporation. All rights reserved.<BR>
> 
>  This program and the accompanying materials
>  are licensed and made available under the terms and conditions
> @@ -115,7 +115,7 @@ RelocateImageUnder4GIfNeeded (
>    // Align buffer on section boundary
>    //
>    ImageContext.ImageAddress += ImageContext.SectionAlignment - 1;
> -  ImageContext.ImageAddress &=
> ~((EFI_PHYSICAL_ADDRESS)(ImageContext.SectionAlignment - 1));
> +  ImageContext.ImageAddress &=
> ~((EFI_PHYSICAL_ADDRESS)ImageContext.SectionAlignment - 1);
>    //
>    // Load the image to our new buffer
>    //
> diff --git a/IntelFspWrapperPkg/Library/BaseFspApiLib/FspApiLib.c
> b/IntelFspWrapperPkg/Library/BaseFspApiLib/FspApiLib.c
> index 162d244..accd6e4 100644
> --- a/IntelFspWrapperPkg/Library/BaseFspApiLib/FspApiLib.c
> +++ b/IntelFspWrapperPkg/Library/BaseFspApiLib/FspApiLib.c
> @@ -1,7 +1,7 @@
>  /** @file
>    Provide FSP API related function.
> 
> -  Copyright (c) 2014 - 2015, Intel Corporation. All rights reserved.<BR>
> +  Copyright (c) 2014 - 2017, Intel Corporation. All rights reserved.<BR>
>    This program and the accompanying materials
>    are licensed and made available under the terms and conditions of the BSD
> License
>    which accompanies this distribution.  The full text of the license may be
> found at
> @@ -98,7 +98,7 @@ CallFspInit (
>    EFI_STATUS          Status;
>    BOOLEAN             InterruptState;
> 
> -  FspInitApi = (FSP_INIT)(UINTN)(FspHeader->ImageBase +
> FspHeader->FspInitEntryOffset);
> +  FspInitApi = (FSP_INIT)((UINTN)FspHeader->ImageBase +
> FspHeader->FspInitEntryOffset);
>    InterruptState = SaveAndDisableInterrupts ();
>    Status = Execute32BitCode ((UINTN)FspInitApi, (UINTN)FspInitParams);
>    SetInterruptState (InterruptState);
> @@ -125,7 +125,7 @@ CallFspNotifyPhase (
>    EFI_STATUS          Status;
>    BOOLEAN             InterruptState;
> 
> -  NotifyPhaseApi = (FSP_NOTIFY_PHASE)(UINTN)(FspHeader->ImageBase +
> FspHeader->NotifyPhaseEntryOffset);
> +  NotifyPhaseApi = (FSP_NOTIFY_PHASE)((UINTN)FspHeader->ImageBase +
> FspHeader->NotifyPhaseEntryOffset);
>    InterruptState = SaveAndDisableInterrupts ();
>    Status = Execute32BitCode ((UINTN)NotifyPhaseApi,
> (UINTN)NotifyPhaseParams);
>    SetInterruptState (InterruptState);
> @@ -152,7 +152,7 @@ CallFspMemoryInit (
>    EFI_STATUS          Status;
>    BOOLEAN             InterruptState;
> 
> -  FspMemoryInitApi = (FSP_MEMORY_INIT)(UINTN)(FspHeader->ImageBase +
> FspHeader->FspMemoryInitEntryOffset);
> +  FspMemoryInitApi = (FSP_MEMORY_INIT)((UINTN)FspHeader->ImageBase +
> FspHeader->FspMemoryInitEntryOffset);
>    InterruptState = SaveAndDisableInterrupts ();
>    Status = Execute32BitCode ((UINTN)FspMemoryInitApi,
> (UINTN)FspMemoryInitParams);
>    SetInterruptState (InterruptState);
> @@ -179,7 +179,7 @@ CallTempRamExit (
>    EFI_STATUS          Status;
>    BOOLEAN             InterruptState;
> 
> -  TempRamExitApi = (FSP_TEMP_RAM_EXIT)(UINTN)(FspHeader->ImageBase
> + FspHeader->TempRamExitEntryOffset);
> +  TempRamExitApi = (FSP_TEMP_RAM_EXIT)((UINTN)FspHeader->ImageBase
> + FspHeader->TempRamExitEntryOffset);
>    InterruptState = SaveAndDisableInterrupts ();
>    Status = Execute32BitCode ((UINTN)TempRamExitApi,
> (UINTN)TempRamExitParam);
>    SetInterruptState (InterruptState);
> @@ -206,7 +206,7 @@ CallFspSiliconInit (
>    EFI_STATUS          Status;
>    BOOLEAN             InterruptState;
> 
> -  FspSiliconInitApi = (FSP_SILICON_INIT)(UINTN)(FspHeader->ImageBase +
> FspHeader->FspSiliconInitEntryOffset);
> +  FspSiliconInitApi = (FSP_SILICON_INIT)((UINTN)FspHeader->ImageBase +
> FspHeader->FspSiliconInitEntryOffset);
>    InterruptState = SaveAndDisableInterrupts ();
>    Status = Execute32BitCode ((UINTN)FspSiliconInitApi,
> (UINTN)FspSiliconInitParam);
>    SetInterruptState (InterruptState);
> --
> 1.9.5.msysgit.0



^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH v3 05/12] IntelFsp2WrapperPkg: Refine casting expression result to bigger size
  2017-02-25  5:12 ` [PATCH v3 05/12] IntelFsp2WrapperPkg: " Hao Wu
@ 2017-02-25  5:51   ` Yao, Jiewen
  0 siblings, 0 replies; 25+ messages in thread
From: Yao, Jiewen @ 2017-02-25  5:51 UTC (permalink / raw)
  To: Wu, Hao A, edk2-devel@lists.01.org

Reviewed-by: jiewen.yao@intel.com

> -----Original Message-----
> From: Wu, Hao A
> Sent: Saturday, February 25, 2017 1:12 PM
> To: edk2-devel@lists.01.org
> Cc: Wu, Hao A <hao.a.wu@intel.com>; Yao, Jiewen <jiewen.yao@intel.com>
> Subject: [PATCH v3 05/12] IntelFsp2WrapperPkg: Refine casting expression result
> to bigger size
> 
> There are cases that the operands of an expression are all with rank less
> than UINT64/INT64 and the result of the expression is explicitly cast to
> UINT64/INT64 to fit the target size.
> 
> An example will be:
> UINT32 a,b;
> // a and b can be any unsigned int type with rank less than UINT64, like
> // UINT8, UINT16, etc.
> UINT64 c;
> c = (UINT64) (a + b);
> 
> Some static code checkers may warn that the expression result might
> overflow within the rank of "int" (integer promotions) and the result is
> then cast to a bigger size.
> 
> The commit refines codes by the following rules:
> 1). When the expression is possible to overflow the range of unsigned int/
> int:
> c = (UINT64)a + b;
> 
> 2). When the expression will not overflow within the rank of "int", remove
> the explicit type casts:
> c = a + b;
> 
> 3). When the expression will be cast to pointer of possible greater size:
> UINT32 a,b;
> VOID *c;
> c = (VOID *)(UINTN)(a + b); --> c = (VOID *)((UINTN)a + b);
> 
> 4). When one side of a comparison expression contains only operands with
> rank less than UINT32:
> UINT8 a;
> UINT16 b;
> UINTN c;
> if ((UINTN)(a + b) > c) {...} --> if (((UINT32)a + b) > c) {...}
> 
> For rule 4), if we remove the 'UINTN' type cast like:
> if (a + b > c) {...}
> The VS compiler will complain with warning C4018 (signed/unsigned
> mismatch, level 3 warning) due to promoting 'a + b' to type 'int'.
> 
> Cc: Jiewen Yao <jiewen.yao@intel.com>
> Contributed-under: TianoCore Contribution Agreement 1.0
> Signed-off-by: Hao Wu <hao.a.wu@intel.com>
> ---
>  IntelFsp2WrapperPkg/FspWrapperNotifyDxe/LoadBelow4G.c               |
> 4 ++--
>  IntelFsp2WrapperPkg/Library/BaseFspWrapperApiLib/FspWrapperApiLib.c | 10
> +++++-----
>  2 files changed, 7 insertions(+), 7 deletions(-)
> 
> diff --git a/IntelFsp2WrapperPkg/FspWrapperNotifyDxe/LoadBelow4G.c
> b/IntelFsp2WrapperPkg/FspWrapperNotifyDxe/LoadBelow4G.c
> index ff2f563..dc5ef89 100644
> --- a/IntelFsp2WrapperPkg/FspWrapperNotifyDxe/LoadBelow4G.c
> +++ b/IntelFsp2WrapperPkg/FspWrapperNotifyDxe/LoadBelow4G.c
> @@ -1,6 +1,6 @@
>  /** @file
> 
> -Copyright (c) 2015 - 2016, Intel Corporation. All rights reserved.<BR>
> +Copyright (c) 2015 - 2017, Intel Corporation. All rights reserved.<BR>
> 
>  This program and the accompanying materials
>  are licensed and made available under the terms and conditions
> @@ -115,7 +115,7 @@ RelocateImageUnder4GIfNeeded (
>    // Align buffer on section boundary
>    //
>    ImageContext.ImageAddress += ImageContext.SectionAlignment - 1;
> -  ImageContext.ImageAddress &=
> ~((EFI_PHYSICAL_ADDRESS)(ImageContext.SectionAlignment - 1));
> +  ImageContext.ImageAddress &=
> ~((EFI_PHYSICAL_ADDRESS)ImageContext.SectionAlignment - 1);
>    //
>    // Load the image to our new buffer
>    //
> diff --git
> a/IntelFsp2WrapperPkg/Library/BaseFspWrapperApiLib/FspWrapperApiLib.c
> b/IntelFsp2WrapperPkg/Library/BaseFspWrapperApiLib/FspWrapperApiLib.c
> index 8cf136f..38de415 100644
> --- a/IntelFsp2WrapperPkg/Library/BaseFspWrapperApiLib/FspWrapperApiLib.c
> +++
> b/IntelFsp2WrapperPkg/Library/BaseFspWrapperApiLib/FspWrapperApiLib.c
> @@ -1,7 +1,7 @@
>  /** @file
>    Provide FSP API related function.
> 
> -  Copyright (c) 2014 - 2016, Intel Corporation. All rights reserved.<BR>
> +  Copyright (c) 2014 - 2017, Intel Corporation. All rights reserved.<BR>
>    This program and the accompanying materials
>    are licensed and made available under the terms and conditions of the BSD
> License
>    which accompanies this distribution.  The full text of the license may be
> found at
> @@ -99,7 +99,7 @@ CallFspNotifyPhase (
>      return EFI_DEVICE_ERROR;
>    }
> 
> -  NotifyPhaseApi = (FSP_NOTIFY_PHASE)(UINTN)(FspHeader->ImageBase +
> FspHeader->NotifyPhaseEntryOffset);
> +  NotifyPhaseApi = (FSP_NOTIFY_PHASE)((UINTN)FspHeader->ImageBase +
> FspHeader->NotifyPhaseEntryOffset);
>    InterruptState = SaveAndDisableInterrupts ();
>    Status = Execute32BitCode ((UINTN)NotifyPhaseApi,
> (UINTN)NotifyPhaseParams, (UINTN)NULL);
>    SetInterruptState (InterruptState);
> @@ -132,7 +132,7 @@ CallFspMemoryInit (
>      return EFI_DEVICE_ERROR;
>    }
> 
> -  FspMemoryInitApi = (FSP_MEMORY_INIT)(UINTN)(FspHeader->ImageBase +
> FspHeader->FspMemoryInitEntryOffset);
> +  FspMemoryInitApi = (FSP_MEMORY_INIT)((UINTN)FspHeader->ImageBase +
> FspHeader->FspMemoryInitEntryOffset);
>    InterruptState = SaveAndDisableInterrupts ();
>    Status = Execute32BitCode ((UINTN)FspMemoryInitApi,
> (UINTN)FspmUpdDataPtr, (UINTN)HobListPtr);
>    SetInterruptState (InterruptState);
> @@ -163,7 +163,7 @@ CallTempRamExit (
>      return EFI_DEVICE_ERROR;
>    }
> 
> -  TempRamExitApi = (FSP_TEMP_RAM_EXIT)(UINTN)(FspHeader->ImageBase
> + FspHeader->TempRamExitEntryOffset);
> +  TempRamExitApi = (FSP_TEMP_RAM_EXIT)((UINTN)FspHeader->ImageBase
> + FspHeader->TempRamExitEntryOffset);
>    InterruptState = SaveAndDisableInterrupts ();
>    Status = Execute32BitCode ((UINTN)TempRamExitApi,
> (UINTN)TempRamExitParam, (UINTN)NULL);
>    SetInterruptState (InterruptState);
> @@ -194,7 +194,7 @@ CallFspSiliconInit (
>      return EFI_DEVICE_ERROR;
>    }
> 
> -  FspSiliconInitApi = (FSP_SILICON_INIT)(UINTN)(FspHeader->ImageBase +
> FspHeader->FspSiliconInitEntryOffset);
> +  FspSiliconInitApi = (FSP_SILICON_INIT)((UINTN)FspHeader->ImageBase +
> FspHeader->FspSiliconInitEntryOffset);
>    InterruptState = SaveAndDisableInterrupts ();
>    Status = Execute32BitCode ((UINTN)FspSiliconInitApi,
> (UINTN)FspsUpdDataPtr, (UINTN)NULL);
>    SetInterruptState (InterruptState);
> --
> 1.9.5.msysgit.0



^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH v3 07/12] NetworkPkg: Refine casting expression result to bigger size
  2017-02-25  5:12 ` [PATCH v3 07/12] NetworkPkg: " Hao Wu
@ 2017-02-27  2:21   ` Wu, Jiaxin
  0 siblings, 0 replies; 25+ messages in thread
From: Wu, Jiaxin @ 2017-02-27  2:21 UTC (permalink / raw)
  To: Wu, Hao A, edk2-devel@lists.01.org; +Cc: Fu, Siyuan

Reviewed-by: Wu Jiaxin <jiaxin.wu@intel.com>


Thanks,
Jiaxin

> -----Original Message-----
> From: Wu, Hao A
> Sent: Saturday, February 25, 2017 1:13 PM
> To: edk2-devel@lists.01.org
> Cc: Wu, Hao A <hao.a.wu@intel.com>; Fu, Siyuan <siyuan.fu@intel.com>;
> Wu, Jiaxin <jiaxin.wu@intel.com>
> Subject: [PATCH v3 07/12] NetworkPkg: Refine casting expression result to
> bigger size
> 
> There are cases that the operands of an expression are all with rank less
> than UINT64/INT64 and the result of the expression is explicitly cast to
> UINT64/INT64 to fit the target size.
> 
> An example will be:
> UINT32 a,b;
> // a and b can be any unsigned int type with rank less than UINT64, like
> // UINT8, UINT16, etc.
> UINT64 c;
> c = (UINT64) (a + b);
> 
> Some static code checkers may warn that the expression result might
> overflow within the rank of "int" (integer promotions) and the result is
> then cast to a bigger size.
> 
> The commit refines codes by the following rules:
> 1). When the expression is possible to overflow the range of unsigned int/
> int:
> c = (UINT64)a + b;
> 
> 2). When the expression will not overflow within the rank of "int", remove
> the explicit type casts:
> c = a + b;
> 
> 3). When the expression will be cast to pointer of possible greater size:
> UINT32 a,b;
> VOID *c;
> c = (VOID *)(UINTN)(a + b); --> c = (VOID *)((UINTN)a + b);
> 
> 4). When one side of a comparison expression contains only operands with
> rank less than UINT32:
> UINT8 a;
> UINT16 b;
> UINTN c;
> if ((UINTN)(a + b) > c) {...} --> if (((UINT32)a + b) > c) {...}
> 
> For rule 4), if we remove the 'UINTN' type cast like:
> if (a + b > c) {...}
> The VS compiler will complain with warning C4018 (signed/unsigned
> mismatch, level 3 warning) due to promoting 'a + b' to type 'int'.
> 
> Cc: Siyuan Fu <siyuan.fu@intel.com>
> Cc: Jiaxin Wu <jiaxin.wu@intel.com>
> Contributed-under: TianoCore Contribution Agreement 1.0
> Signed-off-by: Hao Wu <hao.a.wu@intel.com>
> ---
>  NetworkPkg/IpSecDxe/Ikev2/Payload.c   |  4 ++--
>  NetworkPkg/IpSecDxe/IpSecConfigImpl.c |  8 ++++----
>  NetworkPkg/IpSecDxe/IpSecConfigImpl.h |  4 ++--
>  NetworkPkg/Mtftp6Dxe/Mtftp6Support.c  |  4 ++--
>  NetworkPkg/UefiPxeBcDxe/PxeBcImpl.c   | 10 +++++-----
>  5 files changed, 15 insertions(+), 15 deletions(-)
> 
> diff --git a/NetworkPkg/IpSecDxe/Ikev2/Payload.c
> b/NetworkPkg/IpSecDxe/Ikev2/Payload.c
> index f32b3a8..237743b 100644
> --- a/NetworkPkg/IpSecDxe/Ikev2/Payload.c
> +++ b/NetworkPkg/IpSecDxe/Ikev2/Payload.c
> @@ -2,7 +2,7 @@
>    The implementation of Payloads Creation.
> 
>    (C) Copyright 2015 Hewlett-Packard Development Company, L.P.<BR>
> -  Copyright (c) 2010 - 2016, Intel Corporation. All rights reserved.<BR>
> +  Copyright (c) 2010 - 2017, Intel Corporation. All rights reserved.<BR>
> 
>    This program and the accompanying materials
>    are licensed and made available under the terms and conditions of the BSD
> License
> @@ -1748,7 +1748,7 @@ Ikev2EncodeSa (
>        Transform->Header.NextPayload   =
> IKE_TRANSFORM_NEXT_PAYLOAD_MORE;
>        Transform->Header.PayloadLength = HTONS ((UINT16)TransformSize);
> 
> -      if (TransformIndex == (UINTN)(ProposalData->NumTransforms - 1)) {
> +      if (TransformIndex == ((UINT32)ProposalData->NumTransforms - 1)) {
>          Transform->Header.NextPayload =
> IKE_TRANSFORM_NEXT_PAYLOAD_NONE;
>        }
> 
> diff --git a/NetworkPkg/IpSecDxe/IpSecConfigImpl.c
> b/NetworkPkg/IpSecDxe/IpSecConfigImpl.c
> index cfee978..4a51bff 100644
> --- a/NetworkPkg/IpSecDxe/IpSecConfigImpl.c
> +++ b/NetworkPkg/IpSecDxe/IpSecConfigImpl.c
> @@ -1,7 +1,7 @@
>  /** @file
>    The implementation of IPSEC_CONFIG_PROTOCOL.
> 
> -  Copyright (c) 2009 - 2016, Intel Corporation. All rights reserved.<BR>
> +  Copyright (c) 2009 - 2017, Intel Corporation. All rights reserved.<BR>
> 
>    This program and the accompanying materials
>    are licensed and made available under the terms and conditions of the BSD
> License
> @@ -1152,7 +1152,7 @@ SetSpdEntry (
>    // Do Padding for the different Arch.
>    //
>    SpdEntrySize  = ALIGN_VARIABLE (sizeof (IPSEC_SPD_ENTRY));
> -  SpdEntrySize  = ALIGN_VARIABLE (SpdEntrySize +
> (UINTN)SIZE_OF_SPD_SELECTOR (SpdSel));
> +  SpdEntrySize  = ALIGN_VARIABLE (SpdEntrySize + SIZE_OF_SPD_SELECTOR
> (SpdSel));
>    SpdEntrySize += IpSecGetSizeOfEfiSpdData (SpdData);
> 
>    SpdEntry = AllocateZeroPool (SpdEntrySize);
> @@ -1357,7 +1357,7 @@ SetSadEntry (
>    }
> 
>    if (SaData->SpdSelector != NULL) {
> -    SadEntrySize += SadEntrySize + (UINTN)SIZE_OF_SPD_SELECTOR (SaData-
> >SpdSelector);
> +    SadEntrySize += SadEntrySize + SIZE_OF_SPD_SELECTOR (SaData-
> >SpdSelector);
>    }
>    SadEntry      = AllocateZeroPool (SadEntrySize);
> 
> @@ -1458,7 +1458,7 @@ SetSadEntry (
>        SadEntry->Data->SpdEntry = SpdEntry;
>        SadEntry->Data->SpdSelector = (EFI_IPSEC_SPD_SELECTOR *)((UINT8
> *)SadEntry +
>                                                                  SadEntrySize -
> -                                                                (UINTN)SIZE_OF_SPD_SELECTOR (SaData-
> >SpdSelector)
> +                                                                SIZE_OF_SPD_SELECTOR (SaData-
> >SpdSelector)
>                                                                  );
>        DuplicateSpdSelector (
>         (EFI_IPSEC_CONFIG_SELECTOR *) SadEntry->Data->SpdSelector,
> diff --git a/NetworkPkg/IpSecDxe/IpSecConfigImpl.h
> b/NetworkPkg/IpSecDxe/IpSecConfigImpl.h
> index 3e365da..23e6880 100644
> --- a/NetworkPkg/IpSecDxe/IpSecConfigImpl.h
> +++ b/NetworkPkg/IpSecDxe/IpSecConfigImpl.h
> @@ -1,7 +1,7 @@
>  /** @file
>    Definitions related to IPSEC_CONFIG_PROTOCOL implementations.
> 
> -  Copyright (c) 2009 - 2011, Intel Corporation. All rights reserved.<BR>
> +  Copyright (c) 2009 - 2017, Intel Corporation. All rights reserved.<BR>
> 
>    This program and the accompanying materials
>    are licensed and made available under the terms and conditions of the BSD
> License
> @@ -38,7 +38,7 @@
>  #define IPSECCONFIG_VARIABLE_NAME       L"IpSecConfig"
>  #define IPSECCONFIG_STATUS_NAME         L"IpSecStatus"
> 
> -#define SIZE_OF_SPD_SELECTOR(x) (UINTN) (sizeof
> (EFI_IPSEC_SPD_SELECTOR) \
> +#define SIZE_OF_SPD_SELECTOR(x) (sizeof (EFI_IPSEC_SPD_SELECTOR) \
>         + sizeof (EFI_IP_ADDRESS_INFO) * ((x)->LocalAddressCount + (x)-
> >RemoteAddressCount))
> 
>  #define FIX_REF_BUF_ADDR(addr, base)    addr = (VOID *) ((UINTN) (addr) -
> (UINTN) (base))
> diff --git a/NetworkPkg/Mtftp6Dxe/Mtftp6Support.c
> b/NetworkPkg/Mtftp6Dxe/Mtftp6Support.c
> index 64df901..e6b4127 100644
> --- a/NetworkPkg/Mtftp6Dxe/Mtftp6Support.c
> +++ b/NetworkPkg/Mtftp6Dxe/Mtftp6Support.c
> @@ -1,7 +1,7 @@
>  /** @file
>    Mtftp6 support functions implementation.
> 
> -  Copyright (c) 2009 - 2016, Intel Corporation. All rights reserved.<BR>
> +  Copyright (c) 2009 - 2017, Intel Corporation. All rights reserved.<BR>
> 
>    This program and the accompanying materials
>    are licensed and made available under the terms and conditions of the BSD
> License
> @@ -223,7 +223,7 @@ Mtftp6RemoveBlockNum (
>        *TotalBlock  = Num;
> 
>        if (Range->Round > 0) {
> -        *TotalBlock += Range->Bound +  MultU64x32 ((UINT64) (Range->Round
> -1), (UINT32)(Range->Bound + 1)) + 1;
> +        *TotalBlock += Range->Bound +  MultU64x32 (Range->Round - 1,
> (UINT32)(Range->Bound + 1)) + 1;
>        }
> 
>        if (Range->Start > Range->Bound) {
> diff --git a/NetworkPkg/UefiPxeBcDxe/PxeBcImpl.c
> b/NetworkPkg/UefiPxeBcDxe/PxeBcImpl.c
> index e24c573..36477e9 100644
> --- a/NetworkPkg/UefiPxeBcDxe/PxeBcImpl.c
> +++ b/NetworkPkg/UefiPxeBcDxe/PxeBcImpl.c
> @@ -1,7 +1,7 @@
>  /** @file
>    This implementation of EFI_PXE_BASE_CODE_PROTOCOL and
> EFI_LOAD_FILE_PROTOCOL.
> 
> -  Copyright (c) 2007 - 2016, Intel Corporation. All rights reserved.<BR>
> +  Copyright (c) 2007 - 2017, Intel Corporation. All rights reserved.<BR>
> 
>    This program and the accompanying materials
>    are licensed and made available under the terms and conditions of the BSD
> License
> @@ -95,8 +95,8 @@ EfiPxeBcStart (
>      //
>      // Configure block size for TFTP as a default value to handle all link layers.
>      //
> -    Private->BlockSize = (UINTN) (Private->Ip6MaxPacketSize -
> -                           PXEBC_DEFAULT_UDP_OVERHEAD_SIZE -
> PXEBC_DEFAULT_TFTP_OVERHEAD_SIZE);
> +    Private->BlockSize = Private->Ip6MaxPacketSize -
> +                           PXEBC_DEFAULT_UDP_OVERHEAD_SIZE -
> PXEBC_DEFAULT_TFTP_OVERHEAD_SIZE;
> 
>      //
>      // PXE over IPv6 starts here, initialize the fields and list header.
> @@ -148,8 +148,8 @@ EfiPxeBcStart (
>      //
>      // Configure block size for TFTP as a default value to handle all link layers.
>      //
> -    Private->BlockSize = (UINTN) (Private->Ip4MaxPacketSize -
> -                           PXEBC_DEFAULT_UDP_OVERHEAD_SIZE -
> PXEBC_DEFAULT_TFTP_OVERHEAD_SIZE);
> +    Private->BlockSize = Private->Ip4MaxPacketSize -
> +                           PXEBC_DEFAULT_UDP_OVERHEAD_SIZE -
> PXEBC_DEFAULT_TFTP_OVERHEAD_SIZE;
> 
>      //
>      // PXE over IPv4 starts here, initialize the fields.
> --
> 1.9.5.msysgit.0



^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH v3 10/12] ShellPkg: Refine casting expression result to bigger size
  2017-02-25  5:12 ` [PATCH v3 10/12] ShellPkg: " Hao Wu
@ 2017-02-27  2:22   ` Ni, Ruiyu
  2017-02-27 16:38   ` Carsey, Jaben
  1 sibling, 0 replies; 25+ messages in thread
From: Ni, Ruiyu @ 2017-02-27  2:22 UTC (permalink / raw)
  To: Wu, Hao A, edk2-devel@lists.01.org; +Cc: Carsey, Jaben

Reviewed-by: Ruiyu Ni <ruiyu.ni@intel.com>

Thanks/Ray

> -----Original Message-----
> From: Wu, Hao A
> Sent: Saturday, February 25, 2017 1:13 PM
> To: edk2-devel@lists.01.org
> Cc: Wu, Hao A <hao.a.wu@intel.com>; Carsey, Jaben
> <jaben.carsey@intel.com>; Ni, Ruiyu <ruiyu.ni@intel.com>
> Subject: [PATCH v3 10/12] ShellPkg: Refine casting expression result to bigger
> size
> 
> There are cases that the operands of an expression are all with rank less than
> UINT64/INT64 and the result of the expression is explicitly cast to
> UINT64/INT64 to fit the target size.
> 
> An example will be:
> UINT32 a,b;
> // a and b can be any unsigned int type with rank less than UINT64, like //
> UINT8, UINT16, etc.
> UINT64 c;
> c = (UINT64) (a + b);
> 
> Some static code checkers may warn that the expression result might
> overflow within the rank of "int" (integer promotions) and the result is then
> cast to a bigger size.
> 
> The commit refines codes by the following rules:
> 1). When the expression is possible to overflow the range of unsigned int/
> int:
> c = (UINT64)a + b;
> 
> 2). When the expression will not overflow within the rank of "int", remove
> the explicit type casts:
> c = a + b;
> 
> 3). When the expression will be cast to pointer of possible greater size:
> UINT32 a,b;
> VOID *c;
> c = (VOID *)(UINTN)(a + b); --> c = (VOID *)((UINTN)a + b);
> 
> 4). When one side of a comparison expression contains only operands with
> rank less than UINT32:
> UINT8 a;
> UINT16 b;
> UINTN c;
> if ((UINTN)(a + b) > c) {...} --> if (((UINT32)a + b) > c) {...}
> 
> For rule 4), if we remove the 'UINTN' type cast like:
> if (a + b > c) {...}
> The VS compiler will complain with warning C4018 (signed/unsigned
> mismatch, level 3 warning) due to promoting 'a + b' to type 'int'.
> 
> Cc: Jaben Carsey <jaben.carsey@intel.com>
> Cc: Ruiyu Ni <ruiyu.ni@intel.com>
> Contributed-under: TianoCore Contribution Agreement 1.0
> Signed-off-by: Hao Wu <hao.a.wu@intel.com>
> ---
>  ShellPkg/Library/UefiShellDebug1CommandsLib/HexEdit/BufferImage.c
> | 8 ++++----
> 
> ShellPkg/Library/UefiShellDebug1CommandsLib/UefiShellDebug1Commands
> Lib.c | 4 ++--
>  ShellPkg/Library/UefiShellLib/UefiShellLib.c                             | 4 ++--
>  3 files changed, 8 insertions(+), 8 deletions(-)
> 
> diff --git
> a/ShellPkg/Library/UefiShellDebug1CommandsLib/HexEdit/BufferImage.c
> b/ShellPkg/Library/UefiShellDebug1CommandsLib/HexEdit/BufferImage.c
> index 68d2443..1048ecd 100644
> --- a/ShellPkg/Library/UefiShellDebug1CommandsLib/HexEdit/BufferImage.c
> +++
> b/ShellPkg/Library/UefiShellDebug1CommandsLib/HexEdit/BufferImage.c
> @@ -2,7 +2,7 @@
>    Defines HBufferImage - the view of the file that is visible at any point,
>    as well as the event handlers for editing the file
> 
> -  Copyright (c) 2005 - 2014, Intel Corporation. All rights reserved. <BR>
> +  Copyright (c) 2005 - 2017, Intel Corporation. All rights reserved.
> + <BR>
>    This program and the accompanying materials
>    are licensed and made available under the terms and conditions of the BSD
> License
>    which accompanies this distribution.  The full text of the license may be
> found at @@ -1108,15 +1108,15 @@ HBufferImageCharToHex (
>    // change the character to hex
>    //
>    if (Char >= L'0' && Char <= L'9') {
> -    return (INTN) (Char - L'0');
> +    return (Char - L'0');
>    }
> 
>    if (Char >= L'a' && Char <= L'f') {
> -    return (INTN) (Char - L'a' + 10);
> +    return (Char - L'a' + 10);
>    }
> 
>    if (Char >= L'A' && Char <= L'F') {
> -    return (INTN) (Char - L'A' + 10);
> +    return (Char - L'A' + 10);
>    }
> 
>    return -1;
> diff --git
> a/ShellPkg/Library/UefiShellDebug1CommandsLib/UefiShellDebug1Comman
> dsLib.c
> b/ShellPkg/Library/UefiShellDebug1CommandsLib/UefiShellDebug1Comman
> dsLib.c
> index 6ebf002..a0e249e 100644
> ---
> a/ShellPkg/Library/UefiShellDebug1CommandsLib/UefiShellDebug1Comman
> dsLib.c
> +++
> b/ShellPkg/Library/UefiShellDebug1CommandsLib/UefiShellDebug1Comman
> d
> +++ sLib.c
> @@ -1,7 +1,7 @@
>  /** @file
>    Main file for NULL named library for debug1 profile shell command
> functions.
> 
> -  Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>
> +  Copyright (c) 2010 - 2017, Intel Corporation. All rights
> + reserved.<BR>
>    This program and the accompanying materials
>    are licensed and made available under the terms and conditions of the BSD
> License
>    which accompanies this distribution.  The full text of the license may be
> found at @@ -193,7 +193,7 @@ HexCharToUintn (
>      return Char - L'0';
>    }
> 
> -  return (UINTN) (10 + CharToUpper (Char) - L'A');
> +  return (10 + CharToUpper (Char) - L'A');
>  }
> 
>  /**
> diff --git a/ShellPkg/Library/UefiShellLib/UefiShellLib.c
> b/ShellPkg/Library/UefiShellLib/UefiShellLib.c
> index 536db3c..55e8a67 100644
> --- a/ShellPkg/Library/UefiShellLib/UefiShellLib.c
> +++ b/ShellPkg/Library/UefiShellLib/UefiShellLib.c
> @@ -3,7 +3,7 @@
> 
>    (C) Copyright 2016 Hewlett Packard Enterprise Development LP<BR>
>    Copyright 2016 Dell Inc.
> -  Copyright (c) 2006 - 2016, Intel Corporation. All rights reserved.<BR>
> +  Copyright (c) 2006 - 2017, Intel Corporation. All rights
> + reserved.<BR>
>    This program and the accompanying materials
>    are licensed and made available under the terms and conditions of the BSD
> License
>    which accompanies this distribution.  The full text of the license may be
> found at @@ -3755,7 +3755,7 @@ InternalShellHexCharToUintn (
>      return Char - L'0';
>    }
> 
> -  return (UINTN) (10 + InternalShellCharToUpper (Char) - L'A');
> +  return (10 + InternalShellCharToUpper (Char) - L'A');
>  }
> 
>  /**
> --
> 1.9.5.msysgit.0



^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH v3 03/12] FatPkg: Refine casting expression result to bigger size
  2017-02-25  5:12 ` [PATCH v3 03/12] FatPkg: " Hao Wu
@ 2017-02-27  5:07   ` Ni, Ruiyu
  0 siblings, 0 replies; 25+ messages in thread
From: Ni, Ruiyu @ 2017-02-27  5:07 UTC (permalink / raw)
  To: Wu, Hao A, edk2-devel@lists.01.org; +Cc: Wu, Hao A

Reviewed-by: Ruiyu Ni <ruiyu.ni@intel.com>

Thanks/Ray

> -----Original Message-----
> From: edk2-devel [mailto:edk2-devel-bounces@lists.01.org] On Behalf Of
> Hao Wu
> Sent: Saturday, February 25, 2017 1:12 PM
> To: edk2-devel@lists.01.org
> Cc: Wu, Hao A <hao.a.wu@intel.com>; Ni, Ruiyu <ruiyu.ni@intel.com>
> Subject: [edk2] [PATCH v3 03/12] FatPkg: Refine casting expression result to
> bigger size
> 
> There are cases that the operands of an expression are all with rank less than
> UINT64/INT64 and the result of the expression is explicitly cast to
> UINT64/INT64 to fit the target size.
> 
> An example will be:
> UINT32 a,b;
> // a and b can be any unsigned int type with rank less than UINT64, like //
> UINT8, UINT16, etc.
> UINT64 c;
> c = (UINT64) (a + b);
> 
> Some static code checkers may warn that the expression result might
> overflow within the rank of "int" (integer promotions) and the result is then
> cast to a bigger size.
> 
> The commit refines codes by the following rules:
> 1). When the expression is possible to overflow the range of unsigned int/
> int:
> c = (UINT64)a + b;
> 
> 2). When the expression will not overflow within the rank of "int", remove
> the explicit type casts:
> c = a + b;
> 
> 3). When the expression will be cast to pointer of possible greater size:
> UINT32 a,b;
> VOID *c;
> c = (VOID *)(UINTN)(a + b); --> c = (VOID *)((UINTN)a + b);
> 
> 4). When one side of a comparison expression contains only operands with
> rank less than UINT32:
> UINT8 a;
> UINT16 b;
> UINTN c;
> if ((UINTN)(a + b) > c) {...} --> if (((UINT32)a + b) > c) {...}
> 
> For rule 4), if we remove the 'UINTN' type cast like:
> if (a + b > c) {...}
> The VS compiler will complain with warning C4018 (signed/unsigned
> mismatch, level 3 warning) due to promoting 'a + b' to type 'int'.
> 
> Cc: Ruiyu Ni <ruiyu.ni@intel.com>
> Contributed-under: TianoCore Contribution Agreement 1.0
> Signed-off-by: Hao Wu <hao.a.wu@intel.com>
> ---
>  FatPkg/EnhancedFatDxe/ReadWrite.c | 4 ++--
>  FatPkg/FatPei/FatLiteAccess.c     | 4 ++--
>  2 files changed, 4 insertions(+), 4 deletions(-)
> 
> diff --git a/FatPkg/EnhancedFatDxe/ReadWrite.c
> b/FatPkg/EnhancedFatDxe/ReadWrite.c
> index a6e0ec4..ad3c260 100644
> --- a/FatPkg/EnhancedFatDxe/ReadWrite.c
> +++ b/FatPkg/EnhancedFatDxe/ReadWrite.c
> @@ -1,7 +1,7 @@
>  /** @file
>    Functions that perform file read/write.
> 
> -Copyright (c) 2005 - 2015, Intel Corporation. All rights reserved.<BR>
> +Copyright (c) 2005 - 2017, Intel Corporation. All rights reserved.<BR>
>  This program and the accompanying materials are licensed and made
> available  under the terms and conditions of the BSD License which
> accompanies this  distribution. The full text of the license may be found at
> @@ -173,7 +173,7 @@ Done:
>      // Update IFile->Position, if everything is all right
>      //
>      CurrentPos      = ODir->CurrentPos;
> -    IFile->Position = (UINT64) (CurrentPos * sizeof (FAT_DIRECTORY_ENTRY));
> +    IFile->Position = CurrentPos * sizeof (FAT_DIRECTORY_ENTRY);
>    }
> 
>    return Status;
> diff --git a/FatPkg/FatPei/FatLiteAccess.c b/FatPkg/FatPei/FatLiteAccess.c
> index 1106345..a92c5bf 100644
> --- a/FatPkg/FatPei/FatLiteAccess.c
> +++ b/FatPkg/FatPei/FatLiteAccess.c
> @@ -1,7 +1,7 @@
>  /** @file
>    FAT file system access routines for FAT recovery PEIM
> 
> -Copyright (c) 2006 - 2013, Intel Corporation. All rights reserved.<BR>
> +Copyright (c) 2006 - 2017, Intel Corporation. All rights reserved.<BR>
> 
>  This program and the accompanying materials are licensed and made
> available  under the terms and conditions of the BSD License which
> accompanies this @@ -393,7 +393,7 @@ FatReadFile (
>    } else {
> 
>      if ((File->Attributes & FAT_ATTR_DIRECTORY) == 0) {
> -      Size = Size < (File->FileSize - File->CurrentPos) ? Size : (UINTN) (File-
> >FileSize - File->CurrentPos);
> +      Size = Size < (File->FileSize - File->CurrentPos) ? Size :
> + (File->FileSize - File->CurrentPos);
>      }
>      //
>      // This is a normal cluster based file
> --
> 1.9.5.msysgit.0
> 
> _______________________________________________
> edk2-devel mailing list
> edk2-devel@lists.01.org
> https://lists.01.org/mailman/listinfo/edk2-devel


^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH v3 04/12] IntelFrameworkModulePkg: Refine casting expression result to bigger size
  2017-02-25  5:12 ` [PATCH v3 04/12] IntelFrameworkModulePkg: " Hao Wu
@ 2017-02-27  7:06   ` Fan, Jeff
  0 siblings, 0 replies; 25+ messages in thread
From: Fan, Jeff @ 2017-02-27  7:06 UTC (permalink / raw)
  To: Wu, Hao A, edk2-devel@lists.01.org

Reviewed-by: Jeff Fan <jeff.fan@intel.com>

-----Original Message-----
From: Wu, Hao A 
Sent: Saturday, February 25, 2017 1:12 PM
To: edk2-devel@lists.01.org
Cc: Wu, Hao A; Fan, Jeff
Subject: [PATCH v3 04/12] IntelFrameworkModulePkg: Refine casting expression result to bigger size

There are cases that the operands of an expression are all with rank less than UINT64/INT64 and the result of the expression is explicitly cast to
UINT64/INT64 to fit the target size.

An example will be:
UINT32 a,b;
// a and b can be any unsigned int type with rank less than UINT64, like // UINT8, UINT16, etc.
UINT64 c;
c = (UINT64) (a + b);

Some static code checkers may warn that the expression result might overflow within the rank of "int" (integer promotions) and the result is then cast to a bigger size.

The commit refines codes by the following rules:
1). When the expression is possible to overflow the range of unsigned int/
int:
c = (UINT64)a + b;

2). When the expression will not overflow within the rank of "int", remove the explicit type casts:
c = a + b;

3). When the expression will be cast to pointer of possible greater size:
UINT32 a,b;
VOID *c;
c = (VOID *)(UINTN)(a + b); --> c = (VOID *)((UINTN)a + b);

4). When one side of a comparison expression contains only operands with rank less than UINT32:
UINT8 a;
UINT16 b;
UINTN c;
if ((UINTN)(a + b) > c) {...} --> if (((UINT32)a + b) > c) {...}

For rule 4), if we remove the 'UINTN' type cast like:
if (a + b > c) {...}
The VS compiler will complain with warning C4018 (signed/unsigned mismatch, level 3 warning) due to promoting 'a + b' to type 'int'.

Cc: Jeff Fan <jeff.fan@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Hao Wu <hao.a.wu@intel.com>
---
 IntelFrameworkModulePkg/Csm/BiosThunk/KeyboardDxe/BiosKeyboard.c |  4 ++--
 IntelFrameworkModulePkg/Csm/BiosThunk/Snp16Dxe/BiosSnp16.c       |  4 ++--
 IntelFrameworkModulePkg/Csm/BiosThunk/Snp16Dxe/Misc.c            | 14 +++++++-------
 IntelFrameworkModulePkg/Csm/BiosThunk/VideoDxe/BiosVideo.c       |  4 ++--
 IntelFrameworkModulePkg/Csm/LegacyBiosDxe/LegacyBios.c           |  6 +++---
 IntelFrameworkModulePkg/Csm/LegacyBiosDxe/LegacyBootSupport.c    |  4 ++--
 IntelFrameworkModulePkg/Library/GenericBdsLib/BdsBoot.c          |  2 +-
 IntelFrameworkModulePkg/Library/GenericBdsLib/BdsMisc.c          |  4 ++--
 IntelFrameworkModulePkg/Library/LegacyBootManagerLib/LegacyBm.c  |  2 +-
 IntelFrameworkModulePkg/Universal/BdsDxe/FrontPage.c             |  4 ++--
 IntelFrameworkModulePkg/Universal/CpuIoDxe/CpuIo.c               |  4 ++--
 11 files changed, 26 insertions(+), 26 deletions(-)

diff --git a/IntelFrameworkModulePkg/Csm/BiosThunk/KeyboardDxe/BiosKeyboard.c b/IntelFrameworkModulePkg/Csm/BiosThunk/KeyboardDxe/BiosKeyboard.c
index a597d99..742d009 100644
--- a/IntelFrameworkModulePkg/Csm/BiosThunk/KeyboardDxe/BiosKeyboard.c
+++ b/IntelFrameworkModulePkg/Csm/BiosThunk/KeyboardDxe/BiosKeyboard.c
@@ -1,7 +1,7 @@
 /** @file
   ConsoleOut Routines that speak VGA.
 
-Copyright (c) 2006 - 2016, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2006 - 2017, Intel Corporation. All rights reserved.<BR>
 
 This program and the accompanying materials  are licensed and made available under the terms and conditions @@ -418,7 +418,7 @@ BiosKeyboardDriverBindingStart (
     // Check bit 6 of Feature Byte 2.
     // If it is set, then Int 16 Func 09 is supported
     //
-    if (*(UINT8 *)(UINTN) ((Regs.X.ES << 4) + Regs.X.BX + 0x06) & 0x40) {
+    if (*(UINT8 *) (((UINTN) Regs.X.ES << 4) + Regs.X.BX + 0x06) & 
+ 0x40) {
       //
       // Get Keyboard Functionality
       //
diff --git a/IntelFrameworkModulePkg/Csm/BiosThunk/Snp16Dxe/BiosSnp16.c b/IntelFrameworkModulePkg/Csm/BiosThunk/Snp16Dxe/BiosSnp16.c
index a2a7797..b586a91 100644
--- a/IntelFrameworkModulePkg/Csm/BiosThunk/Snp16Dxe/BiosSnp16.c
+++ b/IntelFrameworkModulePkg/Csm/BiosThunk/Snp16Dxe/BiosSnp16.c
@@ -1,6 +1,6 @@
 /** @file
 
-Copyright (c) 1999 - 2014, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 1999 - 2017, Intel Corporation. All rights reserved.<BR>
 
 This program and the accompanying materials  are licensed and made available under the terms and conditions @@ -1858,7 +1858,7 @@ Undi16SimpleNetworkIsr (
 
       CopyMem (
         Frame,
-        (VOID *)(UINTN) ((SimpleNetworkDevice->Isr.FrameSegSel << 4) + SimpleNetworkDevice->Isr.FrameOffset),
+        (VOID *) (((UINTN) SimpleNetworkDevice->Isr.FrameSegSel << 4) + 
+ SimpleNetworkDevice->Isr.FrameOffset),
         SimpleNetworkDevice->Isr.BufferLength
         );
       Frame = Frame + SimpleNetworkDevice->Isr.BufferLength;
diff --git a/IntelFrameworkModulePkg/Csm/BiosThunk/Snp16Dxe/Misc.c b/IntelFrameworkModulePkg/Csm/BiosThunk/Snp16Dxe/Misc.c
index 4750b2f..a1dc867 100644
--- a/IntelFrameworkModulePkg/Csm/BiosThunk/Snp16Dxe/Misc.c
+++ b/IntelFrameworkModulePkg/Csm/BiosThunk/Snp16Dxe/Misc.c
@@ -1,7 +1,7 @@
 /** @file
   Helper Routines that use a PXE-enabled NIC option ROM.
  
-Copyright (c) 1999 - 2014, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 1999 - 2017, Intel Corporation. All rights reserved.<BR>
 
 This program and the accompanying materials  are licensed and made available under the terms and conditions @@ -49,7 +49,7 @@ CacheVectorAddress (  {
   UINT32  *Address;
 
-  Address                          = (UINT32 *)(UINTN) (IVT_BASE + VectorNumber * 4);
+  Address                          = (UINT32 *) ((UINTN) IVT_BASE + VectorNumber * 4);
   CachedVectorAddress[VectorNumber] = *Address;
   return EFI_SUCCESS;
 }
@@ -68,7 +68,7 @@ RestoreCachedVectorAddress (  {
   UINT32  *Address;
 
-  Address  = (UINT32 *)(UINTN) (IVT_BASE + VectorNumber * 4);
+  Address  = (UINT32 *) ((UINTN) IVT_BASE + VectorNumber * 4);
   *Address = CachedVectorAddress[VectorNumber];
   return EFI_SUCCESS;
 }
@@ -469,7 +469,7 @@ LaunchBaseCode (
 
   RomIdTableAddress = (UNDI_ROMID_T *) (RomAddress + OPTION_ROM_PTR->PxeRomIdOffset);
 
-  if ((UINTN) (OPTION_ROM_PTR->PxeRomIdOffset + RomIdTableAddress->StructLength) > RomLength) {
+  if (((UINT32)OPTION_ROM_PTR->PxeRomIdOffset + 
+ RomIdTableAddress->StructLength) > RomLength) {
     DEBUG ((DEBUG_ERROR, "ROM ID Offset Error\n\r"));
     return EFI_NOT_FOUND;
   }
@@ -754,10 +754,10 @@ LaunchBaseCode (
   Print_Undi_Loader_Table (UndiLoaderTable);
 
   DEBUG ((DEBUG_NET, "Display the PXENV+ and !PXE tables exported by NIC\n\r"));
-  Print_PXENV_Table ((VOID *)(UINTN)((UndiLoaderTable->PXENVptr.Segment << 4) | UndiLoaderTable->PXENVptr.Offset));
-  Print_PXE_Table ((VOID *)(UINTN)((UndiLoaderTable->PXEptr.Segment << 4) + UndiLoaderTable->PXEptr.Offset));
+  Print_PXENV_Table ((VOID *)(((UINTN)UndiLoaderTable->PXENVptr.Segment 
+ << 4) | UndiLoaderTable->PXENVptr.Offset));
+  Print_PXE_Table ((VOID *)(((UINTN)UndiLoaderTable->PXEptr.Segment << 
+ 4) + UndiLoaderTable->PXEptr.Offset));
 
-  Pxe = (PXE_T *)(UINTN)((UndiLoaderTable->PXEptr.Segment << 4) + UndiLoaderTable->PXEptr.Offset);
+  Pxe = (PXE_T *)(((UINTN)UndiLoaderTable->PXEptr.Segment << 4) + 
+ UndiLoaderTable->PXEptr.Offset);
   SimpleNetworkDevice->Nii.Id = (UINT64)(UINTN) Pxe;
 
   gBS->FreePool (Buffer);
diff --git a/IntelFrameworkModulePkg/Csm/BiosThunk/VideoDxe/BiosVideo.c b/IntelFrameworkModulePkg/Csm/BiosThunk/VideoDxe/BiosVideo.c
index f1c8b29..08672cf 100644
--- a/IntelFrameworkModulePkg/Csm/BiosThunk/VideoDxe/BiosVideo.c
+++ b/IntelFrameworkModulePkg/Csm/BiosThunk/VideoDxe/BiosVideo.c
@@ -1,7 +1,7 @@
 /** @file
   ConsoleOut Routines that speak VGA.
 
-Copyright (c) 2007 - 2014, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2007 - 2017, Intel Corporation. All rights reserved.<BR>
 
 This program and the accompanying materials  are licensed and made available under the terms and conditions @@ -1714,7 +1714,7 @@ BiosVideoCheckForVbe (
     //
     // Make sure the FrameBufferSize does not exceed the max available frame buffer size reported by VEB.
     //
-    ASSERT (CurrentModeData->FrameBufferSize <= (UINTN)(BiosVideoPrivate->VbeInformationBlock->TotalMemory * 64 * 1024));
+    ASSERT (CurrentModeData->FrameBufferSize <= 
+ ((UINT32)BiosVideoPrivate->VbeInformationBlock->TotalMemory * 64 * 
+ 1024));
     
     BiosVideoPrivate->ModeData = ModeBuffer;
   }
diff --git a/IntelFrameworkModulePkg/Csm/LegacyBiosDxe/LegacyBios.c b/IntelFrameworkModulePkg/Csm/LegacyBiosDxe/LegacyBios.c
index dd2e2b9..3ead2d9 100644
--- a/IntelFrameworkModulePkg/Csm/LegacyBiosDxe/LegacyBios.c
+++ b/IntelFrameworkModulePkg/Csm/LegacyBiosDxe/LegacyBios.c
@@ -1,6 +1,6 @@
 /** @file
 
-Copyright (c) 2006 - 2013, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2006 - 2017, Intel Corporation. All rights reserved.<BR>
 
 This program and the accompanying materials  are licensed and made available under the terms and conditions @@ -144,7 +144,7 @@ LegacyBiosGetLegacyRegion (
      );
 
   if (Regs.X.AX == 0) {
-    *LegacyMemoryAddress  = (VOID *) (UINTN) ((Regs.X.DS << 4) + Regs.X.BX);
+    *LegacyMemoryAddress  = (VOID *) (((UINTN) Regs.X.DS << 4) + 
+ Regs.X.BX);
     Status = EFI_SUCCESS;
   } else {
     Status = EFI_OUT_OF_RESOURCES;
@@ -728,7 +728,7 @@ InstallSmbiosEventCallback (
   }
   
   if ((mStructureTableAddress != 0) && 
-      (mStructureTablePages < (UINTN) EFI_SIZE_TO_PAGES (EntryPointStructure->TableLength))) {
+      (mStructureTablePages < EFI_SIZE_TO_PAGES 
+ ((UINT32)EntryPointStructure->TableLength))) {
     //
     // If original buffer is not enough for the new SMBIOS table, free original buffer and re-allocate
     //
diff --git a/IntelFrameworkModulePkg/Csm/LegacyBiosDxe/LegacyBootSupport.c b/IntelFrameworkModulePkg/Csm/LegacyBiosDxe/LegacyBootSupport.c
index 52bcae2..1e098b3 100644
--- a/IntelFrameworkModulePkg/Csm/LegacyBiosDxe/LegacyBootSupport.c
+++ b/IntelFrameworkModulePkg/Csm/LegacyBiosDxe/LegacyBootSupport.c
@@ -1,6 +1,6 @@
 /** @file
 
-Copyright (c) 2006 - 2015, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2006 - 2017, Intel Corporation. All rights reserved.<BR>
 
 This program and the accompanying materials  are licensed and made available under the terms and conditions @@ -91,7 +91,7 @@ PrintBbsTable (
     //
     // Print DescString
     //
-    String = (CHAR8 *)(UINTN)((BbsTable[Index].DescStringSegment << 4) + BbsTable[Index].DescStringOffset);
+    String = (CHAR8 *)(((UINTN)BbsTable[Index].DescStringSegment << 4) 
+ + BbsTable[Index].DescStringOffset);
     if (String != NULL) {
       DEBUG ((EFI_D_INFO," ("));
       for (SubIndex = 0; String[SubIndex] != 0; SubIndex++) { diff --git a/IntelFrameworkModulePkg/Library/GenericBdsLib/BdsBoot.c b/IntelFrameworkModulePkg/Library/GenericBdsLib/BdsBoot.c
index 628424d..d1da635 100644
--- a/IntelFrameworkModulePkg/Library/GenericBdsLib/BdsBoot.c
+++ b/IntelFrameworkModulePkg/Library/GenericBdsLib/BdsBoot.c
@@ -227,7 +227,7 @@ BdsBuildLegacyDevNameString (
   //
   // If current BBS entry has its description then use it.
   //
-  StringDesc = (UINT8 *) (UINTN) ((CurBBSEntry->DescStringSegment << 4) + CurBBSEntry->DescStringOffset);
+  StringDesc = (UINT8 *) (((UINTN) CurBBSEntry->DescStringSegment << 4) 
+ + CurBBSEntry->DescStringOffset);
   if (NULL != StringDesc) {
     //
     // Only get fisrt 32 characters, this is suggested by BBS spec diff --git a/IntelFrameworkModulePkg/Library/GenericBdsLib/BdsMisc.c b/IntelFrameworkModulePkg/Library/GenericBdsLib/BdsMisc.c
index 2ba511a..48938b0 100644
--- a/IntelFrameworkModulePkg/Library/GenericBdsLib/BdsMisc.c
+++ b/IntelFrameworkModulePkg/Library/GenericBdsLib/BdsMisc.c
@@ -569,11 +569,11 @@ CharToUint (
   )
 {
   if ((Char >= L'0') && (Char <= L'9')) {
-    return (UINTN) (Char - L'0');
+    return (Char - L'0');
   }
 
   if ((Char >= L'A') && (Char <= L'F')) {
-    return (UINTN) (Char - L'A' + 0xA);
+    return (Char - L'A' + 0xA);
   }
 
   ASSERT (FALSE);
diff --git a/IntelFrameworkModulePkg/Library/LegacyBootManagerLib/LegacyBm.c b/IntelFrameworkModulePkg/Library/LegacyBootManagerLib/LegacyBm.c
index 080a436..76902ec 100644
--- a/IntelFrameworkModulePkg/Library/LegacyBootManagerLib/LegacyBm.c
+++ b/IntelFrameworkModulePkg/Library/LegacyBootManagerLib/LegacyBm.c
@@ -176,7 +176,7 @@ LegacyBmBuildLegacyDevNameString (
   //
   // If current BBS entry has its description then use it.
   //
-  StringDesc = (CHAR8 *) (UINTN) ((CurBBSEntry->DescStringSegment << 4) + CurBBSEntry->DescStringOffset);
+  StringDesc = (CHAR8 *) (((UINTN) CurBBSEntry->DescStringSegment << 4) 
+ + CurBBSEntry->DescStringOffset);
   if (NULL != StringDesc) {
     //
     // Only get fisrt 32 characters, this is suggested by BBS spec diff --git a/IntelFrameworkModulePkg/Universal/BdsDxe/FrontPage.c b/IntelFrameworkModulePkg/Universal/BdsDxe/FrontPage.c
index c771974..3bae0be 100644
--- a/IntelFrameworkModulePkg/Universal/BdsDxe/FrontPage.c
+++ b/IntelFrameworkModulePkg/Universal/BdsDxe/FrontPage.c
@@ -1,7 +1,7 @@
 /** @file
   FrontPage routines to handle the callbacks and browser calls
 
-Copyright (c) 2004 - 2016, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2004 - 2017, Intel Corporation. All rights reserved.<BR>
 This program and the accompanying materials  are licensed and made available under the terms and conditions of the BSD License  which accompanies this distribution.  The full text of the license may be found at @@ -620,7 +620,7 @@ ConvertProcessorToString (
 
   if (Base10Exponent >= 6) {
     FreqMhz = ProcessorFrequency;
-    for (Index = 0; Index < (UINTN) (Base10Exponent - 6); Index++) {
+    for (Index = 0; Index < ((UINT32)Base10Exponent - 6); Index++) {
       FreqMhz *= 10;
     }
   } else {
diff --git a/IntelFrameworkModulePkg/Universal/CpuIoDxe/CpuIo.c b/IntelFrameworkModulePkg/Universal/CpuIoDxe/CpuIo.c
index 9db9dbe..9474606 100644
--- a/IntelFrameworkModulePkg/Universal/CpuIoDxe/CpuIo.c
+++ b/IntelFrameworkModulePkg/Universal/CpuIoDxe/CpuIo.c
@@ -1,7 +1,7 @@
 /** @file
   Uses the services of the I/O Library to produce the CPU I/O Protocol
 
-Copyright (c) 2004 - 2012, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2004 - 2017, Intel Corporation. All rights reserved.<BR>
 Copyright (c) 2017, AMD Incorporated. All rights reserved.<BR>
 
 This program and the accompanying materials                          
@@ -141,7 +141,7 @@ CpuIoCheckParameter (
   //
   // Check to see if Address is aligned
   //
-  if ((Address & (UINT64)(mInStride[Width] - 1)) != 0) {
+  if ((Address & ((UINT64)mInStride[Width] - 1)) != 0) {
     return EFI_UNSUPPORTED;
   }
 
--
1.9.5.msysgit.0



^ permalink raw reply related	[flat|nested] 25+ messages in thread

* Re: [PATCH v3 08/12] PcAtChipsetPkg: Refine casting expression result to bigger size
  2017-02-25  5:12 ` [PATCH v3 08/12] PcAtChipsetPkg: " Hao Wu
@ 2017-02-27  7:24   ` Ni, Ruiyu
  0 siblings, 0 replies; 25+ messages in thread
From: Ni, Ruiyu @ 2017-02-27  7:24 UTC (permalink / raw)
  To: Wu, Hao A, edk2-devel@lists.01.org

Reviewed-by: Ruiyu Ni <ruiyu.ni@intel.com>

Thanks/Ray

> -----Original Message-----
> From: Wu, Hao A
> Sent: Saturday, February 25, 2017 1:13 PM
> To: edk2-devel@lists.01.org
> Cc: Wu, Hao A <hao.a.wu@intel.com>; Ni, Ruiyu <ruiyu.ni@intel.com>
> Subject: [PATCH v3 08/12] PcAtChipsetPkg: Refine casting expression result
> to bigger size
> 
> There are cases that the operands of an expression are all with rank less than
> UINT64/INT64 and the result of the expression is explicitly cast to
> UINT64/INT64 to fit the target size.
> 
> An example will be:
> UINT32 a,b;
> // a and b can be any unsigned int type with rank less than UINT64, like //
> UINT8, UINT16, etc.
> UINT64 c;
> c = (UINT64) (a + b);
> 
> Some static code checkers may warn that the expression result might
> overflow within the rank of "int" (integer promotions) and the result is then
> cast to a bigger size.
> 
> The commit refines codes by the following rules:
> 1). When the expression is possible to overflow the range of unsigned int/
> int:
> c = (UINT64)a + b;
> 
> 2). When the expression will not overflow within the rank of "int", remove
> the explicit type casts:
> c = a + b;
> 
> 3). When the expression will be cast to pointer of possible greater size:
> UINT32 a,b;
> VOID *c;
> c = (VOID *)(UINTN)(a + b); --> c = (VOID *)((UINTN)a + b);
> 
> 4). When one side of a comparison expression contains only operands with
> rank less than UINT32:
> UINT8 a;
> UINT16 b;
> UINTN c;
> if ((UINTN)(a + b) > c) {...} --> if (((UINT32)a + b) > c) {...}
> 
> For rule 4), if we remove the 'UINTN' type cast like:
> if (a + b > c) {...}
> The VS compiler will complain with warning C4018 (signed/unsigned
> mismatch, level 3 warning) due to promoting 'a + b' to type 'int'.
> 
> Cc: Ruiyu Ni <ruiyu.ni@intel.com>
> Contributed-under: TianoCore Contribution Agreement 1.0
> Signed-off-by: Hao Wu <hao.a.wu@intel.com>
> ---
>  PcAtChipsetPkg/Library/SerialIoLib/SerialPortLib.c | 18 +++++++++---------
>  1 file changed, 9 insertions(+), 9 deletions(-)
> 
> diff --git a/PcAtChipsetPkg/Library/SerialIoLib/SerialPortLib.c
> b/PcAtChipsetPkg/Library/SerialIoLib/SerialPortLib.c
> index dcb43fa..95e0db7 100644
> --- a/PcAtChipsetPkg/Library/SerialIoLib/SerialPortLib.c
> +++ b/PcAtChipsetPkg/Library/SerialIoLib/SerialPortLib.c
> @@ -1,7 +1,7 @@
>  /** @file
>    UART Serial Port library functions
> 
> -  Copyright (c) 2006 - 2016, Intel Corporation. All rights reserved.<BR>
> +  Copyright (c) 2006 - 2017, Intel Corporation. All rights
> + reserved.<BR>
>    This program and the accompanying materials
>    are licensed and made available under the terms and conditions of the BSD
> License
>    which accompanies this distribution.  The full text of the license may be
> found at @@ -91,19 +91,19 @@ SerialPortInitialize (
>    // Set communications format
>    //
>    OutputData = (UINT8) ((DLAB << 7) | (gBreakSet << 6) | (gParity << 3) |
> (gStop << 2) | Data);
> -  IoWrite8 ((UINTN) (gUartBase + LCR_OFFSET), OutputData);
> +  IoWrite8 (gUartBase + LCR_OFFSET, OutputData);
> 
>    //
>    // Configure baud rate
>    //
> -  IoWrite8 ((UINTN) (gUartBase + BAUD_HIGH_OFFSET), (UINT8) (Divisor >>
> 8));
> -  IoWrite8 ((UINTN) (gUartBase + BAUD_LOW_OFFSET), (UINT8) (Divisor &
> 0xff));
> +  IoWrite8 (gUartBase + BAUD_HIGH_OFFSET, (UINT8) (Divisor >> 8));
> +  IoWrite8 (gUartBase + BAUD_LOW_OFFSET, (UINT8) (Divisor & 0xff));
> 
>    //
>    // Switch back to bank 0
>    //
>    OutputData = (UINT8) ((~DLAB << 7) | (gBreakSet << 6) | (gParity << 3) |
> (gStop << 2) | Data);
> -  IoWrite8 ((UINTN) (gUartBase + LCR_OFFSET), OutputData);
> +  IoWrite8 (gUartBase + LCR_OFFSET, OutputData);
> 
>    return RETURN_SUCCESS;
>  }
> @@ -470,19 +470,19 @@ SerialPortSetAttributes (
>    // Set communications format
>    //
>    OutputData = (UINT8) ((DLAB << 7) | (gBreakSet << 6) | (LcrParity << 3) |
> (LcrStop << 2) | LcrData);
> -  IoWrite8 ((UINTN) (gUartBase + LCR_OFFSET), OutputData);
> +  IoWrite8 (gUartBase + LCR_OFFSET, OutputData);
> 
>    //
>    // Configure baud rate
>    //
> -  IoWrite8 ((UINTN) (gUartBase + BAUD_HIGH_OFFSET), (UINT8) (Divisor >>
> 8));
> -  IoWrite8 ((UINTN) (gUartBase + BAUD_LOW_OFFSET), (UINT8) (Divisor &
> 0xff));
> +  IoWrite8 (gUartBase + BAUD_HIGH_OFFSET, (UINT8) (Divisor >> 8));
> +  IoWrite8 (gUartBase + BAUD_LOW_OFFSET, (UINT8) (Divisor & 0xff));
> 
>    //
>    // Switch back to bank 0
>    //
>    OutputData = (UINT8) ((~DLAB << 7) | (gBreakSet << 6) | (LcrParity << 3) |
> (LcrStop << 2) | LcrData);
> -  IoWrite8 ((UINTN) (gUartBase + LCR_OFFSET), OutputData);
> +  IoWrite8 (gUartBase + LCR_OFFSET, OutputData);
> 
>    return RETURN_SUCCESS;
>  }
> --
> 1.9.5.msysgit.0



^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH v3 11/12] SourceLevelDebugPkg: Refine casting expression result to bigger size
  2017-02-25  5:12 ` [PATCH v3 11/12] SourceLevelDebugPkg: " Hao Wu
@ 2017-02-27  7:27   ` Fan, Jeff
  0 siblings, 0 replies; 25+ messages in thread
From: Fan, Jeff @ 2017-02-27  7:27 UTC (permalink / raw)
  To: Wu, Hao A, edk2-devel@lists.01.org

Reviewed-by: Jeff Fan <jeff.fan@intel.com>

-----Original Message-----
From: Wu, Hao A 
Sent: Saturday, February 25, 2017 1:13 PM
To: edk2-devel@lists.01.org
Cc: Wu, Hao A; Fan, Jeff
Subject: [PATCH v3 11/12] SourceLevelDebugPkg: Refine casting expression result to bigger size

There are cases that the operands of an expression are all with rank less than UINT64/INT64 and the result of the expression is explicitly cast to
UINT64/INT64 to fit the target size.

An example will be:
UINT32 a,b;
// a and b can be any unsigned int type with rank less than UINT64, like // UINT8, UINT16, etc.
UINT64 c;
c = (UINT64) (a + b);

Some static code checkers may warn that the expression result might overflow within the rank of "int" (integer promotions) and the result is then cast to a bigger size.

The commit refines codes by the following rules:
1). When the expression is possible to overflow the range of unsigned int/
int:
c = (UINT64)a + b;

2). When the expression will not overflow within the rank of "int", remove the explicit type casts:
c = a + b;

3). When the expression will be cast to pointer of possible greater size:
UINT32 a,b;
VOID *c;
c = (VOID *)(UINTN)(a + b); --> c = (VOID *)((UINTN)a + b);

4). When one side of a comparison expression contains only operands with rank less than UINT32:
UINT8 a;
UINT16 b;
UINTN c;
if ((UINTN)(a + b) > c) {...} --> if (((UINT32)a + b) > c) {...}

For rule 4), if we remove the 'UINTN' type cast like:
if (a + b > c) {...}
The VS compiler will complain with warning C4018 (signed/unsigned mismatch, level 3 warning) due to promoting 'a + b' to type 'int'.

Cc: Jeff Fan <jeff.fan@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Hao Wu <hao.a.wu@intel.com>
---
 SourceLevelDebugPkg/Library/DebugAgent/DxeDebugAgent/DxeDebugAgentLib.c         |  6 +++---
 SourceLevelDebugPkg/Library/DebugAgent/SecPeiDebugAgent/SecPeiDebugAgentLib.c   |  8 ++++----
 SourceLevelDebugPkg/Library/DebugAgent/SmmDebugAgent/SmmDebugAgentLib.c         |  6 +++---
 SourceLevelDebugPkg/Library/DebugCommunicationLibUsb/DebugCommunicationLibUsb.c | 18 +++++++++---------
 4 files changed, 19 insertions(+), 19 deletions(-)

diff --git a/SourceLevelDebugPkg/Library/DebugAgent/DxeDebugAgent/DxeDebugAgentLib.c b/SourceLevelDebugPkg/Library/DebugAgent/DxeDebugAgent/DxeDebugAgentLib.c
index a63932c..c74a1f6 100644
--- a/SourceLevelDebugPkg/Library/DebugAgent/DxeDebugAgent/DxeDebugAgentLib.c
+++ b/SourceLevelDebugPkg/Library/DebugAgent/DxeDebugAgent/DxeDebugAgent
+++ Lib.c
@@ -1,7 +1,7 @@
 /** @file
   Debug Agent library implementition for Dxe Core and Dxr modules.
 
-  Copyright (c) 2010 - 2015, Intel Corporation. All rights reserved.<BR>
+  Copyright (c) 2010 - 2017, Intel Corporation. All rights 
+ reserved.<BR>
   This program and the accompanying materials
   are licensed and made available under the terms and conditions of the BSD License
   which accompanies this distribution.  The full text of the license may be found at @@ -512,8 +512,8 @@ InitializeDebugAgent (
     if (Context != NULL) {
       Ia32Idtr =  (IA32_DESCRIPTOR *) Context;
       Ia32IdtEntry = (IA32_IDT_ENTRY *)(Ia32Idtr->Base);
-      MailboxLocation = (UINT64 *) (UINTN) (Ia32IdtEntry[DEBUG_MAILBOX_VECTOR].Bits.OffsetLow +
-                                  (UINT32) (Ia32IdtEntry[DEBUG_MAILBOX_VECTOR].Bits.OffsetHigh << 16));
+      MailboxLocation = (UINT64 *) ((UINTN) Ia32IdtEntry[DEBUG_MAILBOX_VECTOR].Bits.OffsetLow +
+                                   ((UINTN) 
+ Ia32IdtEntry[DEBUG_MAILBOX_VECTOR].Bits.OffsetHigh << 16));
       Mailbox = (DEBUG_AGENT_MAILBOX *)(UINTN)(*MailboxLocation);
       VerifyMailboxChecksum (Mailbox);
     }
diff --git a/SourceLevelDebugPkg/Library/DebugAgent/SecPeiDebugAgent/SecPeiDebugAgentLib.c b/SourceLevelDebugPkg/Library/DebugAgent/SecPeiDebugAgent/SecPeiDebugAgentLib.c
index 128c69f..b717e33 100644
--- a/SourceLevelDebugPkg/Library/DebugAgent/SecPeiDebugAgent/SecPeiDebugAgentLib.c
+++ b/SourceLevelDebugPkg/Library/DebugAgent/SecPeiDebugAgent/SecPeiDebu
+++ gAgentLib.c
@@ -1,7 +1,7 @@
 /** @file
   SEC Core Debug Agent Library instance implementition.
 
-  Copyright (c) 2010 - 2015, Intel Corporation. All rights reserved.<BR>
+  Copyright (c) 2010 - 2017, Intel Corporation. All rights 
+ reserved.<BR>
   This program and the accompanying materials
   are licensed and made available under the terms and conditions of the BSD License
   which accompanies this distribution.  The full text of the license may be found at @@ -213,7 +213,7 @@ GetMailboxPointer (
     // Fix up Debug Port handler and save new mailbox in IDT entry
     //
     Mailbox = (DEBUG_AGENT_MAILBOX *)((UINTN)Mailbox + ((UINTN)(MailboxLocationInHob) - (UINTN)MailboxLocationInIdt));
-    DebugPortHandle = (UINT64)((UINTN)Mailbox->DebugPortHandle + ((UINTN)(MailboxLocationInHob) - (UINTN)MailboxLocationInIdt));
+    DebugPortHandle = (UINTN)Mailbox->DebugPortHandle + 
+ ((UINTN)(MailboxLocationInHob) - (UINTN)MailboxLocationInIdt);
     UpdateMailboxContent (Mailbox, DEBUG_MAILBOX_DEBUG_PORT_HANDLE_INDEX, DebugPortHandle);
     *MailboxLocationInHob = (UINT64)(UINTN)Mailbox;
     SetLocationSavedMailboxPointerInIdtEntry (MailboxLocationInHob); @@ -582,8 +582,8 @@ InitializeDebugAgent (
     } else {
       Ia32Idtr =  (IA32_DESCRIPTOR *) Context;
       Ia32IdtEntry = (IA32_IDT_ENTRY *)(Ia32Idtr->Base);
-      MailboxLocationPointer = (UINT64 *) (UINTN) (Ia32IdtEntry[DEBUG_MAILBOX_VECTOR].Bits.OffsetLow +
-                                         (UINT32) (Ia32IdtEntry[DEBUG_MAILBOX_VECTOR].Bits.OffsetHigh << 16));
+      MailboxLocationPointer = (UINT64 *) ((UINTN) Ia32IdtEntry[DEBUG_MAILBOX_VECTOR].Bits.OffsetLow +
+                                          ((UINTN) 
+ Ia32IdtEntry[DEBUG_MAILBOX_VECTOR].Bits.OffsetHigh << 16));
       Mailbox = (DEBUG_AGENT_MAILBOX *) (UINTN)(*MailboxLocationPointer);
       //
       // Mailbox should valid and setup before executing thunk code diff --git a/SourceLevelDebugPkg/Library/DebugAgent/SmmDebugAgent/SmmDebugAgentLib.c b/SourceLevelDebugPkg/Library/DebugAgent/SmmDebugAgent/SmmDebugAgentLib.c
index 6216142..11afd32 100644
--- a/SourceLevelDebugPkg/Library/DebugAgent/SmmDebugAgent/SmmDebugAgentLib.c
+++ b/SourceLevelDebugPkg/Library/DebugAgent/SmmDebugAgent/SmmDebugAgent
+++ Lib.c
@@ -1,7 +1,7 @@
 /** @file
   Debug Agent library implementition.
 
-  Copyright (c) 2010 - 2016, Intel Corporation. All rights reserved.<BR>
+  Copyright (c) 2010 - 2017, Intel Corporation. All rights 
+ reserved.<BR>
   This program and the accompanying materials
   are licensed and made available under the terms and conditions of the BSD License
   which accompanies this distribution.  The full text of the license may be found at @@ -336,8 +336,8 @@ InitializeDebugAgent (
     } else {
       Ia32Idtr =  (IA32_DESCRIPTOR *) Context;
       Ia32IdtEntry = (IA32_IDT_ENTRY *)(Ia32Idtr->Base);
-      MailboxLocation = (UINT64 *) (UINTN) (Ia32IdtEntry[DEBUG_MAILBOX_VECTOR].Bits.OffsetLow + 
-                                  (UINT32) (Ia32IdtEntry[DEBUG_MAILBOX_VECTOR].Bits.OffsetHigh << 16));
+      MailboxLocation = (UINT64 *) ((UINTN) Ia32IdtEntry[DEBUG_MAILBOX_VECTOR].Bits.OffsetLow +
+                                   ((UINTN) 
+ Ia32IdtEntry[DEBUG_MAILBOX_VECTOR].Bits.OffsetHigh << 16));
       mMailboxPointer = (DEBUG_AGENT_MAILBOX *)(UINTN)(*MailboxLocation);
       VerifyMailboxChecksum (mMailboxPointer);
       //
diff --git a/SourceLevelDebugPkg/Library/DebugCommunicationLibUsb/DebugCommunicationLibUsb.c b/SourceLevelDebugPkg/Library/DebugCommunicationLibUsb/DebugCommunicationLibUsb.c
index d7829c2..d996f80 100644
--- a/SourceLevelDebugPkg/Library/DebugCommunicationLibUsb/DebugCommunicationLibUsb.c
+++ b/SourceLevelDebugPkg/Library/DebugCommunicationLibUsb/DebugCommunic
+++ ationLibUsb.c
@@ -1,7 +1,7 @@
 /** @file
   Debug Port Library implementation based on usb debug port.
 
-  Copyright (c) 2010 - 2015, Intel Corporation. All rights reserved.<BR>
+  Copyright (c) 2010 - 2017, Intel Corporation. All rights 
+ reserved.<BR>
   This program and the accompanying materials
   are licensed and made available under the terms and conditions of the BSD License
   which accompanies this distribution.  The full text of the license may be found at @@ -559,7 +559,7 @@ NeedReinitializeHardware(
   //
   // If the owner and in_use bit is not set, it means system is doing cold/warm boot or EHCI host controller is reset by system software.
   //
-  UsbDebugPortRegister = (USB_DEBUG_PORT_REGISTER *)(UINTN)(Handle->UsbDebugPortMemoryBase + Handle->DebugPortOffset);
+  UsbDebugPortRegister = (USB_DEBUG_PORT_REGISTER 
+ *)((UINTN)Handle->UsbDebugPortMemoryBase + Handle->DebugPortOffset);
   if ((MmioRead32((UINTN)&UsbDebugPortRegister->ControlStatus) & (USB_DEBUG_PORT_OWNER | USB_DEBUG_PORT_ENABLE | USB_DEBUG_PORT_IN_USE))
        != (USB_DEBUG_PORT_OWNER | USB_DEBUG_PORT_ENABLE | USB_DEBUG_PORT_IN_USE)) {
     Status = TRUE;
@@ -604,10 +604,10 @@ InitializeUsbDebugHardware (
   UINT8                     DebugPortNumber;
   UINT8                     Length;
 
-  UsbDebugPortRegister = (USB_DEBUG_PORT_REGISTER *)(UINTN)(Handle->UsbDebugPortMemoryBase + Handle->DebugPortOffset);
-  UsbHCSParam = (UINT32 *)(UINTN)(Handle->EhciMemoryBase + 0x04);
-  UsbCmd      = (UINT32 *)(UINTN)(Handle->EhciMemoryBase + 0x20);
-  UsbStatus   = (UINT32 *)(UINTN)(Handle->EhciMemoryBase + 0x24);
+  UsbDebugPortRegister = (USB_DEBUG_PORT_REGISTER 
+ *)((UINTN)Handle->UsbDebugPortMemoryBase + Handle->DebugPortOffset);  UsbHCSParam = (UINT32 *)((UINTN)Handle->EhciMemoryBase + 0x04);
+  UsbCmd      = (UINT32 *)((UINTN)Handle->EhciMemoryBase + 0x20);
+  UsbStatus   = (UINT32 *)((UINTN)Handle->EhciMemoryBase + 0x24);
 
   //
   // Check if the debug port is enabled and owned by myself.
@@ -652,7 +652,7 @@ InitializeUsbDebugHardware (
   //
   // Should find a device is connected at debug port
   //
-  PortStatus = (UINT32 *)(UINTN)(Handle->EhciMemoryBase + 0x64 + (DebugPortNumber - 1) * 4);
+  PortStatus = (UINT32 *)((UINTN)Handle->EhciMemoryBase + 0x64 + 
+ (DebugPortNumber - 1) * 4);
   if (!(MmioRead32((UINTN)PortStatus) & BIT0)) {
     Handle->Initialized = USBDBG_NO_DEV;
     return RETURN_NOT_FOUND;
@@ -870,7 +870,7 @@ DebugPortWriteBuffer (
     }
   }
 
-  UsbDebugPortRegister = (USB_DEBUG_PORT_REGISTER *)(UINTN)(UsbDebugPortHandle->UsbDebugPortMemoryBase + UsbDebugPortHandle->DebugPortOffset);
+  UsbDebugPortRegister = (USB_DEBUG_PORT_REGISTER 
+ *)((UINTN)UsbDebugPortHandle->UsbDebugPortMemoryBase + 
+ UsbDebugPortHandle->DebugPortOffset);
 
   while ((Total < NumberOfBytes)) {
     if (NumberOfBytes - Total > USB_DEBUG_PORT_MAX_PACKET_SIZE) { @@ -950,7 +950,7 @@ DebugPortPollBuffer (
     return TRUE;
   }
 
-  UsbDebugPortRegister = (USB_DEBUG_PORT_REGISTER *)(UINTN)(UsbDebugPortHandle->UsbDebugPortMemoryBase + UsbDebugPortHandle->DebugPortOffset);
+  UsbDebugPortRegister = (USB_DEBUG_PORT_REGISTER 
+ *)((UINTN)UsbDebugPortHandle->UsbDebugPortMemoryBase + 
+ UsbDebugPortHandle->DebugPortOffset);
 
   UsbDebugPortRegister->TokenPid = INPUT_PID;
   if (UsbDebugPortHandle->BulkInToggle == 0) {
--
1.9.5.msysgit.0



^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH v3 12/12] UefiCpuPkg: Refine casting expression result to bigger size
  2017-02-25  5:12 ` [PATCH v3 12/12] UefiCpuPkg: " Hao Wu
@ 2017-02-27  7:27   ` Fan, Jeff
  0 siblings, 0 replies; 25+ messages in thread
From: Fan, Jeff @ 2017-02-27  7:27 UTC (permalink / raw)
  To: Wu, Hao A, edk2-devel@lists.01.org

Reviewed-by: Jeff Fan <jeff.fan@intel.com>

-----Original Message-----
From: Wu, Hao A 
Sent: Saturday, February 25, 2017 1:13 PM
To: edk2-devel@lists.01.org
Cc: Wu, Hao A; Fan, Jeff
Subject: [PATCH v3 12/12] UefiCpuPkg: Refine casting expression result to bigger size

There are cases that the operands of an expression are all with rank less than UINT64/INT64 and the result of the expression is explicitly cast to
UINT64/INT64 to fit the target size.

An example will be:
UINT32 a,b;
// a and b can be any unsigned int type with rank less than UINT64, like // UINT8, UINT16, etc.
UINT64 c;
c = (UINT64) (a + b);

Some static code checkers may warn that the expression result might overflow within the rank of "int" (integer promotions) and the result is then cast to a bigger size.

The commit refines codes by the following rules:
1). When the expression is possible to overflow the range of unsigned int/
int:
c = (UINT64)a + b;

2). When the expression will not overflow within the rank of "int", remove the explicit type casts:
c = a + b;

3). When the expression will be cast to pointer of possible greater size:
UINT32 a,b;
VOID *c;
c = (VOID *)(UINTN)(a + b); --> c = (VOID *)((UINTN)a + b);

4). When one side of a comparison expression contains only operands with rank less than UINT32:
UINT8 a;
UINT16 b;
UINTN c;
if ((UINTN)(a + b) > c) {...} --> if (((UINT32)a + b) > c) {...}

For rule 4), if we remove the 'UINTN' type cast like:
if (a + b > c) {...}
The VS compiler will complain with warning C4018 (signed/unsigned mismatch, level 3 warning) due to promoting 'a + b' to type 'int'.

Cc: Jeff Fan <jeff.fan@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Hao Wu <hao.a.wu@intel.com>
---
 UefiCpuPkg/CpuIo2Dxe/CpuIo2Dxe.c              | 4 ++--
 UefiCpuPkg/CpuIo2Smm/CpuIo2Smm.c              | 4 ++--
 UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmStm.c | 8 ++++----
 UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.c    | 4 ++--
 UefiCpuPkg/PiSmmCpuDxeSmm/SmramSaveState.c    | 6 +++---
 5 files changed, 13 insertions(+), 13 deletions(-)

diff --git a/UefiCpuPkg/CpuIo2Dxe/CpuIo2Dxe.c b/UefiCpuPkg/CpuIo2Dxe/CpuIo2Dxe.c
index 60f4bbc..d19349d 100644
--- a/UefiCpuPkg/CpuIo2Dxe/CpuIo2Dxe.c
+++ b/UefiCpuPkg/CpuIo2Dxe/CpuIo2Dxe.c
@@ -1,7 +1,7 @@
 /** @file
   Produces the CPU I/O 2 Protocol.
 
-Copyright (c) 2009 - 2012, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2009 - 2017, Intel Corporation. All rights reserved.<BR>
 Copyright (c) 2017, AMD Incorporated. All rights reserved.<BR>
 
 This program and the accompanying materials                          
@@ -141,7 +141,7 @@ CpuIoCheckParameter (
   //
   // Check to see if Address is aligned
   //
-  if ((Address & (UINT64)(mInStride[Width] - 1)) != 0) {
+  if ((Address & ((UINT64)mInStride[Width] - 1)) != 0) {
     return EFI_UNSUPPORTED;
   }
 
diff --git a/UefiCpuPkg/CpuIo2Smm/CpuIo2Smm.c b/UefiCpuPkg/CpuIo2Smm/CpuIo2Smm.c
index 7b1ad37..20b8350 100644
--- a/UefiCpuPkg/CpuIo2Smm/CpuIo2Smm.c
+++ b/UefiCpuPkg/CpuIo2Smm/CpuIo2Smm.c
@@ -1,7 +1,7 @@
 /** @file
   Produces the SMM CPU I/O Protocol.
 
-Copyright (c) 2009 - 2012, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2009 - 2017, Intel Corporation. All rights reserved.<BR>
 This program and the accompanying materials                          
 are licensed and made available under the terms and conditions of the BSD License         
 which accompanies this distribution.  The full text of the license may be found at        
@@ -126,7 +126,7 @@ CpuIoCheckParameter (
   //
   // Check to see if Address is aligned
   //
-  if ((Address & (UINT64)(mStride[Width] - 1)) != 0) {
+  if ((Address & ((UINT64)mStride[Width] - 1)) != 0) {
     return EFI_UNSUPPORTED;
   }
 
diff --git a/UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmStm.c b/UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmStm.c
index bb123ba..03937dc 100644
--- a/UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmStm.c
+++ b/UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmStm.c
@@ -1,7 +1,7 @@
 /** @file
   SMM STM support functions
 
-  Copyright (c) 2015 - 2016, Intel Corporation. All rights reserved.<BR>
+  Copyright (c) 2015 - 2017, Intel Corporation. All rights 
+ reserved.<BR>
   This program and the accompanying materials
   are licensed and made available under the terms and conditions of the BSD License
   which accompanies this distribution.  The full text of the license may be found at @@ -276,8 +276,8 @@ SmmCpuFeaturesInstallSmiHandler (
   UINT32                         RegEdx;
   EFI_PROCESSOR_INFORMATION      ProcessorInfo;
 
-  CopyMem ((VOID *)(UINTN)(SmBase + TXT_SMM_PSD_OFFSET), &gcStmPsd, sizeof (gcStmPsd));
-  Psd = (TXT_PROCESSOR_SMM_DESCRIPTOR *)(VOID *)(UINTN)(SmBase + TXT_SMM_PSD_OFFSET);
+  CopyMem ((VOID *)((UINTN)SmBase + TXT_SMM_PSD_OFFSET), &gcStmPsd, 
+ sizeof (gcStmPsd));  Psd = (TXT_PROCESSOR_SMM_DESCRIPTOR *)(VOID 
+ *)((UINTN)SmBase + TXT_SMM_PSD_OFFSET);
   Psd->SmmGdtPtr = GdtBase;
   Psd->SmmGdtSize = (UINT32)GdtSize;
 
@@ -317,7 +317,7 @@ SmmCpuFeaturesInstallSmiHandler (
   // Copy template to CPU specific SMI handler location
   //
   CopyMem (
-    (VOID*)(UINTN)(SmBase + SMM_HANDLER_OFFSET),
+    (VOID*)((UINTN)SmBase + SMM_HANDLER_OFFSET),
     (VOID*)gcStmSmiHandlerTemplate,
     gcStmSmiHandlerSize
     );
diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.c b/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.c
index fc7714a..2519e28 100644
--- a/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.c
+++ b/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.c
@@ -1,7 +1,7 @@
 /** @file
 Agent Module to load other modules to deploy SMM Entry Vector for X86 CPU.
 
-Copyright (c) 2009 - 2016, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2009 - 2017, Intel Corporation. All rights reserved.<BR>
 This program and the accompanying materials  are licensed and made available under the terms and conditions of the BSD License  which accompanies this distribution.  The full text of the license may be found at @@ -1268,7 +1268,7 @@ AllocateAlignedCodePages (
       Status = gSmst->SmmFreePages (Memory, UnalignedPages);
       ASSERT_EFI_ERROR (Status);
     }
-    Memory         = (EFI_PHYSICAL_ADDRESS) (AlignedMemory + EFI_PAGES_TO_SIZE (Pages));
+    Memory         = AlignedMemory + EFI_PAGES_TO_SIZE (Pages);
     UnalignedPages = RealPages - Pages - UnalignedPages;
     if (UnalignedPages > 0) {
       //
diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/SmramSaveState.c b/UefiCpuPkg/PiSmmCpuDxeSmm/SmramSaveState.c
index b4bc0ec..3188d43 100644
--- a/UefiCpuPkg/PiSmmCpuDxeSmm/SmramSaveState.c
+++ b/UefiCpuPkg/PiSmmCpuDxeSmm/SmramSaveState.c
@@ -1,7 +1,7 @@
 /** @file
 Provides services to access SMRAM Save State Map
 
-Copyright (c) 2010 - 2016, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2010 - 2017, Intel Corporation. All rights reserved.<BR>
 This program and the accompanying materials  are licensed and made available under the terms and conditions of the BSD License  which accompanies this distribution.  The full text of the license may be found at @@ -690,7 +690,7 @@ InstallSmiHandler (
   //
   // Initialize PROCESSOR_SMM_DESCRIPTOR
   //
-  Psd = (PROCESSOR_SMM_DESCRIPTOR *)(VOID *)(UINTN)(SmBase + SMM_PSD_OFFSET);
+  Psd = (PROCESSOR_SMM_DESCRIPTOR *)(VOID *)((UINTN)SmBase + 
+ SMM_PSD_OFFSET);
   CopyMem (Psd, &gcPsd, sizeof (gcPsd));
   Psd->SmmGdtPtr = (UINT64)GdtBase;
   Psd->SmmGdtSize = (UINT32)GdtSize;
@@ -731,7 +731,7 @@ InstallSmiHandler (
   // Copy template to CPU specific SMI handler location
   //
   CopyMem (
-    (VOID*)(UINTN)(SmBase + SMM_HANDLER_OFFSET),
+    (VOID*)((UINTN)SmBase + SMM_HANDLER_OFFSET),
     (VOID*)gcSmiHandlerTemplate,
     gcSmiHandlerSize
     );
--
1.9.5.msysgit.0



^ permalink raw reply related	[flat|nested] 25+ messages in thread

* Re: [PATCH v3 10/12] ShellPkg: Refine casting expression result to bigger size
  2017-02-25  5:12 ` [PATCH v3 10/12] ShellPkg: " Hao Wu
  2017-02-27  2:22   ` Ni, Ruiyu
@ 2017-02-27 16:38   ` Carsey, Jaben
  1 sibling, 0 replies; 25+ messages in thread
From: Carsey, Jaben @ 2017-02-27 16:38 UTC (permalink / raw)
  To: Wu, Hao A, edk2-devel@lists.01.org; +Cc: Ni, Ruiyu, Carsey, Jaben

Reviewed-by: Jaben Carsey <jaben.carsey@intel.com>

> -----Original Message-----
> From: Wu, Hao A
> Sent: Friday, February 24, 2017 9:13 PM
> To: edk2-devel@lists.01.org
> Cc: Wu, Hao A <hao.a.wu@intel.com>; Carsey, Jaben
> <jaben.carsey@intel.com>; Ni, Ruiyu <ruiyu.ni@intel.com>
> Subject: [PATCH v3 10/12] ShellPkg: Refine casting expression result to bigger
> size
> Importance: High
> 
> There are cases that the operands of an expression are all with rank less
> than UINT64/INT64 and the result of the expression is explicitly cast to
> UINT64/INT64 to fit the target size.
> 
> An example will be:
> UINT32 a,b;
> // a and b can be any unsigned int type with rank less than UINT64, like
> // UINT8, UINT16, etc.
> UINT64 c;
> c = (UINT64) (a + b);
> 
> Some static code checkers may warn that the expression result might
> overflow within the rank of "int" (integer promotions) and the result is
> then cast to a bigger size.
> 
> The commit refines codes by the following rules:
> 1). When the expression is possible to overflow the range of unsigned int/
> int:
> c = (UINT64)a + b;
> 
> 2). When the expression will not overflow within the rank of "int", remove
> the explicit type casts:
> c = a + b;
> 
> 3). When the expression will be cast to pointer of possible greater size:
> UINT32 a,b;
> VOID *c;
> c = (VOID *)(UINTN)(a + b); --> c = (VOID *)((UINTN)a + b);
> 
> 4). When one side of a comparison expression contains only operands with
> rank less than UINT32:
> UINT8 a;
> UINT16 b;
> UINTN c;
> if ((UINTN)(a + b) > c) {...} --> if (((UINT32)a + b) > c) {...}
> 
> For rule 4), if we remove the 'UINTN' type cast like:
> if (a + b > c) {...}
> The VS compiler will complain with warning C4018 (signed/unsigned
> mismatch, level 3 warning) due to promoting 'a + b' to type 'int'.
> 
> Cc: Jaben Carsey <jaben.carsey@intel.com>
> Cc: Ruiyu Ni <ruiyu.ni@intel.com>
> Contributed-under: TianoCore Contribution Agreement 1.0
> Signed-off-by: Hao Wu <hao.a.wu@intel.com>
> ---
>  ShellPkg/Library/UefiShellDebug1CommandsLib/HexEdit/BufferImage.c
> | 8 ++++----
> 
> ShellPkg/Library/UefiShellDebug1CommandsLib/UefiShellDebug1Commands
> Lib.c | 4 ++--
>  ShellPkg/Library/UefiShellLib/UefiShellLib.c                             | 4 ++--
>  3 files changed, 8 insertions(+), 8 deletions(-)
> 
> diff --git
> a/ShellPkg/Library/UefiShellDebug1CommandsLib/HexEdit/BufferImage.c
> b/ShellPkg/Library/UefiShellDebug1CommandsLib/HexEdit/BufferImage.c
> index 68d2443..1048ecd 100644
> --- a/ShellPkg/Library/UefiShellDebug1CommandsLib/HexEdit/BufferImage.c
> +++
> b/ShellPkg/Library/UefiShellDebug1CommandsLib/HexEdit/BufferImage.c
> @@ -2,7 +2,7 @@
>    Defines HBufferImage - the view of the file that is visible at any point,
>    as well as the event handlers for editing the file
> 
> -  Copyright (c) 2005 - 2014, Intel Corporation. All rights reserved. <BR>
> +  Copyright (c) 2005 - 2017, Intel Corporation. All rights reserved. <BR>
>    This program and the accompanying materials
>    are licensed and made available under the terms and conditions of the BSD
> License
>    which accompanies this distribution.  The full text of the license may be
> found at
> @@ -1108,15 +1108,15 @@ HBufferImageCharToHex (
>    // change the character to hex
>    //
>    if (Char >= L'0' && Char <= L'9') {
> -    return (INTN) (Char - L'0');
> +    return (Char - L'0');
>    }
> 
>    if (Char >= L'a' && Char <= L'f') {
> -    return (INTN) (Char - L'a' + 10);
> +    return (Char - L'a' + 10);
>    }
> 
>    if (Char >= L'A' && Char <= L'F') {
> -    return (INTN) (Char - L'A' + 10);
> +    return (Char - L'A' + 10);
>    }
> 
>    return -1;
> diff --git
> a/ShellPkg/Library/UefiShellDebug1CommandsLib/UefiShellDebug1Comman
> dsLib.c
> b/ShellPkg/Library/UefiShellDebug1CommandsLib/UefiShellDebug1Comman
> dsLib.c
> index 6ebf002..a0e249e 100644
> ---
> a/ShellPkg/Library/UefiShellDebug1CommandsLib/UefiShellDebug1Comman
> dsLib.c
> +++
> b/ShellPkg/Library/UefiShellDebug1CommandsLib/UefiShellDebug1Comman
> dsLib.c
> @@ -1,7 +1,7 @@
>  /** @file
>    Main file for NULL named library for debug1 profile shell command
> functions.
> 
> -  Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>
> +  Copyright (c) 2010 - 2017, Intel Corporation. All rights reserved.<BR>
>    This program and the accompanying materials
>    are licensed and made available under the terms and conditions of the BSD
> License
>    which accompanies this distribution.  The full text of the license may be
> found at
> @@ -193,7 +193,7 @@ HexCharToUintn (
>      return Char - L'0';
>    }
> 
> -  return (UINTN) (10 + CharToUpper (Char) - L'A');
> +  return (10 + CharToUpper (Char) - L'A');
>  }
> 
>  /**
> diff --git a/ShellPkg/Library/UefiShellLib/UefiShellLib.c
> b/ShellPkg/Library/UefiShellLib/UefiShellLib.c
> index 536db3c..55e8a67 100644
> --- a/ShellPkg/Library/UefiShellLib/UefiShellLib.c
> +++ b/ShellPkg/Library/UefiShellLib/UefiShellLib.c
> @@ -3,7 +3,7 @@
> 
>    (C) Copyright 2016 Hewlett Packard Enterprise Development LP<BR>
>    Copyright 2016 Dell Inc.
> -  Copyright (c) 2006 - 2016, Intel Corporation. All rights reserved.<BR>
> +  Copyright (c) 2006 - 2017, Intel Corporation. All rights reserved.<BR>
>    This program and the accompanying materials
>    are licensed and made available under the terms and conditions of the BSD
> License
>    which accompanies this distribution.  The full text of the license may be
> found at
> @@ -3755,7 +3755,7 @@ InternalShellHexCharToUintn (
>      return Char - L'0';
>    }
> 
> -  return (UINTN) (10 + InternalShellCharToUpper (Char) - L'A');
> +  return (10 + InternalShellCharToUpper (Char) - L'A');
>  }
> 
>  /**
> --
> 1.9.5.msysgit.0



^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH v3 02/12] MdeModulePkg: Refine casting expression result to bigger size
  2017-02-25  5:12 ` [PATCH v3 02/12] MdeModulePkg: " Hao Wu
@ 2017-03-06  1:37   ` Tian, Feng
  0 siblings, 0 replies; 25+ messages in thread
From: Tian, Feng @ 2017-03-06  1:37 UTC (permalink / raw)
  To: Wu, Hao A, edk2-devel@lists.01.org; +Cc: Zeng, Star, Tian, Feng

Reviewed-by: Feng Tian <feng.tian@intel.com>

Thanks
Feng

-----Original Message-----
From: Wu, Hao A 
Sent: Saturday, February 25, 2017 1:12 PM
To: edk2-devel@lists.01.org
Cc: Wu, Hao A <hao.a.wu@intel.com>; Tian, Feng <feng.tian@intel.com>; Zeng, Star <star.zeng@intel.com>
Subject: [PATCH v3 02/12] MdeModulePkg: Refine casting expression result to bigger size

There are cases that the operands of an expression are all with rank less
than UINT64/INT64 and the result of the expression is explicitly cast to
UINT64/INT64 to fit the target size.

An example will be:
UINT32 a,b;
// a and b can be any unsigned int type with rank less than UINT64, like
// UINT8, UINT16, etc.
UINT64 c;
c = (UINT64) (a + b);

Some static code checkers may warn that the expression result might
overflow within the rank of "int" (integer promotions) and the result is
then cast to a bigger size.

The commit refines codes by the following rules:
1). When the expression is possible to overflow the range of unsigned int/
int:
c = (UINT64)a + b;

2). When the expression will not overflow within the rank of "int", remove
the explicit type casts:
c = a + b;

3). When the expression will be cast to pointer of possible greater size:
UINT32 a,b;
VOID *c;
c = (VOID *)(UINTN)(a + b); --> c = (VOID *)((UINTN)a + b);

4). When one side of a comparison expression contains only operands with
rank less than UINT32:
UINT8 a;
UINT16 b;
UINTN c;
if ((UINTN)(a + b) > c) {...} --> if (((UINT32)a + b) > c) {...}

For rule 4), if we remove the 'UINTN' type cast like:
if (a + b > c) {...}
The VS compiler will complain with warning C4018 (signed/unsigned
mismatch, level 3 warning) due to promoting 'a + b' to type 'int'.

Cc: Feng Tian <feng.tian@intel.com>
Cc: Star Zeng <star.zeng@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Hao Wu <hao.a.wu@intel.com>
---
 MdeModulePkg/Application/UiApp/FrontPage.c                                |  4 ++--
 MdeModulePkg/Bus/Pci/EhciDxe/EhciReg.c                                    |  8 ++++----
 MdeModulePkg/Bus/Pci/IdeBusPei/AtapiPeim.c                                |  4 ++--
 MdeModulePkg/Bus/Pci/PciBusDxe/PciOptionRomSupport.c                      |  2 +-
 MdeModulePkg/Bus/Pci/XhciDxe/XhciReg.c                                    | 20 ++++++++++----------
 MdeModulePkg/Bus/Ufs/UfsBlockIoPei/UfsHci.c                               |  6 +++---
 MdeModulePkg/Bus/Ufs/UfsPassThruDxe/UfsPassThruHci.c                      |  6 +++---
 MdeModulePkg/Core/Dxe/Image/Image.c                                       | 14 ++++++--------
 MdeModulePkg/Core/Dxe/Misc/DebugImageInfo.c                               |  4 ++--
 MdeModulePkg/Core/Pei/Image/Image.c                                       | 12 +++++-------
 MdeModulePkg/Core/PiSmmCore/Dispatcher.c                                  | 18 ++++++++----------
 MdeModulePkg/Core/PiSmmCore/PiSmmIpl.c                                    | 12 +++++-------
 MdeModulePkg/Library/DxeCapsuleLibFmp/DxeCapsuleLib.c                     |  4 ++--
 MdeModulePkg/Library/DxeCoreMemoryAllocationLib/MemoryAllocationLib.c     |  4 ++--
 MdeModulePkg/Library/DxeNetLib/DxeNetLib.c                                |  4 ++--
 MdeModulePkg/Library/PiDxeS3BootScriptLib/BootScriptSave.c                |  4 ++--
 MdeModulePkg/Library/PiSmmCoreMemoryAllocationLib/MemoryAllocationLib.c   |  4 ++--
 MdeModulePkg/Library/SmmMemoryAllocationProfileLib/MemoryAllocationLib.c  |  4 ++--
 MdeModulePkg/Library/UefiBootManagerLib/BmMisc.c                          |  4 ++--
 MdeModulePkg/Library/UefiHiiLib/HiiLib.c                                  |  4 ++--
 MdeModulePkg/Library/UefiMemoryAllocationProfileLib/MemoryAllocationLib.c |  4 ++--
 MdeModulePkg/Library/VarCheckHiiLib/VarCheckHiiLibNullClass.c             |  6 +++---
 MdeModulePkg/Universal/Acpi/BootScriptExecutorDxe/ScriptExecute.c         |  4 ++--
 MdeModulePkg/Universal/Acpi/S3SaveStateDxe/AcpiS3ContextSave.c            |  6 +++---
 MdeModulePkg/Universal/CapsulePei/Common/CapsuleCoalesce.c                |  4 ++--
 MdeModulePkg/Universal/DisplayEngineDxe/FormDisplay.c                     |  8 ++++----
 MdeModulePkg/Universal/EbcDxe/EbcExecute.c                                | 10 +++++-----
 MdeModulePkg/Universal/FaultTolerantWriteDxe/UpdateWorkingBlock.c         |  4 ++--
 MdeModulePkg/Universal/HiiDatabaseDxe/Font.c                              | 20 ++++++++++----------
 MdeModulePkg/Universal/Network/UefiPxeBcDxe/PxeBcImpl.c                   |  6 +++---
 MdeModulePkg/Universal/PCD/Dxe/Service.c                                  |  4 ++--
 MdeModulePkg/Universal/PCD/Pei/Service.c                                  |  4 ++--
 MdeModulePkg/Universal/SmbiosDxe/SmbiosDxe.c                              |  6 +++---
 MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.c                     |  6 +++---
 34 files changed, 113 insertions(+), 121 deletions(-)

diff --git a/MdeModulePkg/Application/UiApp/FrontPage.c b/MdeModulePkg/Application/UiApp/FrontPage.c
index bda5ff9..c2393eb 100644
--- a/MdeModulePkg/Application/UiApp/FrontPage.c
+++ b/MdeModulePkg/Application/UiApp/FrontPage.c
@@ -1,7 +1,7 @@
 /** @file
   FrontPage routines to handle the callbacks and browser calls
 
-Copyright (c) 2004 - 2016, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2004 - 2017, Intel Corporation. All rights reserved.<BR>
 This program and the accompanying materials
 are licensed and made available under the terms and conditions of the BSD License
 which accompanies this distribution.  The full text of the license may be found at
@@ -399,7 +399,7 @@ ConvertProcessorToString (
 
   if (Base10Exponent >= 6) {
     FreqMhz = ProcessorFrequency;
-    for (Index = 0; Index < (UINTN) (Base10Exponent - 6); Index++) {
+    for (Index = 0; Index < (UINT32) Base10Exponent - 6; Index++) {
       FreqMhz *= 10;
     }
   } else {
diff --git a/MdeModulePkg/Bus/Pci/EhciDxe/EhciReg.c b/MdeModulePkg/Bus/Pci/EhciDxe/EhciReg.c
index 3a6ed02..34836ec 100644
--- a/MdeModulePkg/Bus/Pci/EhciDxe/EhciReg.c
+++ b/MdeModulePkg/Bus/Pci/EhciDxe/EhciReg.c
@@ -2,7 +2,7 @@
 
   The EHCI register operation routines.
 
-Copyright (c) 2007 - 2012, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2007 - 2017, Intel Corporation. All rights reserved.<BR>
 This program and the accompanying materials
 are licensed and made available under the terms and conditions of the BSD License
 which accompanies this distribution.  The full text of the license may be found at
@@ -76,7 +76,7 @@ EhcReadDbgRegister (
                              Ehc->PciIo,
                              EfiPciIoWidthUint32,
                              Ehc->DebugPortBarNum,
-                             (UINT64) (Ehc->DebugPortOffset + Offset),
+                             Ehc->DebugPortOffset + Offset,
                              1,
                              &Data
                              );
@@ -115,7 +115,7 @@ EhcReadOpReg (
                              Ehc->PciIo,
                              EfiPciIoWidthUint32,
                              EHC_BAR_INDEX,
-                             (UINT64) (Ehc->CapLen + Offset),
+                             Ehc->CapLen + Offset,
                              1,
                              &Data
                              );
@@ -152,7 +152,7 @@ EhcWriteOpReg (
                              Ehc->PciIo,
                              EfiPciIoWidthUint32,
                              EHC_BAR_INDEX,
-                             (UINT64) (Ehc->CapLen + Offset),
+                             Ehc->CapLen + Offset,
                              1,
                              &Data
                              );
diff --git a/MdeModulePkg/Bus/Pci/IdeBusPei/AtapiPeim.c b/MdeModulePkg/Bus/Pci/IdeBusPei/AtapiPeim.c
index be1b829..b1ab34d 100644
--- a/MdeModulePkg/Bus/Pci/IdeBusPei/AtapiPeim.c
+++ b/MdeModulePkg/Bus/Pci/IdeBusPei/AtapiPeim.c
@@ -5,7 +5,7 @@ ATA controllers in the platform.
 This PPI can be consumed by PEIM which produce gEfiPeiDeviceRecoveryModulePpiGuid
 for Atapi CD ROM device.
 
-Copyright (c) 2006 - 2015, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2006 - 2017, Intel Corporation. All rights reserved.<BR>
 
 This program and the accompanying materials
 are licensed and made available under the terms and conditions
@@ -593,7 +593,7 @@ AtapiEnumerateDevices (
       //
       // Pata & Sata, Primary & Secondary channel, Master & Slave device
       //
-      DevicePosition = (UINTN) (Index1 * 2 + Index2);
+      DevicePosition = Index1 * 2 + Index2;
 
       if (DiscoverAtapiDevice (AtapiBlkIoDev, DevicePosition, &MediaInfo, &MediaInfo2)) {
         //
diff --git a/MdeModulePkg/Bus/Pci/PciBusDxe/PciOptionRomSupport.c b/MdeModulePkg/Bus/Pci/PciBusDxe/PciOptionRomSupport.c
index d2ad94e..3713c07 100644
--- a/MdeModulePkg/Bus/Pci/PciBusDxe/PciOptionRomSupport.c
+++ b/MdeModulePkg/Bus/Pci/PciBusDxe/PciOptionRomSupport.c
@@ -305,7 +305,7 @@ GetOpRomInfo (
     return EFI_NOT_FOUND;
   }
 
-  PciIoDevice->RomSize = (UINT64) ((~AllOnes) + 1);
+  PciIoDevice->RomSize = (~AllOnes) + 1;
   return EFI_SUCCESS;
 }
 
diff --git a/MdeModulePkg/Bus/Pci/XhciDxe/XhciReg.c b/MdeModulePkg/Bus/Pci/XhciDxe/XhciReg.c
index 0e1c86c..4d5937d 100644
--- a/MdeModulePkg/Bus/Pci/XhciDxe/XhciReg.c
+++ b/MdeModulePkg/Bus/Pci/XhciDxe/XhciReg.c
@@ -2,7 +2,7 @@
 
   The XHCI register operation routines.
 
-Copyright (c) 2011 - 2016, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2011 - 2017, Intel Corporation. All rights reserved.<BR>
 This program and the accompanying materials
 are licensed and made available under the terms and conditions of the BSD License
 which accompanies this distribution.  The full text of the license may be found at
@@ -112,7 +112,7 @@ XhcReadOpReg (
                              Xhc->PciIo,
                              EfiPciIoWidthUint32,
                              XHC_BAR_INDEX,
-                             (UINT64) (Xhc->CapLength + Offset),
+                             Xhc->CapLength + Offset,
                              1,
                              &Data
                              );
@@ -148,7 +148,7 @@ XhcWriteOpReg (
                              Xhc->PciIo,
                              EfiPciIoWidthUint32,
                              XHC_BAR_INDEX,
-                             (UINT64) (Xhc->CapLength + Offset),
+                             Xhc->CapLength + Offset,
                              1,
                              &Data
                              );
@@ -181,7 +181,7 @@ XhcWriteOpReg16 (
                              Xhc->PciIo,
                              EfiPciIoWidthUint16,
                              XHC_BAR_INDEX,
-                             (UINT64) (Xhc->CapLength + Offset),
+                             Xhc->CapLength + Offset,
                              1,
                              &Data
                              );
@@ -215,7 +215,7 @@ XhcReadDoorBellReg (
                              Xhc->PciIo,
                              EfiPciIoWidthUint32,
                              XHC_BAR_INDEX,
-                             (UINT64) (Xhc->DBOff + Offset),
+                             Xhc->DBOff + Offset,
                              1,
                              &Data
                              );
@@ -251,7 +251,7 @@ XhcWriteDoorBellReg (
                              Xhc->PciIo,
                              EfiPciIoWidthUint32,
                              XHC_BAR_INDEX,
-                             (UINT64) (Xhc->DBOff + Offset),
+                             Xhc->DBOff + Offset,
                              1,
                              &Data
                              );
@@ -285,7 +285,7 @@ XhcReadRuntimeReg (
                              Xhc->PciIo,
                              EfiPciIoWidthUint32,
                              XHC_BAR_INDEX,
-                             (UINT64) (Xhc->RTSOff + Offset),
+                             Xhc->RTSOff + Offset,
                              1,
                              &Data
                              );
@@ -321,7 +321,7 @@ XhcWriteRuntimeReg (
                              Xhc->PciIo,
                              EfiPciIoWidthUint32,
                              XHC_BAR_INDEX,
-                             (UINT64) (Xhc->RTSOff + Offset),
+                             Xhc->RTSOff + Offset,
                              1,
                              &Data
                              );
@@ -355,7 +355,7 @@ XhcReadExtCapReg (
                              Xhc->PciIo,
                              EfiPciIoWidthUint32,
                              XHC_BAR_INDEX,
-                             (UINT64) (Xhc->ExtCapRegBase + Offset),
+                             Xhc->ExtCapRegBase + Offset,
                              1,
                              &Data
                              );
@@ -391,7 +391,7 @@ XhcWriteExtCapReg (
                              Xhc->PciIo,
                              EfiPciIoWidthUint32,
                              XHC_BAR_INDEX,
-                             (UINT64) (Xhc->ExtCapRegBase + Offset),
+                             Xhc->ExtCapRegBase + Offset,
                              1,
                              &Data
                              );
diff --git a/MdeModulePkg/Bus/Ufs/UfsBlockIoPei/UfsHci.c b/MdeModulePkg/Bus/Ufs/UfsBlockIoPei/UfsHci.c
index 332ce7e..1ef6c88 100644
--- a/MdeModulePkg/Bus/Ufs/UfsBlockIoPei/UfsHci.c
+++ b/MdeModulePkg/Bus/Ufs/UfsBlockIoPei/UfsHci.c
@@ -1,6 +1,6 @@
 /** @file
 
-  Copyright (c) 2014 - 2016, Intel Corporation. All rights reserved.<BR>
+  Copyright (c) 2014 - 2017, Intel Corporation. All rights reserved.<BR>
   This program and the accompanying materials
   are licensed and made available under the terms and conditions of the BSD License
   which accompanies this distribution.  The full text of the license may be found at
@@ -589,9 +589,9 @@ UfsCreateDMCommandDesc (
   Trd->UcdBaU = (UINT32)RShiftU64 ((UINT64)(UINTN)QueryReqUpiu, 32);
   if (Opcode == UtpQueryFuncOpcodeWrDesc) {
     Trd->RuL  = (UINT16)DivU64x32 ((UINT64)ROUNDUP8 (sizeof (UTP_QUERY_RESP_UPIU)), sizeof (UINT32));
-    Trd->RuO  = (UINT16)DivU64x32 ((UINT64)(ROUNDUP8 (sizeof (UTP_QUERY_REQ_UPIU)) + ROUNDUP8 (DataSize)), sizeof (UINT32));
+    Trd->RuO  = (UINT16)DivU64x32 ((UINT64)ROUNDUP8 (sizeof (UTP_QUERY_REQ_UPIU)) + ROUNDUP8 (DataSize), sizeof (UINT32));
   } else {
-    Trd->RuL  = (UINT16)DivU64x32 ((UINT64)(ROUNDUP8 (sizeof (UTP_QUERY_RESP_UPIU)) + ROUNDUP8 (DataSize)), sizeof (UINT32));
+    Trd->RuL  = (UINT16)DivU64x32 ((UINT64)ROUNDUP8 (sizeof (UTP_QUERY_RESP_UPIU)) + ROUNDUP8 (DataSize), sizeof (UINT32));
     Trd->RuO  = (UINT16)DivU64x32 ((UINT64)ROUNDUP8 (sizeof (UTP_QUERY_REQ_UPIU)), sizeof (UINT32));
   }
 
diff --git a/MdeModulePkg/Bus/Ufs/UfsPassThruDxe/UfsPassThruHci.c b/MdeModulePkg/Bus/Ufs/UfsPassThruDxe/UfsPassThruHci.c
index bc39cf8..3dd8cbf 100644
--- a/MdeModulePkg/Bus/Ufs/UfsPassThruDxe/UfsPassThruHci.c
+++ b/MdeModulePkg/Bus/Ufs/UfsPassThruDxe/UfsPassThruHci.c
@@ -2,7 +2,7 @@
   UfsPassThruDxe driver is used to produce EFI_EXT_SCSI_PASS_THRU protocol interface
   for upper layer application to execute UFS-supported SCSI cmds.
 
-  Copyright (c) 2014 - 2016, Intel Corporation. All rights reserved.<BR>
+  Copyright (c) 2014 - 2017, Intel Corporation. All rights reserved.<BR>
   This program and the accompanying materials
   are licensed and made available under the terms and conditions of the BSD License
   which accompanies this distribution.  The full text of the license may be found at
@@ -666,9 +666,9 @@ UfsCreateDMCommandDesc (
   Trd->UcdBaU = (UINT32)RShiftU64 ((UINT64)CmdDescPhyAddr, 32);
   if (Opcode == UtpQueryFuncOpcodeWrDesc) {
     Trd->RuL  = (UINT16)DivU64x32 ((UINT64)ROUNDUP8 (sizeof (UTP_QUERY_RESP_UPIU)), sizeof (UINT32));
-    Trd->RuO  = (UINT16)DivU64x32 ((UINT64)(ROUNDUP8 (sizeof (UTP_QUERY_REQ_UPIU)) + ROUNDUP8 (DataSize)), sizeof (UINT32));
+    Trd->RuO  = (UINT16)DivU64x32 ((UINT64)ROUNDUP8 (sizeof (UTP_QUERY_REQ_UPIU)) + ROUNDUP8 (DataSize), sizeof (UINT32));
   } else {
-    Trd->RuL  = (UINT16)DivU64x32 ((UINT64)(ROUNDUP8 (sizeof (UTP_QUERY_RESP_UPIU)) + ROUNDUP8 (DataSize)), sizeof (UINT32));
+    Trd->RuL  = (UINT16)DivU64x32 ((UINT64)ROUNDUP8 (sizeof (UTP_QUERY_RESP_UPIU)) + ROUNDUP8 (DataSize), sizeof (UINT32));
     Trd->RuO  = (UINT16)DivU64x32 ((UINT64)ROUNDUP8 (sizeof (UTP_QUERY_REQ_UPIU)), sizeof (UINT32));
   }
 
diff --git a/MdeModulePkg/Core/Dxe/Image/Image.c b/MdeModulePkg/Core/Dxe/Image/Image.c
index 652da8b..80128e7 100644
--- a/MdeModulePkg/Core/Dxe/Image/Image.c
+++ b/MdeModulePkg/Core/Dxe/Image/Image.c
@@ -313,8 +313,8 @@ CheckAndMarkFixLoadingMemoryUsageBitMap (
    //
    // Test if the memory is avalaible or not.
    // 
-   BaseOffsetPageNumber = (UINTN)EFI_SIZE_TO_PAGES((UINT32)(ImageBase - DxeCodeBase));
-   TopOffsetPageNumber  = (UINTN)EFI_SIZE_TO_PAGES((UINT32)(ImageBase + ImageSize - DxeCodeBase));
+   BaseOffsetPageNumber = EFI_SIZE_TO_PAGES((UINT32)(ImageBase - DxeCodeBase));
+   TopOffsetPageNumber  = EFI_SIZE_TO_PAGES((UINT32)(ImageBase + ImageSize - DxeCodeBase));
    for (Index = BaseOffsetPageNumber; Index < TopOffsetPageNumber; Index ++) {
      if ((mDxeCodeMemoryRangeUsageBitMap[Index / 64] & LShiftU64(1, (Index % 64))) != 0) {
        //
@@ -366,12 +366,10 @@ GetPeCoffImageFixLoadingAssignedAddress(
    //
    Handle = (IMAGE_FILE_HANDLE*)ImageContext->Handle;
    ImgHdr = (EFI_IMAGE_OPTIONAL_HEADER_UNION *)((CHAR8* )Handle->Source + ImageContext->PeCoffHeaderOffset);
-   SectionHeaderOffset = (UINTN)(
-                                 ImageContext->PeCoffHeaderOffset +
-                                 sizeof (UINT32) +
-                                 sizeof (EFI_IMAGE_FILE_HEADER) +
-                                 ImgHdr->Pe32.FileHeader.SizeOfOptionalHeader
-                                 );
+   SectionHeaderOffset = ImageContext->PeCoffHeaderOffset +
+                         sizeof (UINT32) +
+                         sizeof (EFI_IMAGE_FILE_HEADER) +
+                         ImgHdr->Pe32.FileHeader.SizeOfOptionalHeader;
    NumberOfSections = ImgHdr->Pe32.FileHeader.NumberOfSections;
 
    //
diff --git a/MdeModulePkg/Core/Dxe/Misc/DebugImageInfo.c b/MdeModulePkg/Core/Dxe/Misc/DebugImageInfo.c
index 4766072..fda6d44 100644
--- a/MdeModulePkg/Core/Dxe/Misc/DebugImageInfo.c
+++ b/MdeModulePkg/Core/Dxe/Misc/DebugImageInfo.c
@@ -2,7 +2,7 @@
   Support functions for managing debug image info table when loading and unloading
   images.
 
-Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2006 - 2017, Intel Corporation. All rights reserved.<BR>
 This program and the accompanying materials
 are licensed and made available under the terms and conditions of the BSD License
 which accompanies this distribution.  The full text of the license may be found at
@@ -103,7 +103,7 @@ CoreInitializeDebugImageInfoTable (
     Status = CoreFreePages (Memory, UnalignedPages);
     ASSERT_EFI_ERROR (Status);
   }
-  Memory         = (EFI_PHYSICAL_ADDRESS)(AlignedMemory + EFI_PAGES_TO_SIZE (Pages));
+  Memory         = AlignedMemory + EFI_PAGES_TO_SIZE (Pages);
   UnalignedPages = RealPages - Pages - UnalignedPages;
   if (UnalignedPages > 0) {
     //
diff --git a/MdeModulePkg/Core/Pei/Image/Image.c b/MdeModulePkg/Core/Pei/Image/Image.c
index d659de8..381a23f 100644
--- a/MdeModulePkg/Core/Pei/Image/Image.c
+++ b/MdeModulePkg/Core/Pei/Image/Image.c
@@ -1,7 +1,7 @@
 /** @file
   Pei Core Load Image Support
 
-Copyright (c) 2006 - 2016, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2006 - 2017, Intel Corporation. All rights reserved.<BR>
 This program and the accompanying materials
 are licensed and made available under the terms and conditions of the BSD License
 which accompanies this distribution.  The full text of the license may be found at
@@ -250,12 +250,10 @@ GetPeCoffImageFixLoadingAssignedAddress(
      SectionHeaderOffset = sizeof (EFI_TE_IMAGE_HEADER);
      NumberOfSections = ImgHdr->Te.NumberOfSections;
    } else {
-     SectionHeaderOffset = (UINTN)(
-                                 ImageContext->PeCoffHeaderOffset +
-                                 sizeof (UINT32) +
-                                 sizeof (EFI_IMAGE_FILE_HEADER) +
-                                 ImgHdr->Pe32.FileHeader.SizeOfOptionalHeader
-                                 );
+     SectionHeaderOffset = ImageContext->PeCoffHeaderOffset +
+                           sizeof (UINT32) +
+                           sizeof (EFI_IMAGE_FILE_HEADER) +
+                           ImgHdr->Pe32.FileHeader.SizeOfOptionalHeader;
       NumberOfSections = ImgHdr->Pe32.FileHeader.NumberOfSections;
    }
    //
diff --git a/MdeModulePkg/Core/PiSmmCore/Dispatcher.c b/MdeModulePkg/Core/PiSmmCore/Dispatcher.c
index 1bddaf1..b2a6822 100644
--- a/MdeModulePkg/Core/PiSmmCore/Dispatcher.c
+++ b/MdeModulePkg/Core/PiSmmCore/Dispatcher.c
@@ -28,7 +28,7 @@
   Depex - Dependency Expresion.
 
   Copyright (c) 2014, Hewlett-Packard Development Company, L.P.
-  Copyright (c) 2009 - 2016, Intel Corporation. All rights reserved.<BR>
+  Copyright (c) 2009 - 2017, Intel Corporation. All rights reserved.<BR>
   This program and the accompanying materials are licensed and made available 
   under the terms and conditions of the BSD License which accompanies this 
   distribution.  The full text of the license may be found at        
@@ -183,8 +183,8 @@ CheckAndMarkFixLoadingMemoryUsageBitMap (
    //
    // Test if the memory is avalaible or not.
    // 
-   BaseOffsetPageNumber = (UINTN)EFI_SIZE_TO_PAGES((UINT32)(ImageBase - SmmCodeBase));
-   TopOffsetPageNumber  = (UINTN)EFI_SIZE_TO_PAGES((UINT32)(ImageBase + ImageSize - SmmCodeBase));
+   BaseOffsetPageNumber = EFI_SIZE_TO_PAGES((UINT32)(ImageBase - SmmCodeBase));
+   TopOffsetPageNumber  = EFI_SIZE_TO_PAGES((UINT32)(ImageBase + ImageSize - SmmCodeBase));
    for (Index = BaseOffsetPageNumber; Index < TopOffsetPageNumber; Index ++) {
      if ((mSmmCodeMemoryRangeUsageBitMap[Index / 64] & LShiftU64(1, (Index % 64))) != 0) {
        //
@@ -234,12 +234,10 @@ GetPeCoffImageFixLoadingAssignedAddress(
   // Get PeHeader pointer
   //
   ImgHdr = (EFI_IMAGE_OPTIONAL_HEADER_UNION *)((CHAR8* )ImageContext->Handle + ImageContext->PeCoffHeaderOffset);
-  SectionHeaderOffset = (UINTN)(
-                                 ImageContext->PeCoffHeaderOffset +
-                                 sizeof (UINT32) +
-                                 sizeof (EFI_IMAGE_FILE_HEADER) +
-                                 ImgHdr->Pe32.FileHeader.SizeOfOptionalHeader
-                                 );
+  SectionHeaderOffset = ImageContext->PeCoffHeaderOffset +
+                        sizeof (UINT32) +
+                        sizeof (EFI_IMAGE_FILE_HEADER) +
+                        ImgHdr->Pe32.FileHeader.SizeOfOptionalHeader;
   NumberOfSections = ImgHdr->Pe32.FileHeader.NumberOfSections;
 
   //
@@ -520,7 +518,7 @@ SmmLoadImage (
   // Align buffer on section boundary
   //
   ImageContext.ImageAddress += ImageContext.SectionAlignment - 1;
-  ImageContext.ImageAddress &= ~((EFI_PHYSICAL_ADDRESS)(ImageContext.SectionAlignment - 1));
+  ImageContext.ImageAddress &= ~((EFI_PHYSICAL_ADDRESS)ImageContext.SectionAlignment - 1);
 
   //
   // Load the image to our new buffer
diff --git a/MdeModulePkg/Core/PiSmmCore/PiSmmIpl.c b/MdeModulePkg/Core/PiSmmCore/PiSmmIpl.c
index 26b71f1..feb846e 100644
--- a/MdeModulePkg/Core/PiSmmCore/PiSmmIpl.c
+++ b/MdeModulePkg/Core/PiSmmCore/PiSmmIpl.c
@@ -846,12 +846,10 @@ GetPeCoffImageFixLoadingAssignedAddress(
    // Get PeHeader pointer
    //
    ImgHdr = (EFI_IMAGE_OPTIONAL_HEADER_UNION *)((CHAR8* )ImageContext->Handle + ImageContext->PeCoffHeaderOffset);
-   SectionHeaderOffset = (UINTN)(
-                                 ImageContext->PeCoffHeaderOffset +
-                                 sizeof (UINT32) +
-                                 sizeof (EFI_IMAGE_FILE_HEADER) +
-                                 ImgHdr->Pe32.FileHeader.SizeOfOptionalHeader
-                                 );
+   SectionHeaderOffset = ImageContext->PeCoffHeaderOffset +
+                         sizeof (UINT32) +
+                         sizeof (EFI_IMAGE_FILE_HEADER) +
+                         ImgHdr->Pe32.FileHeader.SizeOfOptionalHeader;
    NumberOfSections = ImgHdr->Pe32.FileHeader.NumberOfSections;
 
    //
@@ -1022,7 +1020,7 @@ ExecuteSmmCoreFromSmram (
   }
   
   ImageContext.ImageAddress += ImageContext.SectionAlignment - 1;
-  ImageContext.ImageAddress &= ~((EFI_PHYSICAL_ADDRESS)(ImageContext.SectionAlignment - 1));
+  ImageContext.ImageAddress &= ~((EFI_PHYSICAL_ADDRESS)ImageContext.SectionAlignment - 1);
 
   //
   // Print debug message showing SMM Core load address.
diff --git a/MdeModulePkg/Library/DxeCapsuleLibFmp/DxeCapsuleLib.c b/MdeModulePkg/Library/DxeCapsuleLibFmp/DxeCapsuleLib.c
index d7abcc8..7f500a9 100644
--- a/MdeModulePkg/Library/DxeCapsuleLibFmp/DxeCapsuleLib.c
+++ b/MdeModulePkg/Library/DxeCapsuleLibFmp/DxeCapsuleLib.c
@@ -585,7 +585,7 @@ DisplayCapsuleImage (
   EFI_GRAPHICS_OUTPUT_PROTOCOL  *GraphicsOutput;
 
   ImagePayload = (DISPLAY_DISPLAY_PAYLOAD *)(CapsuleHeader + 1);
-  PayloadSize = (UINTN)(CapsuleHeader->CapsuleImageSize - sizeof(EFI_CAPSULE_HEADER));
+  PayloadSize = CapsuleHeader->CapsuleImageSize - sizeof(EFI_CAPSULE_HEADER);
 
   if (ImagePayload->Version != 1) {
     return EFI_UNSUPPORTED;
@@ -733,7 +733,7 @@ DumpFmpCapsule (
   for (Index = 0; Index < FmpCapsuleHeader->EmbeddedDriverCount; Index++) {
     DEBUG((DEBUG_VERBOSE, "  ItemOffsetList[%d]      - 0x%lx\n", Index, ItemOffsetList[Index]));
   }
-  for (; Index < (UINTN)(FmpCapsuleHeader->EmbeddedDriverCount + FmpCapsuleHeader->PayloadItemCount); Index++) {
+  for (; Index < (UINT32)FmpCapsuleHeader->EmbeddedDriverCount + FmpCapsuleHeader->PayloadItemCount; Index++) {
     DEBUG((DEBUG_VERBOSE, "  ItemOffsetList[%d]      - 0x%lx\n", Index, ItemOffsetList[Index]));
     ImageHeader = (EFI_FIRMWARE_MANAGEMENT_CAPSULE_IMAGE_HEADER *)((UINT8 *)FmpCapsuleHeader + ItemOffsetList[Index]);
 
diff --git a/MdeModulePkg/Library/DxeCoreMemoryAllocationLib/MemoryAllocationLib.c b/MdeModulePkg/Library/DxeCoreMemoryAllocationLib/MemoryAllocationLib.c
index 89c19e7..95725c8 100644
--- a/MdeModulePkg/Library/DxeCoreMemoryAllocationLib/MemoryAllocationLib.c
+++ b/MdeModulePkg/Library/DxeCoreMemoryAllocationLib/MemoryAllocationLib.c
@@ -3,7 +3,7 @@
   on DxeCore Memory Allocation services for DxeCore,
   with memory profile support.
 
-  Copyright (c) 2006 - 2016, Intel Corporation. All rights reserved.<BR>
+  Copyright (c) 2006 - 2017, Intel Corporation. All rights reserved.<BR>
   This program and the accompanying materials                          
   are licensed and made available under the terms and conditions of the BSD License         
   which accompanies this distribution.  The full text of the license may be found at        
@@ -258,7 +258,7 @@ InternalAllocateAlignedPages (
       Status = CoreFreePages (Memory, UnalignedPages);
       ASSERT_EFI_ERROR (Status);
     }
-    Memory         = (EFI_PHYSICAL_ADDRESS) (AlignedMemory + EFI_PAGES_TO_SIZE (Pages));
+    Memory         = AlignedMemory + EFI_PAGES_TO_SIZE (Pages);
     UnalignedPages = RealPages - Pages - UnalignedPages;
     if (UnalignedPages > 0) {
       //
diff --git a/MdeModulePkg/Library/DxeNetLib/DxeNetLib.c b/MdeModulePkg/Library/DxeNetLib/DxeNetLib.c
index 0a7117c..c015aa6 100644
--- a/MdeModulePkg/Library/DxeNetLib/DxeNetLib.c
+++ b/MdeModulePkg/Library/DxeNetLib/DxeNetLib.c
@@ -1,7 +1,7 @@
 /** @file
   Network library.
 
-Copyright (c) 2005 - 2016, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2005 - 2017, Intel Corporation. All rights reserved.<BR>
 (C) Copyright 2015 Hewlett Packard Enterprise Development LP<BR>
 This program and the accompanying materials
 are licensed and made available under the terms and conditions of the BSD License
@@ -3299,7 +3299,7 @@ NetLibGetSystemGuid (
       return EFI_NOT_FOUND;
     }
     Smbios.Hdr    = (SMBIOS_STRUCTURE *) (UINTN) SmbiosTable->TableAddress;
-    SmbiosEnd.Raw = (UINT8 *) (UINTN) (SmbiosTable->TableAddress + SmbiosTable->TableLength);
+    SmbiosEnd.Raw = (UINT8 *) ((UINTN) SmbiosTable->TableAddress + SmbiosTable->TableLength);
   }
 
   do {
diff --git a/MdeModulePkg/Library/PiDxeS3BootScriptLib/BootScriptSave.c b/MdeModulePkg/Library/PiDxeS3BootScriptLib/BootScriptSave.c
index 1f8aaf4..fe2d3a0 100644
--- a/MdeModulePkg/Library/PiDxeS3BootScriptLib/BootScriptSave.c
+++ b/MdeModulePkg/Library/PiDxeS3BootScriptLib/BootScriptSave.c
@@ -691,7 +691,7 @@ S3BootScriptGetBootTimeEntryAddAddress (
    // Here we do not count the reserved memory for runtime script table.
    PageNumber = (UINT16) (mS3BootScriptTablePtr->TableMemoryPageNumber - PcdGet16(PcdS3BootScriptRuntimeTableReservePageNumber));
    TableLength =  mS3BootScriptTablePtr->TableLength;
-   if ((UINTN) EFI_PAGES_TO_SIZE ((UINTN) PageNumber) < (UINTN) (TableLength + EntryLength + sizeof (EFI_BOOT_SCRIPT_TERMINATE))) {
+   if (EFI_PAGES_TO_SIZE ((UINTN) PageNumber) < (TableLength + EntryLength + sizeof (EFI_BOOT_SCRIPT_TERMINATE))) {
      //
      // The buffer is too small to hold the table, Reallocate the buffer
      //
@@ -752,7 +752,7 @@ S3BootScriptGetRuntimeEntryAddAddress (
    //
    // Check if the memory range reserved for S3 Boot Script table is large enough to hold the node.
    //
-   if ((UINTN) (mS3BootScriptTablePtr->TableLength + EntryLength + sizeof (EFI_BOOT_SCRIPT_TERMINATE)) <= (UINTN) EFI_PAGES_TO_SIZE ((UINTN) (mS3BootScriptTablePtr->TableMemoryPageNumber))) {
+   if ((mS3BootScriptTablePtr->TableLength + EntryLength + sizeof (EFI_BOOT_SCRIPT_TERMINATE)) <= EFI_PAGES_TO_SIZE ((UINTN) (mS3BootScriptTablePtr->TableMemoryPageNumber))) {
      NewEntryPtr = mS3BootScriptTablePtr->TableBase + mS3BootScriptTablePtr->TableLength;
      mS3BootScriptTablePtr->TableLength = mS3BootScriptTablePtr->TableLength + EntryLength;
      //
diff --git a/MdeModulePkg/Library/PiSmmCoreMemoryAllocationLib/MemoryAllocationLib.c b/MdeModulePkg/Library/PiSmmCoreMemoryAllocationLib/MemoryAllocationLib.c
index bd21468..96cb275 100644
--- a/MdeModulePkg/Library/PiSmmCoreMemoryAllocationLib/MemoryAllocationLib.c
+++ b/MdeModulePkg/Library/PiSmmCoreMemoryAllocationLib/MemoryAllocationLib.c
@@ -11,7 +11,7 @@
   In addition, allocation for the Reserved memory types are not supported and will 
   always return NULL.
 
-  Copyright (c) 2006 - 2016, Intel Corporation. All rights reserved.<BR>
+  Copyright (c) 2006 - 2017, Intel Corporation. All rights reserved.<BR>
   This program and the accompanying materials                          
   are licensed and made available under the terms and conditions of the BSD License         
   which accompanies this distribution.  The full text of the license may be found at        
@@ -293,7 +293,7 @@ InternalAllocateAlignedPages (
       Status = SmmFreePages (Memory, UnalignedPages);
       ASSERT_EFI_ERROR (Status);
     }
-    Memory         = (EFI_PHYSICAL_ADDRESS) (AlignedMemory + EFI_PAGES_TO_SIZE (Pages));
+    Memory         = AlignedMemory + EFI_PAGES_TO_SIZE (Pages);
     UnalignedPages = RealPages - Pages - UnalignedPages;
     if (UnalignedPages > 0) {
       //
diff --git a/MdeModulePkg/Library/SmmMemoryAllocationProfileLib/MemoryAllocationLib.c b/MdeModulePkg/Library/SmmMemoryAllocationProfileLib/MemoryAllocationLib.c
index e9bbf02..2a18155 100644
--- a/MdeModulePkg/Library/SmmMemoryAllocationProfileLib/MemoryAllocationLib.c
+++ b/MdeModulePkg/Library/SmmMemoryAllocationProfileLib/MemoryAllocationLib.c
@@ -12,7 +12,7 @@
   allocation for the Reserved memory types are not supported and will always 
   return NULL.
 
-  Copyright (c) 2006 - 2016, Intel Corporation. All rights reserved.<BR>
+  Copyright (c) 2006 - 2017, Intel Corporation. All rights reserved.<BR>
   This program and the accompanying materials                          
   are licensed and made available under the terms and conditions of the BSD License         
   which accompanies this distribution.  The full text of the license may be found at        
@@ -371,7 +371,7 @@ InternalAllocateAlignedPages (
       Status = gSmst->SmmFreePages (Memory, UnalignedPages);
       ASSERT_EFI_ERROR (Status);
     }
-    Memory         = (EFI_PHYSICAL_ADDRESS) (AlignedMemory + EFI_PAGES_TO_SIZE (Pages));
+    Memory         = AlignedMemory + EFI_PAGES_TO_SIZE (Pages);
     UnalignedPages = RealPages - Pages - UnalignedPages;
     if (UnalignedPages > 0) {
       //
diff --git a/MdeModulePkg/Library/UefiBootManagerLib/BmMisc.c b/MdeModulePkg/Library/UefiBootManagerLib/BmMisc.c
index e11d842..11ab867 100644
--- a/MdeModulePkg/Library/UefiBootManagerLib/BmMisc.c
+++ b/MdeModulePkg/Library/UefiBootManagerLib/BmMisc.c
@@ -413,11 +413,11 @@ BmCharToUint (
   )
 {
   if ((Char >= L'0') && (Char <= L'9')) {
-    return (UINTN) (Char - L'0');
+    return (Char - L'0');
   }
 
   if ((Char >= L'A') && (Char <= L'F')) {
-    return (UINTN) (Char - L'A' + 0xA);
+    return (Char - L'A' + 0xA);
   }
 
   ASSERT (FALSE);
diff --git a/MdeModulePkg/Library/UefiHiiLib/HiiLib.c b/MdeModulePkg/Library/UefiHiiLib/HiiLib.c
index 8579501..0b5b0a9 100644
--- a/MdeModulePkg/Library/UefiHiiLib/HiiLib.c
+++ b/MdeModulePkg/Library/UefiHiiLib/HiiLib.c
@@ -1,7 +1,7 @@
 /** @file
   HII Library implementation that uses DXE protocols and services.
 
-  Copyright (c) 2006 - 2016, Intel Corporation. All rights reserved.<BR>
+  Copyright (c) 2006 - 2017, Intel Corporation. All rights reserved.<BR>
   This program and the accompanying materials
   are licensed and made available under the terms and conditions of the BSD License
   which accompanies this distribution.  The full text of the license may be found at
@@ -1853,7 +1853,7 @@ GetBlockDataInfo (
     //
     // Check whether VarBuffer is enough
     //
-    if ((UINTN) (Offset + Width) > MaxBufferSize) {
+    if ((UINT32)Offset + Width > MaxBufferSize) {
       DataBuffer = ReallocatePool (
                     MaxBufferSize,
                     Offset + Width + HII_LIB_DEFAULT_VARSTORE_SIZE,
diff --git a/MdeModulePkg/Library/UefiMemoryAllocationProfileLib/MemoryAllocationLib.c b/MdeModulePkg/Library/UefiMemoryAllocationProfileLib/MemoryAllocationLib.c
index 370827d..cef7fc0 100644
--- a/MdeModulePkg/Library/UefiMemoryAllocationProfileLib/MemoryAllocationLib.c
+++ b/MdeModulePkg/Library/UefiMemoryAllocationProfileLib/MemoryAllocationLib.c
@@ -2,7 +2,7 @@
   Support routines for memory allocation routines based 
   on boot services for Dxe phase drivers, with memory profile support.
 
-  Copyright (c) 2006 - 2016, Intel Corporation. All rights reserved.<BR>
+  Copyright (c) 2006 - 2017, Intel Corporation. All rights reserved.<BR>
   This program and the accompanying materials                          
   are licensed and made available under the terms and conditions of the BSD License         
   which accompanies this distribution.  The full text of the license may be found at        
@@ -257,7 +257,7 @@ InternalAllocateAlignedPages (
       Status = gBS->FreePages (Memory, UnalignedPages);
       ASSERT_EFI_ERROR (Status);
     }
-    Memory         = (EFI_PHYSICAL_ADDRESS) (AlignedMemory + EFI_PAGES_TO_SIZE (Pages));
+    Memory         = AlignedMemory + EFI_PAGES_TO_SIZE (Pages);
     UnalignedPages = RealPages - Pages - UnalignedPages;
     if (UnalignedPages > 0) {
       //
diff --git a/MdeModulePkg/Library/VarCheckHiiLib/VarCheckHiiLibNullClass.c b/MdeModulePkg/Library/VarCheckHiiLib/VarCheckHiiLibNullClass.c
index b9ca908..93ff934 100644
--- a/MdeModulePkg/Library/VarCheckHiiLib/VarCheckHiiLibNullClass.c
+++ b/MdeModulePkg/Library/VarCheckHiiLib/VarCheckHiiLibNullClass.c
@@ -1,7 +1,7 @@
 /** @file
   Var Check Hii handler.
 
-Copyright (c) 2015, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2015 - 2017, Intel Corporation. All rights reserved.<BR>
 This program and the accompanying materials
 are licensed and made available under the terms and conditions of the BSD License
 which accompanies this distribution.  The full text of the license may be found at
@@ -94,7 +94,7 @@ VarCheckHiiQuestion (
   UINT8    Index;
   UINT8    MaxContainers;
 
-  if ((UINTN) (HiiQuestion->VarOffset + HiiQuestion->StorageWidth) > DataSize) {
+  if (((UINT32) HiiQuestion->VarOffset + HiiQuestion->StorageWidth) > DataSize) {
     DEBUG ((EFI_D_INFO, "VarCheckHiiQuestion fail: (VarOffset(0x%04x) + StorageWidth(0x%02x)) > Size(0x%x)\n", HiiQuestion->VarOffset, HiiQuestion->StorageWidth, DataSize));
     return FALSE;
   }
@@ -155,7 +155,7 @@ VarCheckHiiQuestion (
 
     case EFI_IFR_ORDERED_LIST_OP:
       MaxContainers = ((VAR_CHECK_HII_QUESTION_ORDEREDLIST *) HiiQuestion)->MaxContainers;
-      if ((UINTN) (HiiQuestion->VarOffset + HiiQuestion->StorageWidth * MaxContainers) > DataSize) {
+      if (((UINT32) HiiQuestion->VarOffset + HiiQuestion->StorageWidth * MaxContainers) > DataSize) {
         DEBUG ((EFI_D_INFO, "VarCheckHiiQuestion fail: (VarOffset(0x%04x) + StorageWidth(0x%02x) * MaxContainers(0x%02x)) > Size(0x%x)\n", HiiQuestion->VarOffset, HiiQuestion->StorageWidth, MaxContainers, DataSize));
         return FALSE;
       }
diff --git a/MdeModulePkg/Universal/Acpi/BootScriptExecutorDxe/ScriptExecute.c b/MdeModulePkg/Universal/Acpi/BootScriptExecutorDxe/ScriptExecute.c
index f67fbca..16551ae 100644
--- a/MdeModulePkg/Universal/Acpi/BootScriptExecutorDxe/ScriptExecute.c
+++ b/MdeModulePkg/Universal/Acpi/BootScriptExecutorDxe/ScriptExecute.c
@@ -4,7 +4,7 @@
   This driver is dispatched by Dxe core and the driver will reload itself to ACPI reserved memory
   in the entry point. The functionality is to interpret and restore the S3 boot script
 
-Copyright (c) 2006 - 2016, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2006 - 2017, Intel Corporation. All rights reserved.<BR>
 
 This program and the accompanying materials
 are licensed and made available under the terms and conditions of the BSD License
@@ -325,7 +325,7 @@ ReadyToLockEventNotify (
   // Align buffer on section boundary
   //
   ImageContext.ImageAddress += ImageContext.SectionAlignment - 1;
-  ImageContext.ImageAddress &= ~((EFI_PHYSICAL_ADDRESS)(ImageContext.SectionAlignment - 1));
+  ImageContext.ImageAddress &= ~((EFI_PHYSICAL_ADDRESS)ImageContext.SectionAlignment - 1);
   //
   // Load the image to our new buffer
   //
diff --git a/MdeModulePkg/Universal/Acpi/S3SaveStateDxe/AcpiS3ContextSave.c b/MdeModulePkg/Universal/Acpi/S3SaveStateDxe/AcpiS3ContextSave.c
index a973d2d..dcfd61c 100644
--- a/MdeModulePkg/Universal/Acpi/S3SaveStateDxe/AcpiS3ContextSave.c
+++ b/MdeModulePkg/Universal/Acpi/S3SaveStateDxe/AcpiS3ContextSave.c
@@ -1,7 +1,7 @@
 /** @file
   This is the implementation to save ACPI S3 Context.
 
-Copyright (c) 2006 - 2016, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2006 - 2017, Intel Corporation. All rights reserved.<BR>
 
 This program and the accompanying materials
 are licensed and made available under the terms and conditions
@@ -401,9 +401,9 @@ S3AllocatePageTablesBuffer (
     // We need calculate whole page size then allocate once, because S3 restore page table does not know each page in Nvs.
     //
     if (!Page1GSupport) {
-      TotalPageTableSize = (UINTN)(1 + NumberOfPml4EntriesNeeded + NumberOfPml4EntriesNeeded * NumberOfPdpEntriesNeeded);
+      TotalPageTableSize = 1 + NumberOfPml4EntriesNeeded + NumberOfPml4EntriesNeeded * NumberOfPdpEntriesNeeded;
     } else {
-      TotalPageTableSize = (UINTN)(1 + NumberOfPml4EntriesNeeded);
+      TotalPageTableSize = 1 + NumberOfPml4EntriesNeeded;
     }
 
     TotalPageTableSize += ExtraPageTablePages;
diff --git a/MdeModulePkg/Universal/CapsulePei/Common/CapsuleCoalesce.c b/MdeModulePkg/Universal/CapsulePei/Common/CapsuleCoalesce.c
index 9e8315e..3e7054c 100644
--- a/MdeModulePkg/Universal/CapsulePei/Common/CapsuleCoalesce.c
+++ b/MdeModulePkg/Universal/CapsulePei/Common/CapsuleCoalesce.c
@@ -10,7 +10,7 @@
   into memory.
 
 (C) Copyright 2014 Hewlett-Packard Development Company, L.P.<BR>
-Copyright (c) 2011 - 2016, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2011 - 2017, Intel Corporation. All rights reserved.<BR>
 This program and the accompanying materials
 are licensed and made available under the terms and conditions of the BSD License
 which accompanies this distribution.  The full text of the license may be found at
@@ -1247,7 +1247,7 @@ CapsuleDataCoalesce (
         //
         ASSERT (PrivateDataPtr->Signature == EFI_CAPSULE_PEIM_PRIVATE_DATA_SIGNATURE);
         ASSERT ((UINTN)DestPtr >= (UINTN)CapsuleImageBase);
-        PrivateDataPtr->CapsuleOffset[CapsuleIndex++] = (UINT64)((UINTN)DestPtr - (UINTN)CapsuleImageBase);
+        PrivateDataPtr->CapsuleOffset[CapsuleIndex++] = (UINTN)DestPtr - (UINTN)CapsuleImageBase;
       }
 
       //
diff --git a/MdeModulePkg/Universal/DisplayEngineDxe/FormDisplay.c b/MdeModulePkg/Universal/DisplayEngineDxe/FormDisplay.c
index 0eb7ddd..e1ac5a3 100644
--- a/MdeModulePkg/Universal/DisplayEngineDxe/FormDisplay.c
+++ b/MdeModulePkg/Universal/DisplayEngineDxe/FormDisplay.c
@@ -1,7 +1,7 @@
 /** @file
 Entry and initialization module for the browser.
 
-Copyright (c) 2007 - 2016, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2007 - 2017, Intel Corporation. All rights reserved.<BR>
 Copyright (c) 2014, Hewlett-Packard Development Company, L.P.<BR>
 This program and the accompanying materials
 are licensed and made available under the terms and conditions of the BSD License
@@ -540,7 +540,7 @@ GetLineByWidth (
   //
   // Need extra glyph info and '\0' info, so +2.
   //
-  *OutputString = AllocateZeroPool (((UINTN) (StrOffset + 2) * sizeof(CHAR16)));
+  *OutputString = AllocateZeroPool ((StrOffset + 2) * sizeof(CHAR16));
   if (*OutputString == NULL) {
     return 0;
   }
@@ -2972,7 +2972,7 @@ UiDisplayMenu (
         gST->ConOut->SetAttribute (gST->ConOut, GetInfoTextColor ());
         for (Index = 0; Index < HelpHeaderLine; Index++) {
           ASSERT (HelpHeaderLine == 1);
-          ASSERT (GetStringWidth (HelpHeaderString) / 2 < (UINTN) (gHelpBlockWidth - 1));
+          ASSERT (GetStringWidth (HelpHeaderString) / 2 < ((UINT32) gHelpBlockWidth - 1));
           PrintStringAtWithWidth (
             gStatementDimensions.RightColumn - gHelpBlockWidth,
             Index + TopRow,
@@ -3053,7 +3053,7 @@ UiDisplayMenu (
         gST->ConOut->SetAttribute (gST->ConOut, GetInfoTextColor ());
         for (Index = 0; Index < HelpBottomLine; Index++) {
           ASSERT (HelpBottomLine == 1);
-          ASSERT (GetStringWidth (HelpBottomString) / 2 < (UINTN) (gHelpBlockWidth - 1)); 
+          ASSERT (GetStringWidth (HelpBottomString) / 2 < ((UINT32) gHelpBlockWidth - 1));
           PrintStringAtWithWidth (
             gStatementDimensions.RightColumn - gHelpBlockWidth,
             BottomRow + Index - HelpBottomLine + 1,
diff --git a/MdeModulePkg/Universal/EbcDxe/EbcExecute.c b/MdeModulePkg/Universal/EbcDxe/EbcExecute.c
index e5d290a..2dfed8e 100644
--- a/MdeModulePkg/Universal/EbcDxe/EbcExecute.c
+++ b/MdeModulePkg/Universal/EbcDxe/EbcExecute.c
@@ -1,7 +1,7 @@
 /** @file
   Contains code that implements the virtual machine.
 
-Copyright (c) 2006 - 2014, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2006 - 2017, Intel Corporation. All rights reserved.<BR>
 This program and the accompanying materials
 are licensed and made available under the terms and conditions of the BSD License
 which accompanies this distribution.  The full text of the license may be found at
@@ -2867,7 +2867,7 @@ ExecutePOPn (
   if (OPERAND1_INDIRECT (Operands)) {
     VmWriteMemN (VmPtr, (UINTN) (VmPtr->Gpr[OPERAND1_REGNUM (Operands)] + Index16), DataN);
   } else {
-    VmPtr->Gpr[OPERAND1_REGNUM (Operands)] = (INT64) (UINT64) ((UINTN) DataN + Index16);
+    VmPtr->Gpr[OPERAND1_REGNUM (Operands)] = (INT64) (UINT64) (UINTN) (DataN + Index16);
   }
 
   return EFI_SUCCESS;
@@ -3592,7 +3592,7 @@ ExecuteSUB (
   if ((*VmPtr->Ip & DATAMANIP_M_64) != 0) {
     return (UINT64) ((INT64) ((INT64) Op1 - (INT64) Op2));
   } else {
-    return (UINT64) ((INT64) ((INT32) Op1 - (INT32) Op2));
+    return (UINT64) ((INT64) ((INT32) ((INT32) Op1 - (INT32) Op2)));
   }
 }
 
@@ -3620,7 +3620,7 @@ ExecuteMUL (
   if ((*VmPtr->Ip & DATAMANIP_M_64) != 0) {
     return MultS64x64 ((INT64)Op1, (INT64)Op2);
   } else {
-    return (UINT64) ((INT64) ((INT32) Op1 * (INT32) Op2));
+    return (UINT64) ((INT64) ((INT32) ((INT32) Op1 * (INT32) Op2)));
   }
 }
 
@@ -3648,7 +3648,7 @@ ExecuteMULU (
   if ((*VmPtr->Ip & DATAMANIP_M_64) != 0) {
     return MultU64x64 (Op1, Op2);
   } else {
-    return (UINT64) ((UINT32) Op1 * (UINT32) Op2);
+    return (UINT64) ((UINT32) ((UINT32) Op1 * (UINT32) Op2));
   }
 }
 
diff --git a/MdeModulePkg/Universal/FaultTolerantWriteDxe/UpdateWorkingBlock.c b/MdeModulePkg/Universal/FaultTolerantWriteDxe/UpdateWorkingBlock.c
index d46a37f..b4327b5 100644
--- a/MdeModulePkg/Universal/FaultTolerantWriteDxe/UpdateWorkingBlock.c
+++ b/MdeModulePkg/Universal/FaultTolerantWriteDxe/UpdateWorkingBlock.c
@@ -2,7 +2,7 @@
 
    Internal functions to operate Working Block Space.
 
-Copyright (c) 2006 - 2015, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2006 - 2017, Intel Corporation. All rights reserved.<BR>
 This program and the accompanying materials                          
 are licensed and made available under the terms and conditions of the BSD License         
 which accompanies this distribution.  The full text of the license may be found at        
@@ -55,7 +55,7 @@ InitializeLocalWorkSpaceHeader (
     &gEdkiiWorkingBlockSignatureGuid,
     sizeof (EFI_GUID)
     );
-  mWorkingBlockHeader.WriteQueueSize = (UINT64) (PcdGet32 (PcdFlashNvStorageFtwWorkingSize) - sizeof (EFI_FAULT_TOLERANT_WORKING_BLOCK_HEADER));
+  mWorkingBlockHeader.WriteQueueSize = PcdGet32 (PcdFlashNvStorageFtwWorkingSize) - sizeof (EFI_FAULT_TOLERANT_WORKING_BLOCK_HEADER);
 
   //
   // Crc is calculated with all the fields except Crc and STATE, so leave them as FTW_ERASED_BYTE.
diff --git a/MdeModulePkg/Universal/HiiDatabaseDxe/Font.c b/MdeModulePkg/Universal/HiiDatabaseDxe/Font.c
index 9bef064..b85cf88 100644
--- a/MdeModulePkg/Universal/HiiDatabaseDxe/Font.c
+++ b/MdeModulePkg/Universal/HiiDatabaseDxe/Font.c
@@ -2,7 +2,7 @@
 Implementation for EFI_HII_FONT_PROTOCOL.
 
 
-Copyright (c) 2007 - 2016, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2007 - 2017, Intel Corporation. All rights reserved.<BR>
 This program and the accompanying materials
 are licensed and made available under the terms and conditions of the BSD License
 which accompanies this distribution.  The full text of the license may be found at
@@ -411,7 +411,7 @@ GlyphToBlt (
   // The glyph's upper left hand corner pixel is the most significant bit of the
   // first bitmap byte.
   //
-  for (Ypos = 0; Ypos < Cell->Height && ((UINTN) (Ypos + YposOffset) < RowHeight); Ypos++) {
+  for (Ypos = 0; Ypos < Cell->Height && (((UINT32) Ypos + YposOffset) < RowHeight); Ypos++) {
     OffsetY = BITMAP_LEN_1_BIT (Cell->Width, Ypos);
 
     //
@@ -419,7 +419,7 @@ GlyphToBlt (
     //
     for (Xpos = 0; Xpos < Cell->Width / 8; Xpos++) {
       Data  = *(GlyphBuffer + OffsetY + Xpos);
-      for (Index = 0; Index < 8 && ((UINTN) (Xpos * 8 + Index + Cell->OffsetX) < RowWidth); Index++) {
+      for (Index = 0; Index < 8 && (((UINT32) Xpos * 8 + Index + Cell->OffsetX) < RowWidth); Index++) {
         if ((Data & (1 << (8 - Index - 1))) != 0) {
           BltBuffer[Ypos * ImageWidth + Xpos * 8 + Index] = Foreground;
         } else {
@@ -435,7 +435,7 @@ GlyphToBlt (
       // There are some padding bits in this byte. Ignore them.
       //
       Data  = *(GlyphBuffer + OffsetY + Xpos);
-      for (Index = 0; Index < Cell->Width % 8 && ((UINTN) (Xpos * 8 + Index + Cell->OffsetX) < RowWidth); Index++) {
+      for (Index = 0; Index < Cell->Width % 8 && (((UINT32) Xpos * 8 + Index + Cell->OffsetX) < RowWidth); Index++) {
         if ((Data & (1 << (8 - Index - 1))) != 0) {
           BltBuffer[Ypos * ImageWidth + Xpos * 8 + Index] = Foreground;
         } else {
@@ -1927,7 +1927,7 @@ HiiStringToImage (
     // If this character is the last character of a row, we need not
     // draw its (AdvanceX - Width - OffsetX) for next character.
     //
-    LineWidth -= (UINTN) (Cell[Index].AdvanceX - Cell[Index].Width - Cell[Index].OffsetX);
+    LineWidth -= (Cell[Index].AdvanceX - Cell[Index].Width - Cell[Index].OffsetX);
 
     //
     // Clip the right-most character if cannot fit when EFI_HII_OUT_FLAG_CLEAN_X is set.
@@ -1950,8 +1950,8 @@ HiiStringToImage (
         //
         // Don't draw the last char on this row. And, don't draw the second last char (AdvanceX - Width - OffsetX).
         //
-        LineWidth -= (UINTN) (Cell[Index].Width + Cell[Index].OffsetX);
-        LineWidth -= (UINTN) (Cell[Index - 1].AdvanceX - Cell[Index - 1].Width - Cell[Index - 1].OffsetX);
+        LineWidth -= (Cell[Index].Width + Cell[Index].OffsetX);
+        LineWidth -= (Cell[Index - 1].AdvanceX - Cell[Index - 1].Width - Cell[Index - 1].OffsetX);
         RowInfo[RowIndex].EndIndex       = Index - 1;
         RowInfo[RowIndex].LineWidth      = LineWidth;
         RowInfo[RowIndex].LineHeight     = LineHeight;
@@ -2008,7 +2008,7 @@ HiiStringToImage (
           if (Index1 == RowInfo[RowIndex].StartIndex) {
             LineWidth = 0;
           } else {
-            LineWidth -= (UINTN) (Cell[Index1 - 1].AdvanceX - Cell[Index1 - 1].Width - Cell[Index1 - 1].OffsetX);
+            LineWidth -= (Cell[Index1 - 1].AdvanceX - Cell[Index1 - 1].Width - Cell[Index1 - 1].OffsetX);
           }
           RowInfo[RowIndex].LineWidth = LineWidth;
         }
@@ -2025,8 +2025,8 @@ HiiStringToImage (
             //
             // Don't draw the last char on this row. And, don't draw the second last char (AdvanceX - Width - OffsetX).
             //
-            LineWidth -= (UINTN) (Cell[Index1].Width + Cell[Index1].OffsetX);
-            LineWidth -= (UINTN) (Cell[Index1 - 1].AdvanceX - Cell[Index1 - 1].Width - Cell[Index1 - 1].OffsetX);
+            LineWidth -= (Cell[Index1].Width + Cell[Index1].OffsetX);
+            LineWidth -= (Cell[Index1 - 1].AdvanceX - Cell[Index1 - 1].Width - Cell[Index1 - 1].OffsetX);
             RowInfo[RowIndex].EndIndex       = Index1 - 1;
             RowInfo[RowIndex].LineWidth      = LineWidth;
           } else {
diff --git a/MdeModulePkg/Universal/Network/UefiPxeBcDxe/PxeBcImpl.c b/MdeModulePkg/Universal/Network/UefiPxeBcDxe/PxeBcImpl.c
index 639da48..cd00f5c 100644
--- a/MdeModulePkg/Universal/Network/UefiPxeBcDxe/PxeBcImpl.c
+++ b/MdeModulePkg/Universal/Network/UefiPxeBcDxe/PxeBcImpl.c
@@ -1,7 +1,7 @@
 /** @file
   Interface routines for PxeBc.
 
-Copyright (c) 2007 - 2016, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2007 - 2017, Intel Corporation. All rights reserved.<BR>
 This program and the accompanying materials
 are licensed and made available under the terms and conditions of the BSD License
 which accompanies this distribution.  The full text of the license may be found at
@@ -353,8 +353,8 @@ EfiPxeBcStart (
   //
   // Configure block size for TFTP as a default value to handle all link layers.
   // 
-  Private->BlockSize   = (UINTN) (MIN (Private->Ip4MaxPacketSize, PXEBC_DEFAULT_PACKET_SIZE) - 
-                           PXEBC_DEFAULT_UDP_OVERHEAD_SIZE - PXEBC_DEFAULT_TFTP_OVERHEAD_SIZE);
+  Private->BlockSize   = MIN (Private->Ip4MaxPacketSize, PXEBC_DEFAULT_PACKET_SIZE) -
+                           PXEBC_DEFAULT_UDP_OVERHEAD_SIZE - PXEBC_DEFAULT_TFTP_OVERHEAD_SIZE;
   //
   // If PcdTftpBlockSize is set to non-zero, override the default value.
   //
diff --git a/MdeModulePkg/Universal/PCD/Dxe/Service.c b/MdeModulePkg/Universal/PCD/Dxe/Service.c
index bf77130..efe7248 100644
--- a/MdeModulePkg/Universal/PCD/Dxe/Service.c
+++ b/MdeModulePkg/Universal/PCD/Dxe/Service.c
@@ -2,7 +2,7 @@
     Help functions used by PCD DXE driver.
 
 Copyright (c) 2014, Hewlett-Packard Development Company, L.P.<BR>
-Copyright (c) 2006 - 2016, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2006 - 2017, Intel Corporation. All rights reserved.<BR>
 (C) Copyright 2016 Hewlett Packard Enterprise Development LP<BR>
 This program and the accompanying materials
 are licensed and made available under the terms and conditions of the BSD License
@@ -452,7 +452,7 @@ GetWorker (
   switch (LocalTokenNumber & PCD_TYPE_ALL_SET) {
     case PCD_TYPE_VPD:
       VpdHead = (VPD_HEAD *) ((UINT8 *) PcdDb + Offset);
-      RetPtr = (VOID *) (UINTN) (PcdGet32 (PcdVpdBaseAddress) + VpdHead->Offset);
+      RetPtr = (VOID *) ((UINTN) PcdGet32 (PcdVpdBaseAddress) + VpdHead->Offset);
 
       break;
 
diff --git a/MdeModulePkg/Universal/PCD/Pei/Service.c b/MdeModulePkg/Universal/PCD/Pei/Service.c
index 66ca892..5e1cb72 100644
--- a/MdeModulePkg/Universal/PCD/Pei/Service.c
+++ b/MdeModulePkg/Universal/PCD/Pei/Service.c
@@ -2,7 +2,7 @@
   The driver internal functions are implmented here.
   They build Pei PCD database, and provide access service to PCD database.
 
-Copyright (c) 2006 - 2016, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2006 - 2017, Intel Corporation. All rights reserved.<BR>
 This program and the accompanying materials
 are licensed and made available under the terms and conditions of the BSD License
 which accompanies this distribution.  The full text of the license may be found at
@@ -985,7 +985,7 @@ GetWorker (
     {
       VPD_HEAD *VpdHead;
       VpdHead = (VPD_HEAD *) ((UINT8 *)PeiPcdDb + Offset);
-      return (VOID *) (UINTN) (PcdGet32 (PcdVpdBaseAddress) + VpdHead->Offset);
+      return (VOID *) ((UINTN) PcdGet32 (PcdVpdBaseAddress) + VpdHead->Offset);
     }
       
     case PCD_TYPE_HII|PCD_TYPE_STRING:
diff --git a/MdeModulePkg/Universal/SmbiosDxe/SmbiosDxe.c b/MdeModulePkg/Universal/SmbiosDxe/SmbiosDxe.c
index ea762d5..4e757e1 100644
--- a/MdeModulePkg/Universal/SmbiosDxe/SmbiosDxe.c
+++ b/MdeModulePkg/Universal/SmbiosDxe/SmbiosDxe.c
@@ -2,7 +2,7 @@
   This code produces the Smbios protocol. It also responsible for constructing 
   SMBIOS table into system table.
   
-Copyright (c) 2009 - 2016, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2009 - 2017, Intel Corporation. All rights reserved.<BR>
 This program and the accompanying materials                          
 are licensed and made available under the terms and conditions of the BSD License         
 which accompanies this distribution.  The full text of the license may be found at        
@@ -1138,7 +1138,7 @@ SmbiosCreateTable (
     EntryPointStructure->MaxStructureSize = (UINT16) sizeof (EndStructure);
   }
 
-  if ((UINTN) EFI_SIZE_TO_PAGES (EntryPointStructure->TableLength) > mPreAllocatedPages) {
+  if (EFI_SIZE_TO_PAGES ((UINT32) EntryPointStructure->TableLength) > mPreAllocatedPages) {
     //
     // If new SMBIOS table size exceeds the previous allocated page, 
     // it is time to re-allocate memory (below 4GB).
@@ -1307,7 +1307,7 @@ SmbiosCreate64BitTable (
   EndStructure.Tailing[1] = 0;
   Smbios30EntryPointStructure->TableMaximumSize = (UINT32) (Smbios30EntryPointStructure->TableMaximumSize + sizeof (EndStructure));
 
-  if ((UINTN) EFI_SIZE_TO_PAGES (Smbios30EntryPointStructure->TableMaximumSize) > mPre64BitAllocatedPages) {
+  if (EFI_SIZE_TO_PAGES (Smbios30EntryPointStructure->TableMaximumSize) > mPre64BitAllocatedPages) {
     //
     // If new SMBIOS table size exceeds the previous allocated page, 
     // it is time to re-allocate memory at anywhere.
diff --git a/MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.c b/MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.c
index b0c7434..0a325de 100644
--- a/MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.c
+++ b/MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.c
@@ -3754,8 +3754,8 @@ InitNonVolatileVariableStore (
     return EFI_VOLUME_CORRUPTED;
   }
 
-  VariableStoreBase = (EFI_PHYSICAL_ADDRESS) ((UINTN) FvHeader + FvHeader->HeaderLength);
-  VariableStoreLength = (UINT64) (NvStorageSize - FvHeader->HeaderLength);
+  VariableStoreBase = (UINTN) FvHeader + FvHeader->HeaderLength;
+  VariableStoreLength = NvStorageSize - FvHeader->HeaderLength;
 
   mNvFvHeaderCache = FvHeader;
   mVariableModuleGlobal->VariableGlobal.NonVolatileVariableBase = VariableStoreBase;
@@ -4099,7 +4099,7 @@ VariableCommonInitialize (
   GuidHob = GetFirstGuidHob (VariableGuid);
   if (GuidHob != NULL) {
     VariableStoreHeader = GET_GUID_HOB_DATA (GuidHob);
-    VariableStoreLength = (UINT64) (GuidHob->Header.HobLength - sizeof (EFI_HOB_GUID_TYPE));
+    VariableStoreLength = GuidHob->Header.HobLength - sizeof (EFI_HOB_GUID_TYPE);
     if (GetVariableStoreStatus (VariableStoreHeader) == EfiValid) {
       mVariableModuleGlobal->VariableGlobal.HobVariableBase = (EFI_PHYSICAL_ADDRESS) (UINTN) AllocateRuntimeCopyPool ((UINTN) VariableStoreLength, (VOID *) VariableStoreHeader);
       if (mVariableModuleGlobal->VariableGlobal.HobVariableBase == 0) {
-- 
1.9.5.msysgit.0



^ permalink raw reply related	[flat|nested] 25+ messages in thread

* Re: [PATCH v3 09/12] SecurityPkg/Opal: Refine casting expression result to bigger size
  2017-02-25  5:12 ` [PATCH v3 09/12] SecurityPkg/Opal: " Hao Wu
@ 2017-03-06  1:40   ` Dong, Eric
  0 siblings, 0 replies; 25+ messages in thread
From: Dong, Eric @ 2017-03-06  1:40 UTC (permalink / raw)
  To: Wu, Hao A, edk2-devel@lists.01.org; +Cc: Tian, Feng, Zhang, Chao B

Reviewed-by: Eric Dong <eric.dong@intel.com>

-----Original Message-----
From: Wu, Hao A 
Sent: Saturday, February 25, 2017 1:13 PM
To: edk2-devel@lists.01.org
Cc: Wu, Hao A; Dong, Eric; Tian, Feng; Zhang, Chao B
Subject: [PATCH v3 09/12] SecurityPkg/Opal: Refine casting expression result to bigger size

There are cases that the operands of an expression are all with rank less than UINT64/INT64 and the result of the expression is explicitly cast to
UINT64/INT64 to fit the target size.

An example will be:
UINT32 a,b;
// a and b can be any unsigned int type with rank less than UINT64, like // UINT8, UINT16, etc.
UINT64 c;
c = (UINT64) (a + b);

Some static code checkers may warn that the expression result might overflow within the rank of "int" (integer promotions) and the result is then cast to a bigger size.

The commit refines codes by the following rules:
1). When the expression is possible to overflow the range of unsigned int/
int:
c = (UINT64)a + b;

2). When the expression will not overflow within the rank of "int", remove the explicit type casts:
c = a + b;

3). When the expression will be cast to pointer of possible greater size:
UINT32 a,b;
VOID *c;
c = (VOID *)(UINTN)(a + b); --> c = (VOID *)((UINTN)a + b);

4). When one side of a comparison expression contains only operands with rank less than UINT32:
UINT8 a;
UINT16 b;
UINTN c;
if ((UINTN)(a + b) > c) {...} --> if (((UINT32)a + b) > c) {...}

For rule 4), if we remove the 'UINTN' type cast like:
if (a + b > c) {...}
The VS compiler will complain with warning C4018 (signed/unsigned mismatch, level 3 warning) due to promoting 'a + b' to type 'int'.

Cc: Eric Dong <eric.dong@intel.com>
Cc: Feng Tian <feng.tian@intel.com>
Cc: Chao Zhang <chao.b.zhang@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Hao Wu <hao.a.wu@intel.com>
---
 SecurityPkg/Tcg/Opal/OpalPasswordSmm/OpalNvmeMode.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/SecurityPkg/Tcg/Opal/OpalPasswordSmm/OpalNvmeMode.c b/SecurityPkg/Tcg/Opal/OpalPasswordSmm/OpalNvmeMode.c
index 9e90d54..a47d276 100644
--- a/SecurityPkg/Tcg/Opal/OpalPasswordSmm/OpalNvmeMode.c
+++ b/SecurityPkg/Tcg/Opal/OpalPasswordSmm/OpalNvmeMode.c
@@ -1,7 +1,7 @@
 /** @file
   Provide functions to initialize NVME controller and perform NVME commands
 
-Copyright (c) 2016, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2016 - 2017, Intel Corporation. All rights reserved.<BR>
 This program and the accompanying materials  are licensed and made available under the terms and conditions of the BSD License  which accompanies this distribution.  The full text of the license may be found at @@ -52,7 +52,7 @@ enum {  ///  /// All of base memories are 4K(0x1000) alignment  ///
-#define NVME_MEM_BASE(Nvme)                 (Nvme->BaseMem)
+#define NVME_MEM_BASE(Nvme)                 ((UINTN)(Nvme->BaseMem))
 #define NVME_CONTROL_DATA_BASE(Nvme)        (ALIGN (NVME_MEM_BASE(Nvme) + ((NvmeGetBaseMemPages (BASEMEM_CONTROLLER_DATA))                        * EFI_PAGE_SIZE), EFI_PAGE_SIZE))
 #define NVME_NAMESPACE_DATA_BASE(Nvme)      (ALIGN (NVME_MEM_BASE(Nvme) + ((NvmeGetBaseMemPages (BASEMEM_IDENTIFY_DATA))                          * EFI_PAGE_SIZE), EFI_PAGE_SIZE))
 #define NVME_ASQ_BASE(Nvme)                 (ALIGN (NVME_MEM_BASE(Nvme) + ((NvmeGetBaseMemPages (BASEMEM_ASQ))                                    * EFI_PAGE_SIZE), EFI_PAGE_SIZE))
--
1.9.5.msysgit.0



^ permalink raw reply related	[flat|nested] 25+ messages in thread

end of thread, other threads:[~2017-03-06  1:40 UTC | newest]

Thread overview: 25+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-02-25  5:12 [PATCH v3 00/12] Refine casting expression result to bigger size Hao Wu
2017-02-25  5:12 ` [PATCH v3 01/12] MdePkg: " Hao Wu
2017-02-25  5:12 ` [PATCH v3 02/12] MdeModulePkg: " Hao Wu
2017-03-06  1:37   ` Tian, Feng
2017-02-25  5:12 ` [PATCH v3 03/12] FatPkg: " Hao Wu
2017-02-27  5:07   ` Ni, Ruiyu
2017-02-25  5:12 ` [PATCH v3 04/12] IntelFrameworkModulePkg: " Hao Wu
2017-02-27  7:06   ` Fan, Jeff
2017-02-25  5:12 ` [PATCH v3 05/12] IntelFsp2WrapperPkg: " Hao Wu
2017-02-25  5:51   ` Yao, Jiewen
2017-02-25  5:12 ` [PATCH v3 06/12] IntelFspWrapperPkg: " Hao Wu
2017-02-25  5:51   ` Yao, Jiewen
2017-02-25  5:12 ` [PATCH v3 07/12] NetworkPkg: " Hao Wu
2017-02-27  2:21   ` Wu, Jiaxin
2017-02-25  5:12 ` [PATCH v3 08/12] PcAtChipsetPkg: " Hao Wu
2017-02-27  7:24   ` Ni, Ruiyu
2017-02-25  5:12 ` [PATCH v3 09/12] SecurityPkg/Opal: " Hao Wu
2017-03-06  1:40   ` Dong, Eric
2017-02-25  5:12 ` [PATCH v3 10/12] ShellPkg: " Hao Wu
2017-02-27  2:22   ` Ni, Ruiyu
2017-02-27 16:38   ` Carsey, Jaben
2017-02-25  5:12 ` [PATCH v3 11/12] SourceLevelDebugPkg: " Hao Wu
2017-02-27  7:27   ` Fan, Jeff
2017-02-25  5:12 ` [PATCH v3 12/12] UefiCpuPkg: " Hao Wu
2017-02-27  7:27   ` Fan, Jeff

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox