Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp5648468imm; Tue, 12 Jun 2018 10:59:13 -0700 (PDT) X-Google-Smtp-Source: ADUXVKKhiJ8fmcOl4f3K0jcN77iUB/rehsVJZyzuSrGZ5paZFfb9jZtYMIPMofIwU2jS00Klqi67 X-Received: by 2002:a63:6dc3:: with SMTP id i186-v6mr1239228pgc.316.1528826353663; Tue, 12 Jun 2018 10:59:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528826353; cv=none; d=google.com; s=arc-20160816; b=y9JAIlkTkvO1X9VENQYeDRG+e3W3rC6OylNqSa6811FlHaLYnoYgKySihjju/svwPZ sW/2w98CSL94EQRT9cNmpZf+ykDLRtQ4g7KsZ3mPWc6yJmx1zUTsUFKBN7n4Gd4QnVu+ zvFxHhbxzYZ4lCOEQWjkBeEBb6W8yOjBPyNmcaSa7O7TRsMm4UM+ulSGssmUjqygY+NO tXo+vSYTX/kXcglYwLlJ2Si3fc9zt3vXF4R2/C7MyNPRvDihfYOjZDtMpMGP5EWZ/YeR ow/iLsN8+IjN6BPComr8t360rbfnUJSlnmIXCzrSBfQXHrJ4GT7/l3SKoVaqClaqtw85 Z1Qw== 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 :user-agent:references:in-reply-to:message-id:date:cc:to:from :subject:arc-authentication-results; bh=TicTu0hcZCu7EjF4JaBNAW7hCfqjWq4KwtFC6bE4TlI=; b=dLFnA1rzhB67/9uOoGCz5YH/iqzaQbtluFkWmPYub9vOOB1ULJrJVGfUPW+3l4JNyV Va3Wt2csWLjm7JNNxPgPxHODuuvUjKonRLNI7i2ev/aVuhmCzScaFbj/MebZkwEY5rJb 3Z2P+UV1m9A16kiRnqbNTn3IprNXak4KjCEDgyc5WzHYqEz252bP5HfqgiSt4GYmle6h uPuaqXcMpjgkErqx0blsRpnd0MXYH7mFfPw5et+rQn05NvMw05v24NPn+p2diTulKNKN SfvSB3XfL9jnDVZJa8juSzN3EY5uVNsQnS/NDQl0sH9EkbrpE+uEleMYOqgu8nEBMg2e mcuA== 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 u22-v6si636494pfg.62.2018.06.12.10.58.59; Tue, 12 Jun 2018 10:59:13 -0700 (PDT) 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 S934163AbeFLR6e (ORCPT + 99 others); Tue, 12 Jun 2018 13:58:34 -0400 Received: from mga18.intel.com ([134.134.136.126]:34448 "EHLO mga18.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933378AbeFLR6c (ORCPT ); Tue, 12 Jun 2018 13:58:32 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga005.jf.intel.com ([10.7.209.41]) by orsmga106.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 12 Jun 2018 10:58:31 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.51,215,1526367600"; d="scan'208";a="232010722" Received: from tstruk-mobl1.jf.intel.com ([10.7.196.162]) by orsmga005.jf.intel.com with ESMTP; 12 Jun 2018 10:58:31 -0700 Subject: [PATCH v3 1/2] tpm: add ptr to the tpm_space struct to file_priv From: Tadeusz Struk To: jarkko.sakkinen@linux.intel.com Cc: jgg@ziepe.ca, linux-integrity@vger.kernel.org, tadeusz.struk@intel.com, linux-security-module@vger.kernel.org, linux-kernel@vger.kernel.org Date: Tue, 12 Jun 2018 10:58:31 -0700 Message-ID: <152882631171.30206.13450199833839965348.stgit@tstruk-mobl1.jf.intel.com> In-Reply-To: <152882630662.30206.8805136953394285180.stgit@tstruk-mobl1.jf.intel.com> References: <152882630662.30206.8805136953394285180.stgit@tstruk-mobl1.jf.intel.com> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add a ptr to struct tpm_space to the file_priv to have an easy access to it in the async job without the need to allocate memory. This also allows to consolidate of the write operations for the two interfaces. Signed-off-by: Tadeusz Struk --- drivers/char/tpm/tpm-dev-common.c | 8 +++++--- drivers/char/tpm/tpm-dev.c | 10 ++-------- drivers/char/tpm/tpm-dev.h | 5 +++-- drivers/char/tpm/tpmrm-dev.c | 14 ++------------ 4 files changed, 12 insertions(+), 25 deletions(-) diff --git a/drivers/char/tpm/tpm-dev-common.c b/drivers/char/tpm/tpm-dev-common.c index e4a04b2d3c32..f0c033b69b62 100644 --- a/drivers/char/tpm/tpm-dev-common.c +++ b/drivers/char/tpm/tpm-dev-common.c @@ -43,9 +43,11 @@ static void timeout_work(struct work_struct *work) } void tpm_common_open(struct file *file, struct tpm_chip *chip, - struct file_priv *priv) + struct file_priv *priv, struct tpm_space *space) { priv->chip = chip; + priv->space = space; + mutex_init(&priv->buffer_mutex); timer_setup(&priv->user_read_timer, user_reader_timeout, 0); INIT_WORK(&priv->work, timeout_work); @@ -79,7 +81,7 @@ ssize_t tpm_common_read(struct file *file, char __user *buf, } ssize_t tpm_common_write(struct file *file, const char __user *buf, - size_t size, loff_t *off, struct tpm_space *space) + size_t size, loff_t *off) { struct file_priv *priv = file->private_data; size_t in_size = size; @@ -119,7 +121,7 @@ ssize_t tpm_common_write(struct file *file, const char __user *buf, mutex_unlock(&priv->buffer_mutex); return -EPIPE; } - out_size = tpm_transmit(priv->chip, space, priv->data_buffer, + out_size = tpm_transmit(priv->chip, priv->space, priv->data_buffer, sizeof(priv->data_buffer), 0); tpm_put_ops(priv->chip); diff --git a/drivers/char/tpm/tpm-dev.c b/drivers/char/tpm/tpm-dev.c index ebd74ab5abef..98b9630c3a36 100644 --- a/drivers/char/tpm/tpm-dev.c +++ b/drivers/char/tpm/tpm-dev.c @@ -39,7 +39,7 @@ static int tpm_open(struct inode *inode, struct file *file) if (priv == NULL) goto out; - tpm_common_open(file, chip, priv); + tpm_common_open(file, chip, priv, NULL); return 0; @@ -48,12 +48,6 @@ static int tpm_open(struct inode *inode, struct file *file) return -ENOMEM; } -static ssize_t tpm_write(struct file *file, const char __user *buf, - size_t size, loff_t *off) -{ - return tpm_common_write(file, buf, size, off, NULL); -} - /* * Called on file close */ @@ -73,6 +67,6 @@ const struct file_operations tpm_fops = { .llseek = no_llseek, .open = tpm_open, .read = tpm_common_read, - .write = tpm_write, + .write = tpm_common_write, .release = tpm_release, }; diff --git a/drivers/char/tpm/tpm-dev.h b/drivers/char/tpm/tpm-dev.h index b24cfb4d3ee1..4048677bbd78 100644 --- a/drivers/char/tpm/tpm-dev.h +++ b/drivers/char/tpm/tpm-dev.h @@ -6,6 +6,7 @@ struct file_priv { struct tpm_chip *chip; + struct tpm_space *space; /* Data passed to and from the tpm via the read/write calls */ size_t data_pending; @@ -18,11 +19,11 @@ struct file_priv { }; void tpm_common_open(struct file *file, struct tpm_chip *chip, - struct file_priv *priv); + struct file_priv *priv, struct tpm_space *space); ssize_t tpm_common_read(struct file *file, char __user *buf, size_t size, loff_t *off); ssize_t tpm_common_write(struct file *file, const char __user *buf, - size_t size, loff_t *off, struct tpm_space *space); + size_t size, loff_t *off); void tpm_common_release(struct file *file, struct file_priv *priv); #endif diff --git a/drivers/char/tpm/tpmrm-dev.c b/drivers/char/tpm/tpmrm-dev.c index 1a0e97a5da5a..96006c6b9696 100644 --- a/drivers/char/tpm/tpmrm-dev.c +++ b/drivers/char/tpm/tpmrm-dev.c @@ -28,7 +28,7 @@ static int tpmrm_open(struct inode *inode, struct file *file) return -ENOMEM; } - tpm_common_open(file, chip, &priv->priv); + tpm_common_open(file, chip, &priv->priv, &priv->space); return 0; } @@ -45,21 +45,11 @@ static int tpmrm_release(struct inode *inode, struct file *file) return 0; } -static ssize_t tpmrm_write(struct file *file, const char __user *buf, - size_t size, loff_t *off) -{ - struct file_priv *fpriv = file->private_data; - struct tpmrm_priv *priv = container_of(fpriv, struct tpmrm_priv, priv); - - return tpm_common_write(file, buf, size, off, &priv->space); -} - const struct file_operations tpmrm_fops = { .owner = THIS_MODULE, .llseek = no_llseek, .open = tpmrm_open, .read = tpm_common_read, - .write = tpmrm_write, + .write = tpm_common_write, .release = tpmrm_release, }; -