Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp5296347imu; Tue, 13 Nov 2018 04:29:00 -0800 (PST) X-Google-Smtp-Source: AJdET5eu6pH/eWSEmDDow5uM6L1Ovpky1clvTOl7n17sse18Wv058jz6uM01UQtZJS4lyuAfI5FI X-Received: by 2002:a17:902:6a3:: with SMTP id 32-v6mr5015364plh.337.1542112140187; Tue, 13 Nov 2018 04:29:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542112140; cv=none; d=google.com; s=arc-20160816; b=c2ss8dkawsCI5b/toSnM+uo+FJKMA3GPieTPv9rEz1ZZ2t+HaTybwfY2VCKBEU5awe AYUYNhPra1vDkJ0vBkhWPUGYTnR7lb58N3kx97I2WXtuI8Uzt4lQSYbG8kH8UsFORF5c Z23T4RU8/aCuOVGdYVquczHFfFex3fSE2xMNyqmEkgvfn+ba5ZKMZo2PTXuHdF297H4T /YstoRZACQnRKXMMTPqC/JzPDc+K1BHUTtkWME4YhymzfCMF2pma9XSeSMdcqbb9nyZJ KsT/SWHBG94dPwaozB78SrThbqz673PhAeiunMh+zA0Gt/qgTbrsIhNYcpePEfz1gsPB yvCw== 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=sEzvmabBVevqedg6fbw+MCC3eDWfjX18dULtHgKPxTk=; b=UOQfI/e6+OZwMWMATvvqdDbxGIVuVAtYiFJ52jYD60p8Zv80ZXdnezFVJQT3m5gpxn GG3d+Xc2fc9h7cHDYD+Eg93mwZKSmSt2hQ8HfAzD0hi3qrCNIPzIeAf7ADiBluAfS09j KGMM+ZHB8ly0C5Ex0dPbsUpTDQnAeFy9AD6rDXP4fGI54P/9k5X6yaHKZAwhiLxlXXkK oJkk4rNBlbFmYULJRdETT+/Xp2te4zva6DN+ejPXcjRuNONVm0xuqCLILUhA74RPDJh/ VOYDVUOOjD2yWiyysDH3KRumPq/V1MmYFWSCendt1CZZJZ3XZwMGxhNFRFym86C7TJru 3Xdw== 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 p4si3230347pga.514.2018.11.13.04.28.42; Tue, 13 Nov 2018 04:29:00 -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 S1733191AbeKMWZn (ORCPT + 99 others); Tue, 13 Nov 2018 17:25:43 -0500 Received: from mga02.intel.com ([134.134.136.20]:57923 "EHLO mga02.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732875AbeKMWZn (ORCPT ); Tue, 13 Nov 2018 17:25:43 -0500 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga101.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 13 Nov 2018 04:27:48 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.54,499,1534834800"; d="scan'208";a="108176616" Received: from ibanaga-mobl1.ger.corp.intel.com (HELO localhost) ([10.249.254.77]) by orsmga002.jf.intel.com with ESMTP; 13 Nov 2018 04:27:42 -0800 From: Jarkko Sakkinen To: linux-integrity@vger.kernel.org Cc: linux-security-module@vger.kernel.org, James Bottomley , Tomas Winkler , Tadeusz Struk , Stefan Berger , Nayna Jain , Jarkko Sakkinen , Peter Huewe , Jason Gunthorpe , Arnd Bergmann , Greg Kroah-Hartman , linux-kernel@vger.kernel.org (open list) Subject: [PATCH v6 10/17] tpm: encapsulate tpm_dev_transmit() Date: Tue, 13 Nov 2018 14:25:59 +0200 Message-Id: <20181113122609.21643-11-jarkko.sakkinen@linux.intel.com> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181113122609.21643-1-jarkko.sakkinen@linux.intel.com> References: <20181113122609.21643-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 --- 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 99b5133a9d05..cbb0ee30b511 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->data_pending = ret; @@ -78,7 +89,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; } @@ -163,8 +174,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