Skip to content

Commit c3d477a

Browse files
tstrukJarkko Sakkinen
authored andcommitted
tpm: add ptr to the tpm_space struct to file_priv
Add a ptr to struct tpm_space to the file_priv and consolidate of the write operations for the two interfaces. Signed-off-by: Tadeusz Struk <tadeusz.struk@intel.com> Tested-by: Philip Tricca <philip.b.tricca@intel.com> Reviewed-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com> Signed-off--by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
1 parent 2f7d8db commit c3d477a

File tree

4 files changed

+12
-25
lines changed

4 files changed

+12
-25
lines changed

drivers/char/tpm/tpm-dev-common.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,11 @@ static void timeout_work(struct work_struct *work)
4343
}
4444

4545
void tpm_common_open(struct file *file, struct tpm_chip *chip,
46-
struct file_priv *priv)
46+
struct file_priv *priv, struct tpm_space *space)
4747
{
4848
priv->chip = chip;
49+
priv->space = space;
50+
4951
mutex_init(&priv->buffer_mutex);
5052
timer_setup(&priv->user_read_timer, user_reader_timeout, 0);
5153
INIT_WORK(&priv->work, timeout_work);
@@ -79,7 +81,7 @@ ssize_t tpm_common_read(struct file *file, char __user *buf,
7981
}
8082

8183
ssize_t tpm_common_write(struct file *file, const char __user *buf,
82-
size_t size, loff_t *off, struct tpm_space *space)
84+
size_t size, loff_t *off)
8385
{
8486
struct file_priv *priv = file->private_data;
8587
size_t in_size = size;
@@ -119,7 +121,7 @@ ssize_t tpm_common_write(struct file *file, const char __user *buf,
119121
mutex_unlock(&priv->buffer_mutex);
120122
return -EPIPE;
121123
}
122-
out_size = tpm_transmit(priv->chip, space, priv->data_buffer,
124+
out_size = tpm_transmit(priv->chip, priv->space, priv->data_buffer,
123125
sizeof(priv->data_buffer), 0);
124126

125127
tpm_put_ops(priv->chip);

drivers/char/tpm/tpm-dev.c

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ static int tpm_open(struct inode *inode, struct file *file)
3939
if (priv == NULL)
4040
goto out;
4141

42-
tpm_common_open(file, chip, priv);
42+
tpm_common_open(file, chip, priv, NULL);
4343

4444
return 0;
4545

@@ -48,12 +48,6 @@ static int tpm_open(struct inode *inode, struct file *file)
4848
return -ENOMEM;
4949
}
5050

51-
static ssize_t tpm_write(struct file *file, const char __user *buf,
52-
size_t size, loff_t *off)
53-
{
54-
return tpm_common_write(file, buf, size, off, NULL);
55-
}
56-
5751
/*
5852
* Called on file close
5953
*/
@@ -73,6 +67,6 @@ const struct file_operations tpm_fops = {
7367
.llseek = no_llseek,
7468
.open = tpm_open,
7569
.read = tpm_common_read,
76-
.write = tpm_write,
70+
.write = tpm_common_write,
7771
.release = tpm_release,
7872
};

drivers/char/tpm/tpm-dev.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
struct file_priv {
88
struct tpm_chip *chip;
9+
struct tpm_space *space;
910

1011
/* Data passed to and from the tpm via the read/write calls */
1112
size_t data_pending;
@@ -18,11 +19,11 @@ struct file_priv {
1819
};
1920

2021
void tpm_common_open(struct file *file, struct tpm_chip *chip,
21-
struct file_priv *priv);
22+
struct file_priv *priv, struct tpm_space *space);
2223
ssize_t tpm_common_read(struct file *file, char __user *buf,
2324
size_t size, loff_t *off);
2425
ssize_t tpm_common_write(struct file *file, const char __user *buf,
25-
size_t size, loff_t *off, struct tpm_space *space);
26+
size_t size, loff_t *off);
2627
void tpm_common_release(struct file *file, struct file_priv *priv);
2728

2829
#endif

drivers/char/tpm/tpmrm-dev.c

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ static int tpmrm_open(struct inode *inode, struct file *file)
2828
return -ENOMEM;
2929
}
3030

31-
tpm_common_open(file, chip, &priv->priv);
31+
tpm_common_open(file, chip, &priv->priv, &priv->space);
3232

3333
return 0;
3434
}
@@ -45,21 +45,11 @@ static int tpmrm_release(struct inode *inode, struct file *file)
4545
return 0;
4646
}
4747

48-
static ssize_t tpmrm_write(struct file *file, const char __user *buf,
49-
size_t size, loff_t *off)
50-
{
51-
struct file_priv *fpriv = file->private_data;
52-
struct tpmrm_priv *priv = container_of(fpriv, struct tpmrm_priv, priv);
53-
54-
return tpm_common_write(file, buf, size, off, &priv->space);
55-
}
56-
5748
const struct file_operations tpmrm_fops = {
5849
.owner = THIS_MODULE,
5950
.llseek = no_llseek,
6051
.open = tpmrm_open,
6152
.read = tpm_common_read,
62-
.write = tpmrm_write,
53+
.write = tpm_common_write,
6354
.release = tpmrm_release,
6455
};
65-

0 commit comments

Comments
 (0)