Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp1577381imu; Sun, 18 Nov 2018 04:51:41 -0800 (PST) X-Google-Smtp-Source: AJdET5eQjeC6KYoSncd3stJW4q4JILC83+tOOvn6kADxzt4pGcyVLHTZE0DsxsAH9usPjH7D3YPh X-Received: by 2002:a62:509b:: with SMTP id g27mr18939803pfj.48.1542545501070; Sun, 18 Nov 2018 04:51:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542545501; cv=none; d=google.com; s=arc-20160816; b=FM7hZtaVFxqWRb/Fki178EHy0vEBGrsb1xpJWrM7LwhGikjUYahwIKmWBFqrKgYOYz T0SeUdf69xQe9xcF0/Yj3qmk0eL+gcHGjQyxq8LY0ncl3xHdbNV02lzXnCdAhHziq/ZD LWGsGNFneoMqHQPjf8J+IHNagnzUJImwS+b5Sd0zE/pSoub/7G7NozOoTpqGZMI/ILFO 5RzxVK0yX8sVlb/cDXLG+d7SUqYK3vy2GEpnfcFwMv4dBrKOFRq4U56d9pRK3CtGxeyp lQiGaSWurpSp/RMeTL6enjro8ZiJIipZr/C0pnMwGwxFXuHbcFe5VuYN6f1acXpnJ0qK sWFA== 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=NwHkTwWqUWBvrNZpxfZc0Qa+3kGSt1B5wv0N3E+gboYWHY9VedXJjGpNsXG6qTlhwr NG8gYUgwPdif/EOuyKPHXY6BJBiTzdcgH87VM1pliGnv8sQIgobKJEep3W5/a1R3PoPr i+dUoQJwxmrib04xPuPWJYHeecPZUb/p6RPZekvk72uQV3SGOfjTa79B/zrSobuaMip7 QDY8U3wg1rpSRnWgyvokG4SeeSLfpPxZrgPvot6r2C8LGDDSXfYRZ4caKjcYFScYXFKv bUGKegwrhxCGlanGi7NTLssVe4PiVGP5o3I1qnHibH0IGUxw09kZnSAFrFrBXuwFlCZE UBsA== 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 m15si8539339pgc.381.2018.11.18.04.51.26; Sun, 18 Nov 2018 04:51:41 -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 S1727576AbeKRXJU (ORCPT + 99 others); Sun, 18 Nov 2018 18:09:20 -0500 Received: from mga18.intel.com ([134.134.136.126]:48231 "EHLO mga18.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726269AbeKRXJU (ORCPT ); Sun, 18 Nov 2018 18:09:20 -0500 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by orsmga106.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 18 Nov 2018 04:49:05 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.56,248,1539673200"; d="scan'208";a="107258560" Received: from tmuluk-mobl4.ger.corp.intel.com (HELO localhost) ([10.249.254.142]) by fmsmga004.fm.intel.com with ESMTP; 18 Nov 2018 04:48:58 -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 v9 07/17] tpm: encapsulate tpm_dev_transmit() Date: Sun, 18 Nov 2018 14:47:40 +0200 Message-Id: <20181118124753.18613-8-jarkko.sakkinen@linux.intel.com> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181118124753.18613-1-jarkko.sakkinen@linux.intel.com> References: <20181118124753.18613-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