From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wr1-f66.google.com (mail-wr1-f66.google.com [209.85.221.66]) by mx.groups.io with SMTP id smtpd.web09.23194.1574339732264191247 for ; Thu, 21 Nov 2019 04:35:32 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@linaro.org header.s=google header.b=to3GrAe3; spf=pass (domain: linaro.org, ip: 209.85.221.66, mailfrom: leif.lindholm@linaro.org) Received: by mail-wr1-f66.google.com with SMTP id s5so4239052wrw.2 for ; Thu, 21 Nov 2019 04:35:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=P+SQ4AF2noL6MAT5RW4KUigqkCndMZ9zghhnBMDxgwA=; b=to3GrAe3UElb2jy52BTBJq/1a61dz/CldqOTYRye+UW5bhNDVSWUVf4jTpOfH1M0id XxBOfkFQSwdVeSMLPV4IzYZQkiE/PdSuqohUF5JGwIGybwPHcIZvHB6AkiOUBdeblQ3Y iwysCVnFYl2wzHSgtU2bgaJGECOL5mD8NbRYF9E2biy4TYf7Ny6BEPvNduYrAo7lyakh bACzQ/Yu4OMyOgRCh4naTaRmzzC2FSjV4M7lro5CLYyIgcNd9cuqwOs/WfizO3lQlgot QdwMu2I4GQ35KvXp75ruqgEi+XNHzAm8JAm5kY8J1/itEpzYB9PdaepF7XRY9RvEdqaa DJVg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=P+SQ4AF2noL6MAT5RW4KUigqkCndMZ9zghhnBMDxgwA=; b=IBZhJlU+QOTklxRn/48L44Kw/UVZOh9f4U+aZqXoim8G/YuU4Z0COqQju0V7LS2ZJv 5PDO4tOAcKdY2F82TpWJdqwf/5g32ACwVMX/RjDRK3ggrx65/ViKZBDcbhgQG5S01sfx 7OwvVv2b7DRMx1Jgw5R8poiXrwtjYc1LQyb16Vu2b68KhqLpPcnPWjFbBn8oUyGMH1ht ZA4KT4dOSbwWkSeUB6s4xCQSn4mguhl+2esFQql1JpKMbJRlVAGPVKLx3q9Lqv9U2El7 7BQlnFgUn8AtUoub1zpDAVT6JExNlyPw0Xe8g8ApRqmw6BH4GabCoYes5fjCpP7iEqqN WdNA== X-Gm-Message-State: APjAAAU6D+8sa3YJT41WWGM5Ime7iY3RNCc7PuynsYRMmj+dQrfvBAWg NvxivHdp2RCHPxDDIlXpC+Qt0Q== X-Google-Smtp-Source: APXvYqwF52dM7r8e4iaD6u3QLtWzXGvQnezfr4rk7YFXVo+YwyIolHP3Zpq4Ae/XoPB7UDmDMD0nHA== X-Received: by 2002:a5d:6192:: with SMTP id j18mr10700193wru.239.1574339730558; Thu, 21 Nov 2019 04:35:30 -0800 (PST) Return-Path: Received: from bivouac.eciton.net (bivouac.eciton.net. [2a00:1098:0:86:1000:23:0:2]) by smtp.gmail.com with ESMTPSA id r2sm2793989wma.44.2019.11.21.04.35.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Nov 2019 04:35:29 -0800 (PST) Date: Thu, 21 Nov 2019 12:35:28 +0000 From: "Leif Lindholm" To: Sami Mujawar Cc: devel@edk2.groups.io, Alexei.Fedorov@arm.com, ard.biesheuvel@linaro.org, Matteo.Carlini@arm.com, nd@arm.com Subject: Re: [PATCH v1 17/19] ArmPlatformPkg: Fix UART divisor warning Message-ID: <20191121123528.GC7359@bivouac.eciton.net> References: <20190823105539.13260-1-sami.mujawar@arm.com> <20190823105539.13260-18-sami.mujawar@arm.com> MIME-Version: 1.0 In-Reply-To: <20190823105539.13260-18-sami.mujawar@arm.com> User-Agent: Mutt/1.10.1 (2018-07-13) Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Fri, Aug 23, 2019 at 11:55:37 +0100, Sami Mujawar wrote: > The VS2017 compiler reports 'warning C4244: '=': 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 Reviewed-by: Leif Lindholm Apologies for missing this set. > --- > ArmPlatformPkg/Library/PL011UartLib/PL011UartLib.c | 10 ++++++++-- > 1 file changed, 8 insertions(+), 2 deletions(-) > > diff --git a/ArmPlatformPkg/Library/PL011UartLib/PL011UartLib.c b/ArmPlatformPkg/Library/PL011UartLib/PL011UartLib.c > index 801990d9551a638c17d560d4226137b8a3ee47bb..2d3c279cce49304959953ec4a34b50e09a7d0045 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 = (PL011_UARTPID2_VER (MmioRead32 (UartBase + UARTPID2)) \ > > PL011_VER_R1P4) \ > @@ -188,7 +189,12 @@ PL011UartInitializePort ( > return RETURN_INVALID_PARAMETER; > } > > - Divisor = (UartClkInHz * 4) / *BaudRate; > + DivisorValue = (((UINT64)UartClkInHz * 4) / *BaudRate); > + if (DivisorValue > MAX_UINT32) { > + return RETURN_INVALID_PARAMETER; > + } > + > + Divisor = (UINT32)DivisorValue; > Integer = Divisor >> FRACTION_PART_SIZE_IN_BITS; > Fractional = Divisor & FRACTION_PART_MASK; > } > -- > 'Guid(CE165669-3EF3-493F-B85D-6190EE5B9759)' > >