From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from userp2120.oracle.com (userp2120.oracle.com [156.151.31.85]) by mx.groups.io with SMTP id smtpd.web10.6668.1585652538297968163 for ; Tue, 31 Mar 2020 04:02:18 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@oracle.com header.s=corp-2020-01-29 header.b=Jx5CNpzb; spf=pass (domain: oracle.com, ip: 156.151.31.85, mailfrom: liran.alon@oracle.com) Received: from pps.filterd (userp2120.oracle.com [127.0.0.1]) by userp2120.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 02VAwsie189619; Tue, 31 Mar 2020 11:02:18 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : mime-version : content-transfer-encoding; s=corp-2020-01-29; bh=DdPYYRMG4HwTIcptVZtuIhZAA05gZHHR9qtuw1FSP+M=; b=Jx5CNpzbHMtWiVs8rAEtusjF0JGvjRjqhgCTwKd+68jB8jwLSiEC1U3E0N20dF4uv9cX HeWD+1WxVlUy8ibQLxfVMWdPGP4cZ+ON3XXXvQSKvsbqaN6PlKPCrOJyba09xPXFNg4x b6+E2stBYxmgcSx+xD7aENRj4IIFNJ8Mmhgto6yfatdCCem7z4k20eQPvkjVz6Up/NHA gChkpOb8lWY0BqrBKYweAQEiVsHAKe5uSm7h7TtxI9R9y0KHTh8FIvH+f4xZTbnZY5fX YJGmIP7TqtQr1nxC/O8XWzcAL5LGi+M5Hnx6stMCWytb2bBdaKi7z93hu3B3PpIjL5DN ZQ== Received: from userp3020.oracle.com (userp3020.oracle.com [156.151.31.79]) by userp2120.oracle.com with ESMTP id 303aqhfctv-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 31 Mar 2020 11:02:17 +0000 Received: from pps.filterd (userp3020.oracle.com [127.0.0.1]) by userp3020.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 02VB2H1l092418; Tue, 31 Mar 2020 11:02:17 GMT Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by userp3020.oracle.com with ESMTP id 302g9x2bs4-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 31 Mar 2020 11:02:17 +0000 Received: from abhmp0009.oracle.com (abhmp0009.oracle.com [141.146.116.15]) by aserv0122.oracle.com (8.14.4/8.14.4) with ESMTP id 02VB2Grd026182; Tue, 31 Mar 2020 11:02:16 GMT Received: from spark.ravello.local (/213.57.127.2) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Tue, 31 Mar 2020 04:02:15 -0700 From: "Liran Alon" To: devel@edk2.groups.io, lersek@redhat.com Cc: sean.brogan@microsoft.com, nikita.leshchenko@oracle.com, aaron.young@oracle.com, jordan.l.justen@intel.com, ard.biesheuvel@linaro.org, Liran Alon Subject: [PATCH] OvmfPkg/PvScsiDxe: Fix VS2019 build error because of implicit cast Date: Tue, 31 Mar 2020 14:04:52 +0300 Message-Id: <20200331110452.51992-1-liran.alon@oracle.com> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9576 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 malwarescore=0 mlxlogscore=999 bulkscore=0 mlxscore=0 spamscore=0 adultscore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2003020000 definitions=main-2003310100 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9576 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 bulkscore=0 phishscore=0 clxscore=1011 malwarescore=0 impostorscore=0 mlxlogscore=999 spamscore=0 mlxscore=0 priorityscore=1501 lowpriorityscore=0 adultscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2003020000 definitions=main-2003310099 Content-Transfer-Encoding: 8bit Sean reported that VS2019 build produce the following build error: INFO - PvScsi.c INFO - Generating code INFO - d:\a\1\s\OvmfPkg\PvScsiDxe\PvScsi.c(459): error C2220: the following warning is treated as an error INFO - d:\a\1\s\OvmfPkg\PvScsiDxe\PvScsi.c(459): warning C4244: '=': conversion from 'const UINT16' to 'UINT8', possible loss of data This result from an implicit cast from PVSCSI Response->ScsiStatus (Which is UINT16) to Packet->TargetResponse (Which is UINT8). Fix this issue by adding an appropriate explicit cast and verify with assert that this truncation do not result in loss of data. Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=2651 Reported-by: Sean Brogan Signed-off-by: Liran Alon --- OvmfPkg/PvScsiDxe/PvScsi.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/OvmfPkg/PvScsiDxe/PvScsi.c b/OvmfPkg/PvScsiDxe/PvScsi.c index 0a66c98421a9..1ca50390c0e5 100644 --- a/OvmfPkg/PvScsiDxe/PvScsi.c +++ b/OvmfPkg/PvScsiDxe/PvScsi.c @@ -455,8 +455,12 @@ HandleResponse ( // // Report target status + // (Strangely, PVSCSI interface defines Response->ScsiStatus as UINT16. + // But it should de-facto always have a value that fits UINT8. To avoid + // unexpected behavior, verify value is in UINT8 bounds before casting) // - Packet->TargetStatus = Response->ScsiStatus; + ASSERT (Response->ScsiStatus <= MAX_UINT8); + Packet->TargetStatus = (UINT8)Response->ScsiStatus; // // Host adapter status and function return value depend on -- 2.20.1