0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015 #include <linux/slab.h>
0016 #include "tpm-dev.h"
0017
0018 static int tpm_open(struct inode *inode, struct file *file)
0019 {
0020 struct tpm_chip *chip;
0021 struct file_priv *priv;
0022
0023 chip = container_of(inode->i_cdev, struct tpm_chip, cdev);
0024
0025
0026
0027
0028 if (test_and_set_bit(0, &chip->is_open)) {
0029 dev_dbg(&chip->dev, "Another process owns this TPM\n");
0030 return -EBUSY;
0031 }
0032
0033 priv = kzalloc(sizeof(*priv), GFP_KERNEL);
0034 if (priv == NULL)
0035 goto out;
0036
0037 tpm_common_open(file, chip, priv, NULL);
0038
0039 return 0;
0040
0041 out:
0042 clear_bit(0, &chip->is_open);
0043 return -ENOMEM;
0044 }
0045
0046
0047
0048
0049 static int tpm_release(struct inode *inode, struct file *file)
0050 {
0051 struct file_priv *priv = file->private_data;
0052
0053 tpm_common_release(file, priv);
0054 clear_bit(0, &priv->chip->is_open);
0055 kfree(priv);
0056
0057 return 0;
0058 }
0059
0060 const struct file_operations tpm_fops = {
0061 .owner = THIS_MODULE,
0062 .llseek = no_llseek,
0063 .open = tpm_open,
0064 .read = tpm_common_read,
0065 .write = tpm_common_write,
0066 .poll = tpm_common_poll,
0067 .release = tpm_release,
0068 };