Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp145028imu; Thu, 8 Nov 2018 06:19:46 -0800 (PST) X-Google-Smtp-Source: AJdET5e01XCuAtChhehOkcrk7apMOgj/lfbzjZG5+eXfqjllTQcmBdZhVvlVhrFn8hT7FxfgCu8J X-Received: by 2002:a63:5722:: with SMTP id l34mr3930404pgb.118.1541686786307; Thu, 08 Nov 2018 06:19:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541686786; cv=none; d=google.com; s=arc-20160816; b=Y+wvoq8KZTmD5aR2xWnqzveUFB6p7YGlvLcOk3HJIa3ILXqKIi/re/D5SGdH5+1vzW crIFwqIWmdctC8yxYI9W3hcV8yQhMzK/L3nLEzlmRyksjmRSSyT3bd4shbbO6JZblJZJ +v2Cx6Lt2PFXbxp3/zr7tTwT2TN4IpVz1ZxNL4QvJYbBJvAFWCdoJ/NSDrc88Q1f3Ybq HtJmwcXVcnImqekw1Q5M+N1MHCpv2gBGA8g7QFsCirHqRe8hvjyO0Px+L82sPBiM6GAj y05HpmS/ohR9NmvGfjnB0asNUrxOLUzOagTVqUhaUnSdZUoFdb3PAAdmIkOth/tAfB9d 6wlg== 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=GOKuDn/TGwQ7goQgI7RavO3UljwqgtDS2/wRLpkA5Yg8TvcZCY3coLYJMrhGijHjgz QS6/7AG7v7GT0kUMaTWbEL33CCZIekzr3khrihEgqKtAJDlOJn0nUlTLcmE4hyjKOWJ5 C94E7riU49ll7pkTt9byhkK93yHchqBzaaHUOFTOhlnC6l3Y1teRlp1BuQ7UM7bWKN4w VSksDh0+hLsCGRtqygR0l48MOt3Aps2Hbb4s3D0/mavjyctH9zYVUpncGJSUUkRbgYT+ p0imhupcCNdQZDraa1jDw8eqdUvkxQqKrWtM9LO8obKo/xqrwX/dMrjtrcH6cLB98a8E uUvQ== 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 i20si329732pgm.586.2018.11.08.06.19.30; Thu, 08 Nov 2018 06:19:46 -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 S1727653AbeKHXw6 (ORCPT + 99 others); Thu, 8 Nov 2018 18:52:58 -0500 Received: from mga05.intel.com ([192.55.52.43]:25215 "EHLO mga05.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726541AbeKHXw6 (ORCPT ); Thu, 8 Nov 2018 18:52:58 -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 fmsmga105.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 08 Nov 2018 06:17:17 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.54,478,1534834800"; d="scan'208";a="106962525" Received: from ibanaga-mobl1.ger.corp.intel.com (HELO localhost) ([10.249.254.75]) by orsmga002.jf.intel.com with ESMTP; 08 Nov 2018 06:17:10 -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 v5 10/17] tpm: encapsulate tpm_dev_transmit() Date: Thu, 8 Nov 2018 16:15:31 +0200 Message-Id: <20181108141541.12832-11-jarkko.sakkinen@linux.intel.com> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181108141541.12832-1-jarkko.sakkinen@linux.intel.com> References: <20181108141541.12832-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