Linux kernel mirror (for testing)
git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel
os
linux
1/*
2 * Copyright (C) 2017 James.Bottomley@HansenPartnership.com
3 *
4 * GPLv2
5 */
6#include <linux/slab.h>
7#include "tpm-dev.h"
8
9struct tpmrm_priv {
10 struct file_priv priv;
11 struct tpm_space space;
12};
13
14static int tpmrm_open(struct inode *inode, struct file *file)
15{
16 struct tpm_chip *chip;
17 struct tpmrm_priv *priv;
18 int rc;
19
20 chip = container_of(inode->i_cdev, struct tpm_chip, cdevs);
21 priv = kzalloc(sizeof(*priv), GFP_KERNEL);
22 if (priv == NULL)
23 return -ENOMEM;
24
25 rc = tpm2_init_space(&priv->space);
26 if (rc) {
27 kfree(priv);
28 return -ENOMEM;
29 }
30
31 tpm_common_open(file, chip, &priv->priv, &priv->space);
32
33 return 0;
34}
35
36static int tpmrm_release(struct inode *inode, struct file *file)
37{
38 struct file_priv *fpriv = file->private_data;
39 struct tpmrm_priv *priv = container_of(fpriv, struct tpmrm_priv, priv);
40
41 tpm_common_release(file, fpriv);
42 tpm2_del_space(fpriv->chip, &priv->space);
43 kfree(priv);
44
45 return 0;
46}
47
48const struct file_operations tpmrm_fops = {
49 .owner = THIS_MODULE,
50 .llseek = no_llseek,
51 .open = tpmrm_open,
52 .read = tpm_common_read,
53 .write = tpm_common_write,
54 .poll = tpm_common_poll,
55 .release = tpmrm_release,
56};