From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from cam-smtp0.cambridge.arm.com (cam-smtp0.cambridge.arm.com [217.140.106.54]) by mx.groups.io with SMTP id smtpd.web12.2367.1596136519406212551 for ; Thu, 30 Jul 2020 12:15:20 -0700 Authentication-Results: mx.groups.io; dkim=missing; spf=pass (domain: arm.com, ip: 217.140.106.54, mailfrom: pierre.gondois@arm.com) Received: from E119881.Arm.com (E119881.Arm.com [10.1.197.28]) by cam-smtp0.cambridge.arm.com (8.13.8/8.13.8) with ESMTP id 06UJFG0O008924; Thu, 30 Jul 2020 20:15:17 +0100 From: "PierreGondois" To: devel@edk2.groups.io Cc: Pierre Gondois , leif@nuviainc.com, ard.biesheuvel@arm.com, sami.mujawar@arm.com, nd@arm.com Subject: [PATCH edk2-platforms v1 1/3] Silicon/Marvell/Drivers: Casts to avoid void* pointer arithmetic Date: Thu, 30 Jul 2020 20:15:09 +0100 Message-Id: <20200730191511.101896-2-pierre.gondois@arm.com> X-Mailer: git-send-email 2.16.2.windows.1 In-Reply-To: <20200730191511.101896-1-pierre.gondois@arm.com> References: <20200730191511.101896-1-pierre.gondois@arm.com> From: Pierre Gondois 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 --- 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.
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.
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.
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.
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)'