2019-06-04 16:11:38 +08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-only
|
2017-01-04 01:07:32 +08:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2017 James.Bottomley@HansenPartnership.com
|
|
|
|
*/
|
|
|
|
#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;
|
|
|
|
|
2024-06-11 20:26:44 +08:00
|
|
|
rc = tpm2_init_space(&priv->space, TPM2_SPACE_BUFFER_SIZE);
|
2017-01-04 01:07:32 +08:00
|
|
|
if (rc) {
|
|
|
|
kfree(priv);
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
2018-09-11 01:18:28 +08:00
|
|
|
tpm_common_open(file, chip, &priv->priv, &priv->space);
|
2017-01-04 01:07:32 +08:00
|
|
|
|
|
|
|
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);
|
2017-02-01 07:47:31 +08:00
|
|
|
tpm2_del_space(fpriv->chip, &priv->space);
|
2017-01-04 01:07:32 +08:00
|
|
|
kfree(priv);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
const struct file_operations tpmrm_fops = {
|
|
|
|
.owner = THIS_MODULE,
|
|
|
|
.llseek = no_llseek,
|
|
|
|
.open = tpmrm_open,
|
|
|
|
.read = tpm_common_read,
|
2018-09-11 01:18:28 +08:00
|
|
|
.write = tpm_common_write,
|
2018-09-11 01:18:33 +08:00
|
|
|
.poll = tpm_common_poll,
|
2017-01-04 01:07:32 +08:00
|
|
|
.release = tpmrm_release,
|
|
|
|
};
|