[edk2-devel] [PATCH edk2-platforms v1 1/3] Silicon/Marvell/Drivers: Casts to avoid void* pointer arithmetic

PierreGondois pierre.gondois at arm.com
Thu Jul 30 19:15:09 UTC 2020


From: Pierre Gondois <pierre.gondois at arm.com>

By default, gcc allows void* pointer arithmetic.
This is a GCC extension.
However, the C reference manual states that void*
pointer "cannot be operands of addition or subtraction
operators". Cf s5.3.1 "Generic Pointers".

This patch adds casts to avoid doing void* pointer arithmetic.

Signed-off-by: Pierre Gondois <pierre.gondois at arm.com>
---

The changes can be seen at: https://github.com/PierreARM/edk2-platforms/commits/Casts_avoiding_void_pointer_arith_v1

Notes:
    v1:
     - Use casts to avoid void* pointer arithmetic. [Pierre]

 Silicon/Marvell/Drivers/Net/Pp2Dxe/Pp2Dxe.c                   | 5 +++--
 Silicon/Marvell/Drivers/SdMmc/XenonDxe/XenonSdhci.c           | 5 +++--
 Silicon/Marvell/Drivers/SmbiosPlatformDxe/SmbiosPlatformDxe.c | 4 ++--
 Silicon/Marvell/Drivers/Spi/MvSpiFlashDxe/MvSpiFlashDxe.c     | 9 ++++++---
 4 files changed, 14 insertions(+), 9 deletions(-)

