From: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
To: Peter Huewe <peterhuewe@gmx.de>
Cc: Nayna Jain <nayna@linux.vnet.ibm.com>,
Marcel Selhorst <tpmdd@selhorst.net>,
Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>,
Jason Gunthorpe <jgunthorpe@obsidianresearch.com>,
tpmdd-devel@lists.sourceforge.net (moderated list:TPM DEVICE
DRIVER), linux-kernel@vger.kernel.org (open list)
Subject: [PATCH RESEND 1/3] tpm: define a generic open() method for ascii & bios measurements
Date: Sat, 1 Oct 2016 22:25:24 +0300 [thread overview]
Message-ID: <1475349926-476-2-git-send-email-jarkko.sakkinen@linux.intel.com> (raw)
In-Reply-To: <1475349926-476-1-git-send-email-jarkko.sakkinen@linux.intel.com>
From: Nayna Jain <nayna@linux.vnet.ibm.com>
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@obsidianresearch.com>
Signed-off-by: Nayna Jain <nayna@linux.vnet.ibm.com>
Reviewed-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
Reviewed-by: Jason Gunthorpe <jgunthorpe@obsidianresearch.com>
---
drivers/char/tpm/tpm_eventlog.c | 59 +++++++++--------------------------------
1 file changed, 13 insertions(+), 46 deletions(-)
diff --git a/drivers/char/tpm/tpm_eventlog.c b/drivers/char/tpm/tpm_eventlog.c
index e722886..75e6644 100644
--- a/drivers/char/tpm/tpm_eventlog.c
+++ b/drivers/char/tpm/tpm_eventlog.c
@@ -7,6 +7,7 @@
* Stefan Berger <stefanb@us.ibm.com>
* Reiner Sailer <sailer@watson.ibm.com>
* Kylene Hall <kjhall@us.ibm.com>
+ * Nayna Jain <nayna@linux.vnet.ibm.com>
*
* Maintained by: <tpmdd-devel@lists.sourceforge.net>
*
@@ -318,12 +319,14 @@ static const struct seq_operations tpm_binary_b_measurments_seqops = {
.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 @@ out_free:
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_measurments_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_measurments_seqops,
+ &tpm_bios_measurements_ops);
if (is_bad(ascii_file))
goto out_bin;
--
2.7.4
next prev parent reply other threads:[~2016-10-01 19:25 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-10-01 19:25 [PATCH RESEND 0/3] Clean up handling of event log files Jarkko Sakkinen
2016-10-01 19:25 ` Jarkko Sakkinen [this message]
2016-10-08 10:56 ` [PATCH RESEND 1/3] tpm: define a generic open() method for ascii & bios measurements Jarkko Sakkinen
2016-10-01 19:25 ` [PATCH RESEND 2/3] tpm: replace dynamically allocated bios_dir with a static array Jarkko Sakkinen
2016-10-02 21:28 ` Jason Gunthorpe
2016-10-03 12:21 ` Jarkko Sakkinen
2016-10-08 11:01 ` Jarkko Sakkinen
2016-10-10 18:53 ` Nayna
2016-10-11 11:23 ` Jarkko Sakkinen
2016-10-11 16:53 ` Jason Gunthorpe
2016-10-11 17:19 ` Nayna
2016-10-11 18:12 ` Jarkko Sakkinen
2016-10-11 18:09 ` Jarkko Sakkinen
2016-10-01 19:25 ` [PATCH RESEND 3/3] tpm: drop tpm1_chip_register(/unregister) Jarkko Sakkinen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1475349926-476-2-git-send-email-jarkko.sakkinen@linux.intel.com \
--to=jarkko.sakkinen@linux.intel.com \
--cc=jgunthorpe@obsidianresearch.com \
--cc=linux-kernel@vger.kernel.org \
--cc=nayna@linux.vnet.ibm.com \
--cc=peterhuewe@gmx.de \
--cc=tpmdd-devel@lists.sourceforge.net \
--cc=tpmdd@selhorst.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).