[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <1479117656-12403-2-git-send-email-nayna@linux.vnet.ibm.com>
Date: Mon, 14 Nov 2016 05:00:48 -0500
From: Nayna Jain <nayna@...ux.vnet.ibm.com>
To: tpmdd-devel@...ts.sourceforge.net
Cc: peterhuewe@....de, tpmdd@...horst.net,
jarkko.sakkinen@...ux.intel.com, jgunthorpe@...idianresearch.com,
linux-kernel@...r.kernel.org,
linux-security-module@...r.kernel.org,
Nayna Jain <nayna@...ux.vnet.ibm.com>
Subject: [PATCH v6 1/9] tpm: define a generic open() method for ascii & bios measurements
open() method for event log ascii and binary bios measurements file
operations are very similar. This patch refactors the code into a
single open() call by passing seq_operations as i_node->private data.
Suggested-by: Jason Gunthorpe <jgunthorpe@...idianresearch.com>
Signed-off-by: Nayna Jain <nayna@...ux.vnet.ibm.com>
Reviewed-by: Jarkko Sakkinen <jarkko.sakkinen@...ux.intel.com>
Reviewed-by: Jason Gunthorpe <jgunthorpe@...idianresearch.com>
Tested-by: Jarkko Sakkinen <jarkko.sakkinen@...ux.intel.com>
Signed-off-by: Jarkko Sakkinen <jarkko.sakkinen@...ux.intel.com>
---
drivers/char/tpm/tpm_eventlog.c | 63 ++++++++++-------------------------------
1 file changed, 15 insertions(+), 48 deletions(-)
diff --git a/drivers/char/tpm/tpm_eventlog.c b/drivers/char/tpm/tpm_eventlog.c
index e722886..42b49c4 100644
--- a/drivers/char/tpm/tpm_eventlog.c
+++ b/drivers/char/tpm/tpm_eventlog.c
@@ -7,6 +7,7 @@
* Stefan Berger <stefanb@...ibm.com>
* Reiner Sailer <sailer@...son.ibm.com>
* Kylene Hall <kjhall@...ibm.com>
+ * Nayna Jain <nayna@...ux.vnet.ibm.com>
*
* Maintained by: <tpmdd-devel@...ts.sourceforge.net>
*
@@ -304,26 +305,28 @@ static int tpm_ascii_bios_measurements_show(struct seq_file *m, void *v)
return 0;
}
-static const struct seq_operations tpm_ascii_b_measurments_seqops = {
+static const struct seq_operations tpm_ascii_b_measurements_seqops = {
.start = tpm_bios_measurements_start,
.next = tpm_bios_measurements_next,
.stop = tpm_bios_measurements_stop,
.show = tpm_ascii_bios_measurements_show,
};
-static const struct seq_operations tpm_binary_b_measurments_seqops = {
+static const struct seq_operations tpm_binary_b_measurements_seqops = {
.start = tpm_bios_measurements_start,
.next = tpm_bios_measurements_next,
.stop = tpm_bios_measurements_stop,
.show = tpm_binary_bios_measurements_show,
};
-static int tpm_ascii_bios_measurements_open(struct inode *inode,
+static int tpm_bios_measurements_open(struct inode *inode,
struct file *file)
{
int err;
struct tpm_bios_log *log;
struct seq_file *seq;
+ const struct seq_operations *seqops =
+ (const struct seq_operations *)inode->i_private;
log = kzalloc(sizeof(struct tpm_bios_log), GFP_KERNEL);
if (!log)
@@ -333,7 +336,7 @@ static int tpm_ascii_bios_measurements_open(struct inode *inode,
goto out_free;
/* now register seq file */
- err = seq_open(file, &tpm_ascii_b_measurments_seqops);
+ err = seq_open(file, seqops);
if (!err) {
seq = file->private_data;
seq->private = log;
@@ -349,46 +352,8 @@ static int tpm_ascii_bios_measurements_open(struct inode *inode,
goto out;
}
-static const struct file_operations tpm_ascii_bios_measurements_ops = {
- .open = tpm_ascii_bios_measurements_open,
- .read = seq_read,
- .llseek = seq_lseek,
- .release = tpm_bios_measurements_release,
-};
-
-static int tpm_binary_bios_measurements_open(struct inode *inode,
- struct file *file)
-{
- int err;
- struct tpm_bios_log *log;
- struct seq_file *seq;
-
- log = kzalloc(sizeof(struct tpm_bios_log), GFP_KERNEL);
- if (!log)
- return -ENOMEM;
-
- if ((err = read_log(log)))
- goto out_free;
-
- /* now register seq file */
- err = seq_open(file, &tpm_binary_b_measurments_seqops);
- if (!err) {
- seq = file->private_data;
- seq->private = log;
- } else {
- goto out_free;
- }
-
-out:
- return err;
-out_free:
- kfree(log->bios_event_log);
- kfree(log);
- goto out;
-}
-
-static const struct file_operations tpm_binary_bios_measurements_ops = {
- .open = tpm_binary_bios_measurements_open,
+static const struct file_operations tpm_bios_measurements_ops = {
+ .open = tpm_bios_measurements_open,
.read = seq_read,
.llseek = seq_lseek,
.release = tpm_bios_measurements_release,
@@ -413,15 +378,17 @@ struct dentry **tpm_bios_log_setup(const char *name)
bin_file =
securityfs_create_file("binary_bios_measurements",
- S_IRUSR | S_IRGRP, tpm_dir, NULL,
- &tpm_binary_bios_measurements_ops);
+ S_IRUSR | S_IRGRP, tpm_dir,
+ (void *)&tpm_binary_b_measurements_seqops,
+ &tpm_bios_measurements_ops);
if (is_bad(bin_file))
goto out_tpm;
ascii_file =
securityfs_create_file("ascii_bios_measurements",
- S_IRUSR | S_IRGRP, tpm_dir, NULL,
- &tpm_ascii_bios_measurements_ops);
+ S_IRUSR | S_IRGRP, tpm_dir,
+ (void *)&tpm_ascii_b_measurements_seqops,
+ &tpm_bios_measurements_ops);
if (is_bad(ascii_file))
goto out_bin;
--
2.5.0
Powered by blists - more mailing lists