brintos

brintos / linux-shallow public Read only

0
0
Text · 1.1 KiB · c25df7e Raw
55 lines · c
1// SPDX-License-Identifier: GPL-2.0-only2/*3 * Copyright (C) 2017 James.Bottomley@HansenPartnership.com4 */5#include <linux/slab.h>6#include "tpm-dev.h"7 8struct tpmrm_priv {9	struct file_priv priv;10	struct tpm_space space;11};12 13static int tpmrm_open(struct inode *inode, struct file *file)14{15	struct tpm_chip *chip;16	struct tpmrm_priv *priv;17	int rc;18 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;23 24	rc = tpm2_init_space(&priv->space, TPM2_SPACE_BUFFER_SIZE);25	if (rc) {26		kfree(priv);27		return -ENOMEM;28	}29 30	tpm_common_open(file, chip, &priv->priv, &priv->space);31 32	return 0;33}34 35static int tpmrm_release(struct inode *inode, struct file *file)36{37	struct file_priv *fpriv = file->private_data;38	struct tpmrm_priv *priv = container_of(fpriv, struct tpmrm_priv, priv);39 40	tpm_common_release(file, fpriv);41	tpm2_del_space(fpriv->chip, &priv->space);42	kfree(priv);43 44	return 0;45}46 47const struct file_operations tpmrm_fops = {48	.owner = THIS_MODULE,49	.open = tpmrm_open,50	.read = tpm_common_read,51	.write = tpm_common_write,52	.poll = tpm_common_poll,53	.release = tpmrm_release,54};55