From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59416) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZyVns-0000wx-6Y for qemu-devel@nongnu.org; Mon, 16 Nov 2015 21:15:29 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZyVno-0004RL-Ns for qemu-devel@nongnu.org; Mon, 16 Nov 2015 21:15:28 -0500 Received: from e19.ny.us.ibm.com ([129.33.205.209]:43531) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZyVno-0004RH-IY for qemu-devel@nongnu.org; Mon, 16 Nov 2015 21:15:24 -0500 Received: from localhost by e19.ny.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Mon, 16 Nov 2015 21:15:23 -0500 Received: from b01cxnp23034.gho.pok.ibm.com (b01cxnp23034.gho.pok.ibm.com [9.57.198.29]) by d01dlp03.pok.ibm.com (Postfix) with ESMTP id D7688C90057 for ; Mon, 16 Nov 2015 21:03:29 -0500 (EST) Received: from d01av02.pok.ibm.com (d01av02.pok.ibm.com [9.56.224.216]) by b01cxnp23034.gho.pok.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id tAH2FJro65142844 for ; Tue, 17 Nov 2015 02:15:19 GMT Received: from d01av02.pok.ibm.com (localhost [127.0.0.1]) by d01av02.pok.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id tAH2FJ4o002775 for ; Mon, 16 Nov 2015 21:15:19 -0500 From: Stefan Berger Date: Mon, 16 Nov 2015 21:15:16 -0500 Message-Id: <1447726516-17081-1-git-send-email-stefanb@us.ibm.com> Subject: [Qemu-devel] [PATCH] tpm: adapt sysfs cancel path for new TPM driver List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org, mst@redhat.com Cc: Stefan Berger , Stefan Berger , crobinso@redhat.com Adapt the sysfs TPM command cancel path for the TPM driver that does not use a miscdevice anymore since Linux 4.0. Support old and new paths. Signed-off-by: Stefan Berger --- hw/tpm/tpm_passthrough.c | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/hw/tpm/tpm_passthrough.c b/hw/tpm/tpm_passthrough.c index 8d8523a..424d7e3 100644 --- a/hw/tpm/tpm_passthrough.c +++ b/hw/tpm/tpm_passthrough.c @@ -353,6 +353,8 @@ static int tpm_passthrough_open_sysfs_cancel(TPMBackend *tb) int fd = -1; char *dev; char path[PATH_MAX]; + const char *prefix[] = {"misc/", "tpm/"}; + int i; if (tb->cancel_path) { fd = qemu_open(tb->cancel_path, O_WRONLY); @@ -366,16 +368,21 @@ static int tpm_passthrough_open_sysfs_cancel(TPMBackend *tb) dev = strrchr(tpm_pt->tpm_dev, '/'); if (dev) { dev++; - if (snprintf(path, sizeof(path), "/sys/class/misc/%s/device/cancel", - dev) < sizeof(path)) { - fd = qemu_open(path, O_WRONLY); - if (fd >= 0) { - tb->cancel_path = g_strdup(path); - } else { - error_report("tpm_passthrough: Could not open TPM cancel " - "path %s : %s", path, strerror(errno)); + for (i = 0; i < ARRAY_SIZE(prefix); i++) { + if (snprintf(path, sizeof(path), + "/sys/class/%s%s/device/cancel", + prefix[i], dev) < sizeof(path)) { + fd = qemu_open(path, O_WRONLY); + if (fd >= 0) { + tb->cancel_path = g_strdup(path); + break; + } } } + if (fd < 0) { + error_report("tpm_passthrough: Could not open TPM cancel " + "path %s : %s", path, strerror(errno)); + } } else { error_report("tpm_passthrough: Bad TPM device path %s", tpm_pt->tpm_dev); -- 2.4.3