From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-1.mimecast.com (us-smtp-1.mimecast.com [207.211.31.120]) by mx.groups.io with SMTP id smtpd.web12.24933.1574349210135964410 for ; Thu, 21 Nov 2019 07:13:30 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=aKFOOPAc; spf=pass (domain: redhat.com, ip: 207.211.31.120, mailfrom: philmd@redhat.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1574349209; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=0MWNmYCVlFfMFIppoPFtngvvRwskablkdKV2fZ5UE0o=; b=aKFOOPAcd67V1F26CnChSfF4tBVhjD+a2/tiOCIX2WrKERxnJp9iskPlgjM/IfsITFNLcU NvK4qOm23+V73bhGgU7MBL8n45SB7GPpyHwvKz7S46M2tGIb0jf/2F0NjlKiqWOgDltgNN jxWPJ5fblBAMOqIg9+XsCPthDURBe20= Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-353-Ig0jwpM9MVOzF3TM-SoNYQ-1; Thu, 21 Nov 2019 10:13:27 -0500 Received: by mail-wr1-f69.google.com with SMTP id c12so954185wrq.7 for ; Thu, 21 Nov 2019 07:13:27 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=zhHS+r43ITgRecV6AKjEpYQGLT2OVOkM+BnMov6CfbI=; b=YwWzonJTmLY2qwaSNa9GzdH5lLOdzF7ACy6+xuNijhE4NZziebkFUfbnq3qGrkbr+N 2yw7ZXGT7CNXm01HXh5Utz/bQs0qsIi10PuFMbQq85ubAAWLBLNDr15RJtNa/1erc9Qd AnTPBtgnUu/I5QyDjgmRzxajNzhAQWIQA6MhdDIADy7Huh2V844KKE9gf3YmlPiI6gmL qqJ+pGbGEr0r9tOCfuWbOqefsr9SGGA/u+lhxqL2kgRlVmFHBZGhQl8AHiqjFOzM5QjT 3Wq46t7dopp+7zNmr3cWGhw1hxcx4xSE6jSNFJz1tXrjmVEvWRlVC4m5gDiTD3kCDdKw LdoA== X-Gm-Message-State: APjAAAVzTQAlQ6ltY/QZ4FRi7EpIYOgLVPUZkyw0SbDxViCzU2dSgsoL zWtP2LZbfqHA5q/IK7HITltJ/xSYrALUIf9WVNjVc6v3RG203o8blFKq408bLygzSg+pZVFvH9s Gto2KhKGgMb4sjg== X-Received: by 2002:adf:fc0a:: with SMTP id i10mr11871796wrr.105.1574349206164; Thu, 21 Nov 2019 07:13:26 -0800 (PST) X-Google-Smtp-Source: APXvYqxhANnMF7XSTPSlwqr514RBxX4wKc5o0XO3YXadwV5MKSOwADLstkrfwF/+Eg7YDaho1b1RWQ== X-Received: by 2002:adf:fc0a:: with SMTP id i10mr11871763wrr.105.1574349205935; Thu, 21 Nov 2019 07:13:25 -0800 (PST) Return-Path: Received: from [192.168.1.35] (131.red-88-21-102.staticip.rima-tde.net. [88.21.102.131]) by smtp.gmail.com with ESMTPSA id w12sm3239924wmi.17.2019.11.21.07.13.24 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 21 Nov 2019 07:13:25 -0800 (PST) Subject: Re: [edk2-devel] [PATCH v1 17/19] ArmPlatformPkg: Fix UART divisor warning To: devel@edk2.groups.io, sami.mujawar@arm.com Cc: Alexei.Fedorov@arm.com, ard.biesheuvel@linaro.org, leif.lindholm@linaro.org, Matteo.Carlini@arm.com, nd@arm.com References: <20190823105539.13260-1-sami.mujawar@arm.com> <20190823105539.13260-18-sami.mujawar@arm.com> From: =?UTF-8?B?UGhpbGlwcGUgTWF0aGlldS1EYXVkw6k=?= Message-ID: <33184467-3b90-518f-4cbd-5c4ae438b893@redhat.com> Date: Thu, 21 Nov 2019 16:13:23 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.1.1 MIME-Version: 1.0 In-Reply-To: <20190823105539.13260-18-sami.mujawar@arm.com> X-MC-Unique: Ig0jwpM9MVOzF3TM-SoNYQ-1 X-Mimecast-Spam-Score: 0 Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: quoted-printable On 8/23/19 12:55 PM, Sami Mujawar wrote: > The VS2017 compiler reports 'warning C4244: '=3D': conversion > from 'UINT64' to 'UINT32', possible loss of data' for the > calculation of the UART Divisor value. >=20 > Fix this warning by adding appropriate typecast and a validation > that ensures that the UART divisor value generated does not exceed > MAX_UINT32. >=20 > Signed-off-by: Sami Mujawar > --- > ArmPlatformPkg/Library/PL011UartLib/PL011UartLib.c | 10 ++++++++-- > 1 file changed, 8 insertions(+), 2 deletions(-) >=20 > diff --git a/ArmPlatformPkg/Library/PL011UartLib/PL011UartLib.c b/ArmPlat= formPkg/Library/PL011UartLib/PL011UartLib.c > index 801990d9551a638c17d560d4226137b8a3ee47bb..2d3c279cce49304959953ec4a= 34b50e09a7d0045 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/destruc= tor > =20 > 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.
> =20 > SPDX-License-Identifier: BSD-2-Clause-Patent > =20 > @@ -78,6 +78,7 @@ PL011UartInitializePort ( > UINT32 Integer; > UINT32 Fractional; > UINT32 HardwareFifoDepth; > + UINT64 DivisorValue; > =20 > HardwareFifoDepth =3D (PL011_UARTPID2_VER (MmioRead32 (UartBase + UAR= TPID2)) \ > > PL011_VER_R1P4) \ > @@ -188,7 +189,12 @@ PL011UartInitializePort ( > return RETURN_INVALID_PARAMETER; > } > =20 > - 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; > } >=20 Reviewed-by: Philippe Mathieu-Daude