From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mx.groups.io with SMTP id smtpd.web10.11554.1675434223273493871 for ; Fri, 03 Feb 2023 06:23:43 -0800 Authentication-Results: mx.groups.io; dkim=missing; spf=pass (domain: arm.com, ip: 217.140.110.172, mailfrom: sudeep.holla@arm.com) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 5C1D84B3; Fri, 3 Feb 2023 06:24:24 -0800 (PST) Received: from usa.arm.com (e103737-lin.cambridge.arm.com [10.1.197.49]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id E99293F71E; Fri, 3 Feb 2023 06:23:40 -0800 (PST) From: "Sudeep Holla" To: devel@edk2.groups.io Cc: Sudeep Holla , Leif Lindholm , Ard Biesheuvel , Pierre Gondois , Girish Pathak , Jeff Brasen , Pierre Gondois , Sami Mujawar Subject: [PATCH v2] ArmPkg/ArmScmiDxe: Fix the calculation of RequiredArraySize in ClockDescribeRates() Date: Fri, 3 Feb 2023 14:23:38 +0000 Message-Id: <20230203142338.3403641-1-sudeep.holla@arm.com> X-Mailer: git-send-email 2.39.1 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable As per the SCMI specification, section CLOCK_DESCRIBE_RATES mentions that the value of num_rates_flags[11:0] in the response must be 3 if the return format is the triplet. Due to the buggy firmware, this was not noticed for long time. The firmware is now fixed resulting in ClockDescribeRates() to fail with "Buffer Too Small" error as the RequiredArraySize gets miscalculated as 72 instead of 24. Fix the issue by reusing the logic for both the return format which must work if num_rates_flags has correct value as expected from the specification. Cc: Pierre Gondois Cc: Girish Pathak Cc: Jeff Brasen Reviewed-by: Pierre Gondois Tested-by: Pierre Gondois Reported-by: Sami Mujawar Signed-off-by: Sudeep Holla --- ArmPkg/Drivers/ArmScmiDxe/ScmiClockProtocol.c | 35 ++++++++----------- 1 file changed, 14 insertions(+), 21 deletions(-) v1->v2: - Removed the unnecessary and incorrect loop to populate the clock rate triplets(as suggested by Pierre) Note the real delta is just 7 lines deletion when viewed with ignored spacechanges. diff --git a/ArmPkg/Drivers/ArmScmiDxe/ScmiClockProtocol.c b/ArmPkg/Drivers= /ArmScmiDxe/ScmiClockProtocol.c index 12a7e6df5d43..f092208a6601 100644 --- a/ArmPkg/Drivers/ArmScmiDxe/ScmiClockProtocol.c +++ b/ArmPkg/Drivers/ArmScmiDxe/ScmiClockProtocol.c @@ -236,12 +236,7 @@ ClockDescribeRates ( *TotalRates =3D NUM_RATES (DescribeRates->NumRatesFlags)=0D + NUM_REMAIN_RATES (DescribeRates->NumRatesFlags);=0D =0D - if (*Format =3D=3D ScmiClockRateFormatDiscrete) {=0D - RequiredArraySize =3D (*TotalRates) * sizeof (UINT64);=0D - } else {=0D - // We need to return triplet of 64 bit value for each rate=0D - RequiredArraySize =3D (*TotalRates) * 3 * sizeof (UINT64);=0D - }=0D + RequiredArraySize =3D (*TotalRates) * sizeof (UINT64);=0D =0D if (RequiredArraySize > (*RateArraySize)) {=0D *RateArraySize =3D RequiredArraySize;=0D @@ -259,23 +254,21 @@ ClockDescribeRates ( ConvertTo64Bit (Rate->Low, Rate->High);=0D }=0D } else {=0D - for (RateNo =3D 0; RateNo < NUM_RATES (DescribeRates->NumRatesFlags)= ; RateNo++) {=0D - // Linear clock rates from minimum to maximum in steps=0D - // Minimum clock rate.=0D - Rate =3D &DescribeRates->Rates[= RateOffset++];=0D - RateArray[RateIndex].ContinuousRate.Min =3D=0D - ConvertTo64Bit (Rate->Low, Rate->High);=0D + // Linear clock rates from minimum to maximum in steps=0D + // Minimum clock rate.=0D + Rate =3D &DescribeRates->Rates[Ra= teOffset++];=0D + RateArray[RateIndex].ContinuousRate.Min =3D=0D + ConvertTo64Bit (Rate->Low, Rate->High);=0D =0D - Rate =3D &DescribeRates->Rates[RateOffset++];=0D - // Maximum clock rate.=0D - RateArray[RateIndex].ContinuousRate.Max =3D=0D - ConvertTo64Bit (Rate->Low, Rate->High);=0D + Rate =3D &DescribeRates->Rates[RateOffset++];=0D + // Maximum clock rate.=0D + RateArray[RateIndex].ContinuousRate.Max =3D=0D + ConvertTo64Bit (Rate->Low, Rate->High);=0D =0D - Rate =3D &DescribeRates->Rates[RateOffset++];=0D - // Step.=0D - RateArray[RateIndex++].ContinuousRate.Step =3D=0D - ConvertTo64Bit (Rate->Low, Rate->High);=0D - }=0D + Rate =3D &DescribeRates->Rates[RateOffset++];=0D + // Step.=0D + RateArray[RateIndex++].ContinuousRate.Step =3D=0D + ConvertTo64Bit (Rate->Low, Rate->High);=0D }=0D } while (NUM_REMAIN_RATES (DescribeRates->NumRatesFlags) !=3D 0);=0D =0D --=20 2.39.1