#include <linux/slab.h>
#include "tpm-dev.h"
static int tpm_open(struct inode *inode, struct file *file)
{
struct tpm_chip *chip;
struct file_priv *priv;
chip = container_of(inode->i_cdev, struct tpm_chip, cdev);
if (test_and_set_bit(0, &chip->is_open)) {
dev_dbg(&chip->dev, "Another process owns this TPM\n");
return -EBUSY;
}
priv = kzalloc(sizeof(*priv), GFP_KERNEL);
if (priv == NULL)
goto out;
tpm_common_open(file, chip, priv, NULL);
return 0;
out:
clear_bit(0, &chip->is_open);
return -ENOMEM;
}
static int tpm_release(struct inode *inode, struct file *file)
{
struct file_priv *priv = file->private_data;
tpm_common_release(file, priv);
clear_bit(0, &priv->chip->is_open);
kfree(priv);
return 0;
}
const struct file_operations tpm_fops = {
.owner = THIS_MODULE,
.llseek = no_llseek,
.open = tpm_open,
.read = tpm_common_read,
.write = tpm_common_write,
.poll = tpm_common_poll,
.release = tpm_release,
}