Received: by 2002:ac0:8c9a:0:0:0:0:0 with SMTP id r26csp5600273ima; Tue, 5 Feb 2019 14:49:14 -0800 (PST) X-Google-Smtp-Source: AHgI3IZb9E0U+lGSkak8d/Zcr+oN4aLgXrWcNYl1MRQ055tahkFmAvZHl760d9AoIQuwAmrA8CdV X-Received: by 2002:a62:62c5:: with SMTP id w188mr7453060pfb.160.1549406954528; Tue, 05 Feb 2019 14:49:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1549406954; cv=none; d=google.com; s=arc-20160816; b=KM8pzZIxynrypCqpqZ/h+aALfqPX7hQesKRIzu0d/j0wwf3EE6eIBO8CiOyMn4QwPl zTlByyVdHDDK40vQ7R7PSSfzsMmmHuehKljCa/emqj40Jog5u70EZ7noHt11pkXl/7L7 YdrHrPGreLEc4f30t2nDoWUcR+Q7YMzy4UZkA6ODLBKMqaOn01r3OuHaVIMsvV6jAQaw mjguYuYVwv15vveOwInZIu6WACqJ9elTuuqmxFoPVl3UHL56obBLMrKNAPLpnhUb2eLh eWGWlinpZRWxp1Nlk3MTikzuAfRpHa395OmpWPbsZ5/DNYPfwbAQTXBc8jC2YIxilm6u OgVw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=XDNDNk1Zpym0ErO/vXk0632ho2QDJtaOGAfrwbe2cLk=; b=B6M8zLgg9b0zKKuOnUCjle7FEXVWnOFHxIy3MvXhtWjTOawGQFLCNhOmua8Ya5A3YB 5fGRrYMVfTxtjjMmh2ZqrXpxxK7yXMfwyqO8wJmf6ST670SUYWSl3m/RO5R+EBH3swYV yKpWLghphYAYbEKic3sGJbEXxJ2845L2xz01rZSyDKPBrjGUrvDCR8XuSRVBdWbDIhM9 EZP5lB76mc4QrQVMWTVtN2/vDU/XQ5BcndK6+t99lvGYnCQpwUXWqncucdgHtzft7A8x CGsua27XFggucFpiyIq8D9UYQtL90FSAxMJEHPtscPwLjDMENkUbh7/H2v0oc7DnoPeL EzxA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v35si4232518pgl.130.2019.02.05.14.48.59; Tue, 05 Feb 2019 14:49:14 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730803AbfBEWs0 (ORCPT + 99 others); Tue, 5 Feb 2019 17:48:26 -0500 Received: from mga06.intel.com ([134.134.136.31]:62932 "EHLO mga06.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729902AbfBEWsW (ORCPT ); Tue, 5 Feb 2019 17:48:22 -0500 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga006.jf.intel.com ([10.7.209.51]) by orsmga104.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 05 Feb 2019 14:48:22 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.58,337,1544515200"; d="scan'208";a="113982181" Received: from ibanaga-mobl1.ger.corp.intel.com (HELO localhost) ([10.249.254.171]) by orsmga006.jf.intel.com with ESMTP; 05 Feb 2019 14:48:17 -0800 From: Jarkko Sakkinen To: linux-integrity@vger.kernel.org Cc: linux-kernel@vger.kernel.org, linux-security-module@vger.kernel.org, Peter Huewe , Jason Gunthorpe , Tomas Winkler , Tadeusz Struk , Stefan Berger , Nayna Jain , Jarkko Sakkinen Subject: [PATCH v11 07/16] tpm: encapsulate tpm_dev_transmit() Date: Wed, 6 Feb 2019 00:47:14 +0200 Message-Id: <20190205224723.19671-8-jarkko.sakkinen@linux.intel.com> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20190205224723.19671-1-jarkko.sakkinen@linux.intel.com> References: <20190205224723.19671-1-jarkko.sakkinen@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Encapsulate tpm_transmit() call pattern to tpm_dev_transmit() because it is identically used from two places. Use unlocked version of tpm_transmit() so that we are able to move the calls to tpm2_prepare_space() and tpm2_commit_space() later on to this new function. Signed-off-by: Jarkko Sakkinen Reviewed-by: Stefan Berger Tested-by: Stefan Berger Reviewed-by: Jerry Snitselaar Reviewed-by: James Bottomley --- drivers/char/tpm/tpm-dev-common.c | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/drivers/char/tpm/tpm-dev-common.c b/drivers/char/tpm/tpm-dev-common.c index 5eecad233ea1..759796953d84 100644 --- a/drivers/char/tpm/tpm-dev-common.c +++ b/drivers/char/tpm/tpm-dev-common.c @@ -27,7 +27,19 @@ static struct workqueue_struct *tpm_dev_wq; static DEFINE_MUTEX(tpm_dev_wq_lock); -static void tpm_async_work(struct work_struct *work) +static ssize_t tpm_dev_transmit(struct tpm_chip *chip, struct tpm_space *space, + u8 *buf, size_t bufsiz) +{ + ssize_t ret; + + mutex_lock(&chip->tpm_mutex); + ret = tpm_transmit(chip, space, buf, bufsiz, TPM_TRANSMIT_UNLOCKED); + mutex_unlock(&chip->tpm_mutex); + + return ret; +} + +static void tpm_dev_async_work(struct work_struct *work) { struct file_priv *priv = container_of(work, struct file_priv, async_work); @@ -35,9 +47,8 @@ static void tpm_async_work(struct work_struct *work) mutex_lock(&priv->buffer_mutex); priv->command_enqueued = false; - ret = tpm_transmit(priv->chip, priv->space, priv->data_buffer, - sizeof(priv->data_buffer), 0); - + ret = tpm_dev_transmit(priv->chip, priv->space, priv->data_buffer, + sizeof(priv->data_buffer)); tpm_put_ops(priv->chip); if (ret > 0) { priv->response_length = ret; @@ -80,7 +91,7 @@ void tpm_common_open(struct file *file, struct tpm_chip *chip, mutex_init(&priv->buffer_mutex); timer_setup(&priv->user_read_timer, user_reader_timeout, 0); INIT_WORK(&priv->timeout_work, tpm_timeout_work); - INIT_WORK(&priv->async_work, tpm_async_work); + INIT_WORK(&priv->async_work, tpm_dev_async_work); init_waitqueue_head(&priv->async_wait); file->private_data = priv; } @@ -183,8 +194,8 @@ ssize_t tpm_common_write(struct file *file, const char __user *buf, return size; } - ret = tpm_transmit(priv->chip, priv->space, priv->data_buffer, - sizeof(priv->data_buffer), 0); + ret = tpm_dev_transmit(priv->chip, priv->space, priv->data_buffer, + sizeof(priv->data_buffer)); tpm_put_ops(priv->chip); if (ret > 0) { -- 2.19.1