diff options
author | Jason Gunthorpe <jgunthorpe@obsidianresearch.com> | 2013-10-05 13:38:02 -0400 |
---|---|---|
committer | Peter Huewe <peterhuewe@gmx.de> | 2013-10-22 13:42:31 -0400 |
commit | 58c09e21332c4ab56ac694a71f6715db2768f53f (patch) | |
tree | cb1198d4aa42d98dcacab0b5dd845f57c07899b6 /drivers/char/tpm | |
parent | 6aff1fdc5d59acd7181bdd2f41b34d7bea1b6dcb (diff) |
tpm: Use container_of to locate the tpm_chip in tpm_open
misc_open sets the file->private_date to the misc_dev when calling
open. We can use container_of to go from the misc_dev back to the
tpm_chip.
Future clean ups will move tpm_open into a new file and this change
means we do not have to export the tpm_chip list.
Signed-off-by: Jason Gunthorpe <jgunthorpe@obsidianresearch.com>
Reviewed-by: Joel Schopp <jschopp@linux.vnet.ibm.com>
Reviewed-by: Peter Huewe <peterhuewe@gmx.de>
Acked-by: Ashley Lai <adlai@linux.vnet.ibm.com>
Signed-off-by: Peter Huewe <peterhuewe@gmx.de>
Diffstat (limited to 'drivers/char/tpm')
-rw-r--r-- | drivers/char/tpm/tpm.c | 21 |
1 files changed, 4 insertions, 17 deletions
diff --git a/drivers/char/tpm/tpm.c b/drivers/char/tpm/tpm.c index 71eb8c762880..c3ab508222af 100644 --- a/drivers/char/tpm/tpm.c +++ b/drivers/char/tpm/tpm.c | |||
@@ -1170,38 +1170,25 @@ EXPORT_SYMBOL_GPL(wait_for_tpm_stat); | |||
1170 | */ | 1170 | */ |
1171 | int tpm_open(struct inode *inode, struct file *file) | 1171 | int tpm_open(struct inode *inode, struct file *file) |
1172 | { | 1172 | { |
1173 | int minor = iminor(inode); | 1173 | struct miscdevice *misc = file->private_data; |
1174 | struct tpm_chip *chip = NULL, *pos; | 1174 | struct tpm_chip *chip = container_of(misc, struct tpm_chip, |
1175 | 1175 | vendor.miscdev); | |
1176 | rcu_read_lock(); | ||
1177 | list_for_each_entry_rcu(pos, &tpm_chip_list, list) { | ||
1178 | if (pos->vendor.miscdev.minor == minor) { | ||
1179 | chip = pos; | ||
1180 | get_device(chip->dev); | ||
1181 | break; | ||
1182 | } | ||
1183 | } | ||
1184 | rcu_read_unlock(); | ||
1185 | |||
1186 | if (!chip) | ||
1187 | return -ENODEV; | ||
1188 | 1176 | ||
1189 | if (test_and_set_bit(0, &chip->is_open)) { | 1177 | if (test_and_set_bit(0, &chip->is_open)) { |
1190 | dev_dbg(chip->dev, "Another process owns this TPM\n"); | 1178 | dev_dbg(chip->dev, "Another process owns this TPM\n"); |
1191 | put_device(chip->dev); | ||
1192 | return -EBUSY; | 1179 | return -EBUSY; |
1193 | } | 1180 | } |
1194 | 1181 | ||
1195 | chip->data_buffer = kzalloc(TPM_BUFSIZE, GFP_KERNEL); | 1182 | chip->data_buffer = kzalloc(TPM_BUFSIZE, GFP_KERNEL); |
1196 | if (chip->data_buffer == NULL) { | 1183 | if (chip->data_buffer == NULL) { |
1197 | clear_bit(0, &chip->is_open); | 1184 | clear_bit(0, &chip->is_open); |
1198 | put_device(chip->dev); | ||
1199 | return -ENOMEM; | 1185 | return -ENOMEM; |
1200 | } | 1186 | } |
1201 | 1187 | ||
1202 | atomic_set(&chip->data_pending, 0); | 1188 | atomic_set(&chip->data_pending, 0); |
1203 | 1189 | ||
1204 | file->private_data = chip; | 1190 | file->private_data = chip; |
1191 | get_device(chip->dev); | ||
1205 | return 0; | 1192 | return 0; |
1206 | } | 1193 | } |
1207 | EXPORT_SYMBOL_GPL(tpm_open); | 1194 | EXPORT_SYMBOL_GPL(tpm_open); |