Merge tag 'block-5.11-2021-01-10' of git://git.kernel.dk/linux-block
[linux/fpc-iii.git] / drivers / char / tpm / tpmrm-dev.c
blobeef0fb06ea83223cefd9ce823607f2aad298c5ba
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3 * Copyright (C) 2017 James.Bottomley@HansenPartnership.com
4 */
5 #include <linux/slab.h>
6 #include "tpm-dev.h"
8 struct tpmrm_priv {
9 struct file_priv priv;
10 struct tpm_space space;
13 static int tpmrm_open(struct inode *inode, struct file *file)
15 struct tpm_chip *chip;
16 struct tpmrm_priv *priv;
17 int rc;
19 chip = container_of(inode->i_cdev, struct tpm_chip, cdevs);
20 priv = kzalloc(sizeof(*priv), GFP_KERNEL);
21 if (priv == NULL)
22 return -ENOMEM;
24 rc = tpm2_init_space(&priv->space, TPM2_SPACE_BUFFER_SIZE);
25 if (rc) {
26 kfree(priv);
27 return -ENOMEM;
30 tpm_common_open(file, chip, &priv->priv, &priv->space);
32 return 0;
35 static int tpmrm_release(struct inode *inode, struct file *file)
37 struct file_priv *fpriv = file->private_data;
38 struct tpmrm_priv *priv = container_of(fpriv, struct tpmrm_priv, priv);
40 tpm_common_release(file, fpriv);
41 tpm2_del_space(fpriv->chip, &priv->space);
42 kfree(priv);
44 return 0;
47 const struct file_operations tpmrm_fops = {
48 .owner = THIS_MODULE,
49 .llseek = no_llseek,
50 .open = tpmrm_open,
51 .read = tpm_common_read,
52 .write = tpm_common_write,
53 .poll = tpm_common_poll,
54 .release = tpmrm_release,