1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
|
// SPDX-License-Identifier: GPL-2.0-only
/*
* 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;
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,
.poll = tpm_common_poll,
.release = tpmrm_release,
};
|