diff --git a/Silicon/Marvell/Drivers/Net/Pp2Dxe/Pp2Dxe.c b/Silicon/Marvell/Drivers/Net/Pp2Dxe/Pp2Dxe.c
index 9a1d1a7bede84d75a58806bf5f594684eaa9f0cb..0872f1788993b09394fb339f4c2113cc7d6a4491 100644
--- a/Silicon/Marvell/Drivers/Net/Pp2Dxe/Pp2Dxe.c
+++ b/Silicon/Marvell/Drivers/Net/Pp2Dxe/Pp2Dxe.c
@@ -1,5 +1,6 @@
 /********************************************************************************
 Copyright (C) 2016 Marvell International Ltd.
+Copyright (c) 2020, Arm Limited. All rights reserved.<BR>
 
 SPDX-License-Identifier: BSD-2-Clause-Patent
 
@@ -1342,7 +1343,7 @@ Pp2DxeInitialiseController (
 
   for (Index = 0; Index < MVPP2_MAX_PORT; Index++) {
     Mvpp2Shared->BufferLocation.TxDescs[Index] = (MVPP2_TX_DESC *)
-      (BufferSpace + Index * MVPP2_MAX_TXD * sizeof(MVPP2_TX_DESC));
+      ((UINTN)BufferSpace + Index * MVPP2_MAX_TXD * sizeof(MVPP2_TX_DESC));
   }
 
   Mvpp2Shared->BufferLocation.AggrTxDescs = (MVPP2_TX_DESC *)
@@ -1356,7 +1357,7 @@ Pp2DxeInitialiseController (
 
   for (Index = 0; Index < MVPP2_MAX_PORT; Index++) {
     Mvpp2Shared->BufferLocation.RxBuffers[Index] = (DmaAddrT)
-      (BufferSpace + (MVPP2_MAX_TXD * MVPP2_MAX_PORT + MVPP2_AGGR_TXQ_SIZE) *
+      ((UINTN)BufferSpace + (MVPP2_MAX_TXD * MVPP2_MAX_PORT + MVPP2_AGGR_TXQ_SIZE) *
       sizeof(MVPP2_TX_DESC) + MVPP2_MAX_RXD * MVPP2_MAX_PORT * sizeof(MVPP2_RX_DESC) +
       Index * MVPP2_BM_SIZE * RX_BUFFER_SIZE);
   }
diff --git a/Silicon/Marvell/Drivers/SdMmc/XenonDxe/XenonSdhci.c b/Silicon/Marvell/Drivers/SdMmc/XenonDxe/XenonSdhci.c
index 6059cf84d934a84bed704ad8cb2090db63d33a45..9fbf302c2848ae9491043b2a281905638ae3d61a 100755
--- a/Silicon/Marvell/Drivers/SdMmc/XenonDxe/XenonSdhci.c
+++ b/Silicon/Marvell/Drivers/SdMmc/XenonDxe/XenonSdhci.c
@@ -1,5 +1,6 @@
 /*******************************************************************************
 Copyright (C) 2016 Marvell International Ltd.
+Copyright (c) 2020, Arm Limited. All rights reserved.<BR>
 
 SPDX-License-Identifier: BSD-2-Clause-Patent
 
@@ -629,7 +630,7 @@ XenonTransferPio (
   // solution.
   //
   for (Index = 0; Index < BlockSize; Index += 4) {
-    Offs = Buffer + Index;
+    Offs = (UINT8*)((UINTN)Buffer + Index);
     if (Read) {
       *(UINT32 *)Offs = MmioRead32 (SDHC_DAT_BUF_PORT_ADDR);
     } else {
@@ -699,7 +700,7 @@ XenonTransferData (
 
       XenonTransferPio (Slot, Buffer, BlockSize, Read);
 
-      Buffer += BlockSize;
+      Buffer = (VOID*)((UINTN)Buffer + BlockSize);
       if (++Block >= Blocks) {
         break;
       }
diff --git a/Silicon/Marvell/Drivers/SmbiosPlatformDxe/SmbiosPlatformDxe.c b/Silicon/Marvell/Drivers/SmbiosPlatformDxe/SmbiosPlatformDxe.c
index 3b909f341289dc829684527a562eb9183bd94246..2ecaec2af515267ddaeb24248d6e1a629f554ddb 100644
--- a/Silicon/Marvell/Drivers/SmbiosPlatformDxe/SmbiosPlatformDxe.c
+++ b/Silicon/Marvell/Drivers/SmbiosPlatformDxe/SmbiosPlatformDxe.c
@@ -1,7 +1,7 @@
 /** @file
   This driver installs SMBIOS information for Marvell Armada platforms
 
-  Copyright (c) 2015, ARM Limited. All rights reserved.
+  Copyright (c) 2015-2020, Arm Limited. All rights reserved.<BR>
   Copyright (c) 2019, Marvell International Ltd. and its affiliates
 
   SPDX-License-Identifier: BSD-2-Clause-Patent
@@ -605,7 +605,7 @@ LogSmbiosData (
   CopyMem (Record, Template, Template->Length);
 
   // Append string pack
-  Str = ((VOID *)Record) + Record->Length;
+  Str = (CHAR8*)((UINTN)Record + Record->Length);
   for (Index = 0; StringArray[Index] != NULL; Index++) {
     StringSize = AsciiStrSize (StringArray[Index]);
     CopyMem (Str, StringArray[Index], StringSize);
diff --git a/Silicon/Marvell/Drivers/Spi/MvSpiFlashDxe/MvSpiFlashDxe.c b/Silicon/Marvell/Drivers/Spi/MvSpiFlashDxe/MvSpiFlashDxe.c
index db12adb7644ec3f211df75ef16bb19e7c96fbdc7..f99f3d5763cdb25206e2e3d9165b6c9039690fcb 100755
--- a/Silicon/Marvell/Drivers/Spi/MvSpiFlashDxe/MvSpiFlashDxe.c
+++ b/Silicon/Marvell/Drivers/Spi/MvSpiFlashDxe/MvSpiFlashDxe.c
@@ -1,5 +1,6 @@
 /*******************************************************************************
 Copyright (C) 2016 Marvell International Ltd.
+Copyright (c) 2020, Arm Limited. All rights reserved.<BR>
 
 SPDX-License-Identifier: BSD-2-Clause-Patent
 
@@ -233,7 +234,7 @@ MvSpiFlashRead (
 
     Offset += ReadLength;
     Length -= ReadLength;
-    Buf += ReadLength;
+    Buf = (VOID*)((UINTN)Buf + ReadLength);
   }
 
   return Status;
@@ -268,8 +269,10 @@ MvSpiFlashWrite (
     SpiFlashFormatAddress (WriteAddr, Slave->AddrSize, Cmd);
 
     // Program proper write address and write data
-    Status = MvSpiFlashWriteCommon (Slave, Cmd, Slave->AddrSize + 1, Buf + ActualIndex,
-      ChunkLength);
+    Status = MvSpiFlashWriteCommon (
+      Slave, Cmd, Slave->AddrSize + 1,
+      (VOID*)((UINTN)Buf + ActualIndex), ChunkLength
+      );
     if (EFI_ERROR (Status)) {
       DEBUG((DEBUG_ERROR, "SpiFlash: Error while programming write address\n"));
       return Status;
-- 
'Guid(CE165669-3EF3-493F-B85D-6190EE5B9759)'


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#63517): https://edk2.groups.io/g/devel/message/63517
Mute This Topic: https://groups.io/mt/75893334/1813853
Group Owner: devel+owner at edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [edk2-devel-archive at redhat.com]
-=-=-=-=-=-=-=-=-=-=-=-




More information about the edk2-devel-archive mailing list