linux/drivers/char/tpm/tpmrm-dev.c
Tadeusz Struk c3d477a725 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>
2018-10-05 13:47:33 +03:00

56 lines
1.1 KiB
C

/*
* Copyright (C) 2017 James.Bottomley@HansenPartnership.com
*
* GPLv2
*/
#include <linux/slab.h>
#include "tpm-dev.h"
struct tpmrm_priv {
struct file_priv priv;
struct tpm_space space;
};
static int tpmrm_open(struct inode *inode, struct file *file)
{
struct tpm_chip *chip;
struct tpmrm_priv *priv;
int rc;
chip = container_of(inode->i_cdev, struct tpm_chip, cdevs);
priv = kzalloc(sizeof(*priv), GFP_KERNEL);
if (priv == NULL)
return -ENOMEM;
rc = tpm2_init_space(&priv->space);
if (rc) {
kfree(priv);
return -ENOMEM;
}
tpm_common_open(file, chip, &priv->priv, &priv->space);
return 0;
}
static int tpmrm_release(struct inode *inode, struct file *file)
{
struct file_priv *fpriv = file->private_data;
struct tpmrm_priv *priv = container_of(fpriv, struct tpmrm_priv, priv);
tpm_common_release(file, fpriv);
tpm2_del_space(fpriv->chip, &priv->space);
kfree(priv);
return 0;
}
const struct file_operations tpmrm_fops = {
.owner = THIS_MODULE,
.llseek = no_llseek,
.open = tpmrm_open,
.read = tpm_common_read,
.write = tpm_common_write,
.release = tpmrm_release,
};