From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: mx.groups.io; dkim=pass header.i=@armh.onmicrosoft.com header.s=selector2-armh-onmicrosoft-com header.b=om4n4/GX; spf=pass (domain: arm.com, ip: 40.107.15.77, mailfrom: alexei.fedorov@arm.com) Received: from EUR01-DB5-obe.outbound.protection.outlook.com (EUR01-DB5-obe.outbound.protection.outlook.com [40.107.15.77]) by groups.io with SMTP; Fri, 23 Aug 2019 04:49:03 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=armh.onmicrosoft.com; s=selector2-armh-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=wwAzFojyCO3tB2qXr5eVuSrZB2fgHDtcH1TJnLSmy8E=; b=om4n4/GX8mO/T9qWkgheXbZAHIMIrjyTCgsORGVvU7zJoTf0bizNcwcGprX+o6bTKsLnRhGAMpkTx+iBqsoMwj9koHxroH1AU4psI9PulxIjQCp3vbshhWHiy4Tze5I8RWm4Oupj7ytqRhfG8IxFGSwRQTDwcSlwf68E2LGQnhg= Received: from AM4PR08CA0055.eurprd08.prod.outlook.com (2603:10a6:205:2::26) by DB6PR0801MB1846.eurprd08.prod.outlook.com (2603:10a6:4:35::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2178.16; Fri, 23 Aug 2019 11:48:58 +0000 Received: from VE1EUR03FT046.eop-EUR03.prod.protection.outlook.com (2a01:111:f400:7e09::203) by AM4PR08CA0055.outlook.office365.com (2603:10a6:205:2::26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.2199.14 via Frontend Transport; Fri, 23 Aug 2019 11:48:58 +0000 Authentication-Results: spf=temperror (sender IP is 63.35.35.123) smtp.mailfrom=arm.com; edk2.groups.io; dkim=pass (signature was verified) header.d=armh.onmicrosoft.com;edk2.groups.io; dmarc=temperror action=none header.from=arm.com; Received-SPF: TempError (protection.outlook.com: error in processing during lookup of arm.com: DNS Timeout) Received: from 64aa7808-outbound-1.mta.getcheckrecipient.com (63.35.35.123) by VE1EUR03FT046.mail.protection.outlook.com (10.152.19.226) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.2199.13 via Frontend Transport; Fri, 23 Aug 2019 11:48:56 +0000 Received: ("Tessian outbound 8b8b6ad907d7:v27"); Fri, 23 Aug 2019 11:48:56 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: cc4e5c69f1389ed2 X-CR-MTA-TID: 64aa7808 Received: from 1c8d8d7ac56e.2 (ip-172-16-0-2.eu-west-1.compute.internal [104.47.5.50]) by 64aa7808-outbound-1.mta.getcheckrecipient.com id 7BDE4A58-4BBC-4B1E-81FB-D732C46207C6.1; Fri, 23 Aug 2019 11:48:51 +0000 Received: from EUR02-HE1-obe.outbound.protection.outlook.com (mail-he1eur02lp2050.outbound.protection.outlook.com [104.47.5.50]) by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id 1c8d8d7ac56e.2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Fri, 23 Aug 2019 11:48:51 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=jzSSBcM5IXAPhk0qJalk2GCvH3cbeGlZ6xkZFq+E57bRRNO5RNZS8uTSrBoQAyBwShmAAk1fck7zl5fh1eDQACBSW3Fvz4F3UX21RpPcE3NaPD+HWZnKECKcLPvg+70V1ETzde9Fo1MBLmgx+PDS8384e9j4CZDjOaZ7NPxIIFO5D+pw6nATSj6W1qchffooJ0/jDHWQqjovLigeY4IEaSZ66VLPXLYAi0MFBFAOkMhume1ZzicuCqZ4f7D2PbiUly9RsjF1XgfxrnitMbai8V2TWln6/cMWLe44e+kfA/9eR+yWy/6CdZljFO0thGjfPcLpO37cm5R4Y3xlbwinaQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=EORLztHivJRk9f8MEB5Xy+AqoUYzT/0YyKBVLgFlGA0=; b=VSBseImxzAplTPOnvBt0Oc6KIXXaUtuxnjiLsTqgxqOlhZgrs2SJK1Gq3uKBcOGlvI3OKyByAJFQO/egIh0OYAhYpJk3UeTD4kC7rvc8xffBRwlX0GLPiFeW4vnE1mhJHi6tds8GFThXJdvxjq7E7mdNIBEe5/6Y03FgB35vZms9u7Q9/k954K/y0JcYz675g/EEzgtrZ9we8/JByMrjazOAuxlfUQxRNMf3K+uCHwfSoh7/C68CzHlao5BS8L6ndzfrwh/kJ9orTxTJxCMy7d2CMZ4xEvHy4Lsj3TgjIhvHLRPgDwW+JTzlvN1PVZ9wQuWxFkztg2r5G1L7HkWKYA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=arm.com; dmarc=pass action=none header.from=arm.com; dkim=pass header.d=arm.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=armh.onmicrosoft.com; s=selector2-armh-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=EORLztHivJRk9f8MEB5Xy+AqoUYzT/0YyKBVLgFlGA0=; b=kBTgkpMMUG03GetscynaZ6xaR2Vlhrejs8MzCsAqISQgK41pypXNB17BTPwQTcCsNoRL9nZqtPyw2sV20O4csqnI2WBziT6MJJnOb2/2woHCvfD1QgbR7LvHwAPiYibY4dYy+nBpwuljIYLpvh1oTLTMd06gv879RMAuhVHow6c= Received: from AM5PR0801MB1732.eurprd08.prod.outlook.com (10.169.244.21) by AM5PR0801MB1906.eurprd08.prod.outlook.com (10.168.156.148) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2178.18; Fri, 23 Aug 2019 11:48:50 +0000 Received: from AM5PR0801MB1732.eurprd08.prod.outlook.com ([fe80::50d7:cef5:ee39:2e83]) by AM5PR0801MB1732.eurprd08.prod.outlook.com ([fe80::50d7:cef5:ee39:2e83%9]) with mapi id 15.20.2178.020; Fri, 23 Aug 2019 11:48:50 +0000 From: "Alexei Fedorov" To: Sami Mujawar , "devel@edk2.groups.io" Subject: Re: [PATCH v1 17/19] ArmPlatformPkg: Fix UART divisor warning Thread-Topic: [PATCH v1 17/19] ArmPlatformPkg: Fix UART divisor warning Thread-Index: AQHVWaGzE/WF4cb0kkqSJPutu1NIT6cIniI9 Date: Fri, 23 Aug 2019 11:48:50 +0000 Message-ID: References: <20190823105539.13260-1-sami.mujawar@arm.com>,<20190823105539.13260-18-sami.mujawar@arm.com> In-Reply-To: <20190823105539.13260-18-sami.mujawar@arm.com> Accept-Language: en-GB, en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: Authentication-Results-Original: spf=none (sender IP is ) smtp.mailfrom=Alexei.Fedorov@arm.com; x-originating-ip: [217.140.106.49] x-ms-publictraffictype: Email X-MS-Office365-Filtering-Correlation-Id: 87f012ce-5ad9-4581-bfae-08d727bfe175 X-MS-Office365-Filtering-HT: Tenant X-Microsoft-Antispam-Untrusted: BCL:0;PCL:0;RULEID:(2390118)(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600166)(711020)(4605104)(1401327)(4618075)(2017052603328)(7193020);SRVR:AM5PR0801MB1906; X-MS-TrafficTypeDiagnostic: AM5PR0801MB1906:|DB6PR0801MB1846: x-ms-exchange-transport-forked: True X-Microsoft-Antispam-PRVS: x-checkrecipientrouted: true x-ms-oob-tlc-oobclassifiers: OLM:212;OLM:212; x-forefront-prvs: 0138CD935C X-Forefront-Antispam-Report-Untrusted: SFV:NSPM;SFS:(10009020)(4636009)(346002)(396003)(136003)(376002)(39860400002)(366004)(189003)(199004)(76176011)(19627405001)(26005)(2501003)(9686003)(66066001)(186003)(3846002)(102836004)(25786009)(105004)(6116002)(2906002)(55016002)(99286004)(66946007)(476003)(14444005)(53546011)(7696005)(446003)(76116006)(66446008)(478600001)(256004)(11346002)(66476007)(66556008)(64756008)(8936002)(8676002)(53936002)(52536014)(229853002)(486006)(33656002)(6506007)(19627235002)(81166006)(74316002)(6246003)(316002)(7736002)(71190400001)(71200400001)(54896002)(5660300002)(81156014)(86362001)(110136005)(14454004)(6436002)(46800400005);DIR:OUT;SFP:1101;SCL:1;SRVR:AM5PR0801MB1906;H:AM5PR0801MB1732.eurprd08.prod.outlook.com;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;MX:1;A:1; received-spf: None (protection.outlook.com: arm.com does not designate permitted sender hosts) X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Message-Info-Original: 177C3D47oG03EQSdD/GHxWBXBascD23ptghHpfnf5Y8zAmXYjQ2kHFhngEb9C9dRelZTKwfMSXH72mtUrTfeiJp2z3sXVcpuIcJefj1wRZRG85P7h8TWOdF9NrRCvQ/1Mp8WAsgejrgeWKddB3F83wVaKConqFkUSyAEm16JYSLyi8wBeeha+F71blSW7QaDUfoQoIgiRyejeZYTq/VCdGLJ5O1UASBupgtaPj2C4iTE8KELou/bu2kH5XGlyoZR6H4exuS1LQmFsIGYi0voAvscplPzmzvcFgOF5qBSOK1VMOplxQWobf2aR8P1VBL6VyiX8hOESGxcYLnSaK/RF/FCdcYgjrt4gzCDCxHV/I+/ht7e/ScbYWMXHG0QNLA7vm6m+Gr5ZL+tat7ZCZlfFIX8kBHDE5b6VK+G/csA3Ig= MIME-Version: 1.0 X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM5PR0801MB1906 Original-Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Alexei.Fedorov@arm.com; Return-Path: Alexei.Fedorov@arm.com X-EOPAttributedMessage: 0 X-MS-Exchange-Transport-CrossTenantHeadersStripped: VE1EUR03FT046.eop-EUR03.prod.protection.outlook.com X-Forefront-Antispam-Report: CIP:63.35.35.123;IPV:CAL;SCL:-1;CTRY:IE;EFV:NLI;SFV:NSPM;SFS:(10009020)(4636009)(346002)(396003)(376002)(39860400002)(136003)(2980300002)(199004)(189003)(40434004)(9686003)(5660300002)(19627405001)(70206006)(81156014)(81166006)(33656002)(76130400001)(5024004)(26826003)(14444005)(7696005)(14454004)(70586007)(478600001)(476003)(22756006)(8676002)(76176011)(36906005)(8936002)(126002)(11346002)(2501003)(316002)(53546011)(110136005)(446003)(63350400001)(6506007)(16586007)(63370400001)(55016002)(74316002)(356004)(6246003)(229853002)(7736002)(25786009)(2906002)(105004)(336012)(71190400001)(6116002)(86362001)(66066001)(26005)(102836004)(486006)(99286004)(19627235002)(54896002)(52536014)(186003)(3846002)(46800400005);DIR:OUT;SFP:1101;SCL:1;SRVR:DB6PR0801MB1846;H:64aa7808-outbound-1.mta.getcheckrecipient.com;FPR:;SPF:TempError;LANG:en;PTR:ec2-63-35-35-123.eu-west-1.compute.amazonaws.com;A:1;MX:1; X-MS-Office365-Filtering-Correlation-Id-Prvs: 4523c1cc-5951-4f2e-3b6c-08d727bfdd4d X-Microsoft-Antispam: BCL:0;PCL:0;RULEID:(2390118)(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600166)(710020)(711020)(4605104)(1401327)(2017052603328)(7193020);SRVR:DB6PR0801MB1846; X-Forefront-PRVS: 0138CD935C X-Microsoft-Antispam-Message-Info: 6uCp4QjdHIdqIg+sJW6ilsOCVhBWAajcSl3vzvIR+lJxAn5Oir8HU3GMkg+CLlmexxO/gun7d0dT3f89q+bRIA1+Lg/+/xyoRTahpzdBUEqOBsOAqp5uDEz9g6CyBOYcziqN5mt5+SzoN3Xh4uYqzBncigDBbEHO48glFaFqUrqvw+/JWsRihkfQxl5CWfyLVBXtyQiVxqFot25mlA36n6IPweaZgA+XBE1Ut7mtYguQ2QhqXT4JKc7er9mLP/Nf4DmggZsNfHOEBPiHlWf/iyxnVd/SyuuMYw8/Xxj8RYuOjX25h2gkiiPkinV5tlw8p0vquMwT5BSogPY8cq2XHicZYnDgirYbOBR+yG7LXcGNTr3Czr5ZiqcQKmOGCvsxlC3hKzJTR36uLyho5/WKqmshEOVW1ArvB7J6XR63NiY= X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Aug 2019 11:48:56.9733 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 87f012ce-5ad9-4581-bfae-08d727bfe175 X-MS-Exchange-CrossTenant-Id: f34e5979-57d9-4aaa-ad4d-b122a662184d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=f34e5979-57d9-4aaa-ad4d-b122a662184d;Ip=[63.35.35.123];Helo=[64aa7808-outbound-1.mta.getcheckrecipient.com] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB6PR0801MB1846 Content-Language: en-GB Content-Type: multipart/alternative; boundary="_000_AM5PR0801MB17326BB90F738D94B068DAE19AA40AM5PR0801MB1732_" --_000_AM5PR0801MB17326BB90F738D94B068DAE19AA40AM5PR0801MB1732_ Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Reviewed-by: Alexei Fedorov Alexei ________________________________ From: Sami Mujawar Sent: 23 August 2019 11:55 To: devel@edk2.groups.io Cc: Sami Mujawar ; Alexei Fedorov ; ard.biesheuvel@linaro.org ; leif.lindholm= @linaro.org ; Matteo Carlini ; nd Subject: [PATCH v1 17/19] ArmPlatformPkg: Fix UART divisor warning The VS2017 compiler reports 'warning C4244: '=3D': conversion from 'UINT64' to 'UINT32', possible loss of data' for the calculation of the UART Divisor value. Fix this warning by adding appropriate typecast and a validation that ensures that the UART divisor value generated does not exceed MAX_UINT32. Signed-off-by: Sami Mujawar --- ArmPlatformPkg/Library/PL011UartLib/PL011UartLib.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/ArmPlatformPkg/Library/PL011UartLib/PL011UartLib.c b/ArmPlatfo= rmPkg/Library/PL011UartLib/PL011UartLib.c index 801990d9551a638c17d560d4226137b8a3ee47bb..2d3c279cce49304959953ec4a34= b50e09a7d0045 100644 --- a/ArmPlatformPkg/Library/PL011UartLib/PL011UartLib.c +++ b/ArmPlatformPkg/Library/PL011UartLib/PL011UartLib.c @@ -2,7 +2,7 @@ Serial I/O Port library functions with no library constructor/destructor Copyright (c) 2008 - 2010, Apple Inc. All rights reserved.
- Copyright (c) 2011 - 2016, ARM Ltd. All rights reserved.
+ Copyright (c) 2011 - 2019, ARM Ltd. All rights reserved.
SPDX-License-Identifier: BSD-2-Clause-Patent @@ -78,6 +78,7 @@ PL011UartInitializePort ( UINT32 Integer; UINT32 Fractional; UINT32 HardwareFifoDepth; + UINT64 DivisorValue; HardwareFifoDepth =3D (PL011_UARTPID2_VER (MmioRead32 (UartBase + UARTPI= D2)) \ > PL011_VER_R1P4) \ @@ -188,7 +189,12 @@ PL011UartInitializePort ( return RETURN_INVALID_PARAMETER; } - Divisor =3D (UartClkInHz * 4) / *BaudRate; + DivisorValue =3D (((UINT64)UartClkInHz * 4) / *BaudRate); + if (DivisorValue > MAX_UINT32) { + return RETURN_INVALID_PARAMETER; + } + + Divisor =3D (UINT32)DivisorValue; Integer =3D Divisor >> FRACTION_PART_SIZE_IN_BITS; Fractional =3D Divisor & FRACTION_PART_MASK; } -- 'Guid(CE165669-3EF3-493F-B85D-6190EE5B9759)' IMPORTANT NOTICE: The contents of this email and any attachments are confid= ential and may also be privileged. If you are not the intended recipient, p= lease notify the sender immediately and do not disclose the contents to any= other person, use it for any purpose, or store or copy the information in = any medium. Thank you. --_000_AM5PR0801MB17326BB90F738D94B068DAE19AA40AM5PR0801MB1732_ Content-Type: text/html; charset="us-ascii" Content-Transfer-Encoding: quoted-printable
Reviewed-by: Alexei Fedorov <Alexei.Fedorov@arm.com>

Alexei


From: Sami Mujawar <sami= .mujawar@arm.com>
Sent: 23 August 2019 11:55
To: devel@edk2.groups.io <devel@edk2.groups.io>
Cc: Sami Mujawar <Sami.Mujawar@arm.com>; Alexei Fedorov <Al= exei.Fedorov@arm.com>; ard.biesheuvel@linaro.org <ard.biesheuvel@lina= ro.org>; leif.lindholm@linaro.org <leif.lindholm@linaro.org>; Matt= eo Carlini <Matteo.Carlini@arm.com>; nd <nd@arm.com>
Subject: [PATCH v1 17/19] ArmPlatformPkg: Fix UART divisor warning
 
The VS2017 compiler reports 'warning C4244: '=3D':= conversion
from 'UINT64' to 'UINT32', possible loss of data' for the
calculation of the UART Divisor value.

Fix this warning by adding appropriate typecast and a validation
that ensures that the UART divisor value generated does not exceed
MAX_UINT32.

Signed-off-by: Sami Mujawar <sami.mujawar@arm.com>
---
 ArmPlatformPkg/Library/PL011UartLib/PL011UartLib.c | 10 ++= 3;+++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/ArmPlatformPkg/Library/PL011UartLib/PL011UartLib.c b/ArmPlatfo= rmPkg/Library/PL011UartLib/PL011UartLib.c
index 801990d9551a638c17d560d4226137b8a3ee47bb..2d3c279cce49304959953ec4a34= b50e09a7d0045 100644
--- a/ArmPlatformPkg/Library/PL011UartLib/PL011UartLib.c
+++ b/ArmPlatformPkg/Library/PL011UartLib/PL011UartLib.c
@@ -2,7 +2,7 @@
   Serial I/O Port library functions with no library constructor/= destructor
 
   Copyright (c) 2008 - 2010, Apple Inc. All rights reserved.<= BR>
-  Copyright (c) 2011 - 2016, ARM Ltd. All rights reserved.<BR><= br> +  Copyright (c) 2011 - 2019, ARM Ltd. All rights reserved.<BR&= gt;
 
   SPDX-License-Identifier: BSD-2-Clause-Patent
 
@@ -78,6 +78,7 @@ PL011UartInitializePort (
   UINT32      Integer;
   UINT32      Fractional;
   UINT32      HardwareFifoDepth;
+  UINT64      DivisorValue;
 
   HardwareFifoDepth =3D (PL011_UARTPID2_VER (MmioRead32 (UartBas= e + UARTPID2)) \
            &nb= sp;           > PL011_= VER_R1P4) \
@@ -188,7 +189,12 @@ PL011UartInitializePort (
       return RETURN_INVALID_PARAMETER;
     }
 
-    Divisor =3D (UartClkInHz * 4) / *BaudRate;
+    DivisorValue =3D (((UINT64)UartClkInHz * 4) / *Baud= Rate);
+    if (DivisorValue > MAX_UINT32) {
+      return RETURN_INVALID_PARAMETER;
+    }
+
+    Divisor =3D (UINT32)DivisorValue;
     Integer =3D Divisor >> FRACTION_PART_SIZE_IN= _BITS;
     Fractional =3D Divisor & FRACTION_PART_MASK;    }
--
'Guid(CE165669-3EF3-493F-B85D-6190EE5B9759)'


IMPORTANT NOTICE: The contents of this email and any attachments are confid= ential and may also be privileged. If you are not the intended recipient, p= lease notify the sender immediately and do not disclose the contents to any= other person, use it for any purpose, or store or copy the information in any medium. Thank you. --_000_AM5PR0801MB17326BB90F738D94B068DAE19AA40AM5PR0801MB1732_--