From nobody Mon Feb 9 01:19:49 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 151001659682464.21121510312776; Mon, 6 Nov 2017 17:03:16 -0800 (PST) Received: from localhost ([::1]:50897 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eBsIB-000887-Rx for importer@patchew.org; Mon, 06 Nov 2017 20:03:03 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55433) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eBsEU-0005JO-Kc for qemu-devel@nongnu.org; Mon, 06 Nov 2017 19:59:15 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eBsER-0003mj-FL for qemu-devel@nongnu.org; Mon, 06 Nov 2017 19:59:14 -0500 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:40986 helo=mx0a-001b2d01.pphosted.com) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eBsER-0003mM-AH for qemu-devel@nongnu.org; Mon, 06 Nov 2017 19:59:11 -0500 Received: from pps.filterd (m0098419.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.21/8.16.0.21) with SMTP id vA70sGBD065383 for ; Mon, 6 Nov 2017 19:59:07 -0500 Received: from e17.ny.us.ibm.com (e17.ny.us.ibm.com [129.33.205.207]) by mx0b-001b2d01.pphosted.com with ESMTP id 2e31y4t6vg-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Mon, 06 Nov 2017 19:59:07 -0500 Received: from localhost by e17.ny.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Mon, 6 Nov 2017 19:59:06 -0500 Received: from b01cxnp22034.gho.pok.ibm.com (9.57.198.24) by e17.ny.us.ibm.com (146.89.104.204) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Mon, 6 Nov 2017 19:59:03 -0500 Received: from b01ledav006.gho.pok.ibm.com (b01ledav006.gho.pok.ibm.com [9.57.199.111]) by b01cxnp22034.gho.pok.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id vA70x2Rw51380332; Tue, 7 Nov 2017 00:59:03 GMT Received: from b01ledav006.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 3F450AC04A; Mon, 6 Nov 2017 19:59:52 -0500 (EST) Received: from sbct-3.watson.ibm.com (unknown [9.47.158.153]) by b01ledav006.gho.pok.ibm.com (Postfix) with ESMTP id 3CEB1AC040; Mon, 6 Nov 2017 19:59:52 -0500 (EST) From: Stefan Berger To: qemu-devel@nongnu.org, marcandre.lureau@redhat.com Date: Mon, 6 Nov 2017 19:58:53 -0500 X-Mailer: git-send-email 2.5.5 In-Reply-To: <1510016336-4086-1-git-send-email-stefanb@linux.vnet.ibm.com> References: <1510016336-4086-1-git-send-email-stefanb@linux.vnet.ibm.com> X-TM-AS-GCONF: 00 x-cbid: 17110700-0040-0000-0000-000003BE6036 X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00008022; HX=3.00000241; KW=3.00000007; PH=3.00000004; SC=3.00000239; SDB=6.00942183; UDB=6.00475248; IPR=6.00722471; BA=6.00005674; NDR=6.00000001; ZLA=6.00000005; ZF=6.00000009; ZB=6.00000000; ZP=6.00000000; ZH=6.00000000; ZU=6.00000002; MB=3.00017888; XFM=3.00000015; UTC=2017-11-07 00:59:04 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17110700-0041-0000-0000-000007B37866 Message-Id: <1510016336-4086-3-git-send-email-stefanb@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-11-06_08:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=0 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 impostorscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1707230000 definitions=main-1711070011 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] [fuzzy] X-Received-From: 148.163.158.5 Subject: [Qemu-devel] [PATCH 2/5] tpm: pull tpm_util_send() out of tpm_util_test() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: amarnath.valluri@intel.com, Stefan Berger Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Stefan Berger Reviewed-by: Marc-Andr=C3=A9 Lureau --- hw/tpm/tpm_util.c | 33 ++++++++++++++++++++++++++------- 1 file changed, 26 insertions(+), 7 deletions(-) diff --git a/hw/tpm/tpm_util.c b/hw/tpm/tpm_util.c index daf1faa..396e793 100644 --- a/hw/tpm/tpm_util.c +++ b/hw/tpm/tpm_util.c @@ -53,10 +53,11 @@ bool tpm_util_is_selftest(const uint8_t *in, uint32_t i= n_len) * A basic test of a TPM device. We expect a well formatted response header * (error response is fine) within one second. */ -static int tpm_util_test(int fd, - unsigned char *request, - size_t requestlen, - uint16_t *return_tag) +static int tpm_util_tx(int fd, + unsigned char *request, + size_t requestlen, + unsigned char *response, + size_t responselen) { struct tpm_resp_hdr *resp; fd_set readfds; @@ -65,7 +66,6 @@ static int tpm_util_test(int fd, .tv_sec =3D 1, .tv_usec =3D 0, }; - unsigned char buf[1024]; =20 n =3D write(fd, request, requestlen); if (n < 0) { @@ -84,17 +84,36 @@ static int tpm_util_test(int fd, return -errno; } =20 - n =3D read(fd, &buf, sizeof(buf)); + n =3D read(fd, response, responselen); if (n < sizeof(struct tpm_resp_hdr)) { return -EFAULT; } =20 - resp =3D (struct tpm_resp_hdr *)buf; + resp =3D (struct tpm_resp_hdr *)response; /* check the header */ if (be32_to_cpu(resp->len) !=3D n) { return -EMSGSIZE; } =20 + return 0; +} + +static int tpm_util_test(int fd, + unsigned char *request, + size_t requestlen, + uint16_t *return_tag) +{ + struct tpm_resp_hdr *resp; + unsigned char buf[1024]; + ssize_t ret; + + ret =3D tpm_util_tx(fd, request, requestlen, + buf, sizeof(buf)); + if (ret < 0) { + return ret; + } + + resp =3D (struct tpm_resp_hdr *)buf; *return_tag =3D be16_to_cpu(resp->tag); =20 return 0; --=20 2.5.5