From: "Li, Meng" <Meng.Li@windriver.com>
To: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
Cc: "linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
"peterhuewe@gmx.de" <peterhuewe@gmx.de>,
"tpmdd@selhorst.net" <tpmdd@selhorst.net>,
"jgunthorpe@obsidianresearch.com"
<jgunthorpe@obsidianresearch.com>,
"tpmdd-devel@lists.sourceforge.net"
<tpmdd-devel@lists.sourceforge.net>
Subject: RE: [PATCH] tpm: Add sysfs interface to show TPM hardware version
Date: Mon, 13 Mar 2017 12:37:30 +0000 [thread overview]
Message-ID: <529F9A9100AE8045A7A5B5A00A39FBB83DE93249@ALA-MBC.corp.ad.wrs.com> (raw)
In-Reply-To: <20170313114852.kmfequmchxi3jams@intel.com>
> -----Original Message-----
> From: Jarkko Sakkinen [mailto:jarkko.sakkinen@linux.intel.com]
> Sent: Monday, March 13, 2017 7:49 PM
> To: Li, Meng
> Cc: linux-kernel@vger.kernel.org; peterhuewe@gmx.de;
> tpmdd@selhorst.net; jgunthorpe@obsidianresearch.com; tpmdd-
> devel@lists.sourceforge.net
> Subject: Re: [PATCH] tpm: Add sysfs interface to show TPM hardware
> version
>
> On Mon, Mar 13, 2017 at 01:21:57PM +0800, Meng.Li@windriver.com wrote:
> > From: Limeng <Meng.Li@windriver.com>
> >
> > So far, there is not a sysfs interface for user space code to check
> > the TPM hardware version(TPM1.x or TPM2). So, add a file named
> > description in /sys/class/tpm/tpmX/ to show it.
> >
> > Signed-off-by: Meng Li <Meng.Li@windriver.com>
> > ---
> > drivers/char/tpm/tpm-chip.c | 85
> +++++++++++++++++++++++++++++++++++++++++++
> > 1 file changed, 85 insertions(+)
> >
> > diff --git a/drivers/char/tpm/tpm-chip.c b/drivers/char/tpm/tpm-chip.c
> > index c406343..da2cd69 100644
> > --- a/drivers/char/tpm/tpm-chip.c
> > +++ b/drivers/char/tpm/tpm-chip.c
>
> tpm-sysfs.c Probably makes sense to rename legacy group there as tpm1_
Thanks for this advice.
>
> > @@ -36,6 +36,83 @@
> > dev_t tpm_devt;
> >
> > /**
> > + * show_description - sysfs interface for checking current TPM hardware
> version.
> > + * @dev: pointer to tpm chip device
> > + * @attr: unused
> > + * @buf: char buffer to be filled with TPM hardware version info
> > + *
> > + * Provides sysfs interface for showing current TPM hardware version.
> > + */
> > +static ssize_t show_description(struct device *dev,
> > + struct device_attribute *attr, char *buf)
>
> family
>
> > +{
> > + struct tpm_chip *chip = (struct tpm_chip *)container_of(dev,struct
> tpm_chip,dev);
> > + int ret;
> > +
> > + if (chip->flags & TPM_CHIP_FLAG_TPM2)
> > + ret = sprintf(buf, "TPM 2.0");
> > + else
> > + ret = sprintf(buf, "TPM 1.x");
> > +
> > + return ret;
> > +}
> > +
> > +/**
> > + * store_description - interface for manually setting data.
> > + * @dev: unused
> > + * @attr: unused
> > + * @buf: unused
> > + * @count: unused
> > + *
> > + * There is not any process in this function, reserve for feature.
> > + */
> > +static ssize_t store_description(struct device *dev, struct
> device_attribute *attr,
> > + const char *buf, size_t count)
> > +{
> > + return count;
> > +}
>
> What is this??
>
> > +
> > +static struct device_attribute tpm_attrs[] = {
> > + __ATTR(description, S_IRUGO | S_IWUSR, show_description,
> > +store_description), };
> > +
> > +/**
> > + * tpm_create_sysfs - Create tpm sysfs interface.
> > + * @dev: pointer to tpm chip device
> > + *
> > + * Create sysfs interface for checking current TPM hardware version.
> > + */
> > +static int tpm_create_sysfs(struct device *dev) {
> > + int r, t;
> > +
> > + for (t = 0; t < ARRAY_SIZE(tpm_attrs); t++) {
> > + r = device_create_file(dev, &tpm_attrs[t]);
> > + if (r) {
> > + dev_err(dev, "failed to create sysfs file\n");
> > + return r;
> > + }
> > + }
> > +
> > + return 0;
> > +}
> > +
> > +/**
> > + * tpm_remove_sysfs - Remove tpm sysfs interface.
> > + * @dev: pointer to tpm chip device
> > + *
> > + * Remove sysfs interface for checking current TPM hardware version.
> > + */
> > +static void tpm_remove_sysfs(struct device *dev) {
> > + int t;
> > +
> > + for (t = 0; t < ARRAY_SIZE(tpm_attrs); t++) {
> > + device_remove_file(dev, &tpm_attrs[t]);
> > + }
> > +}
> > +
> > +/**
> > * tpm_try_get_ops() - Get a ref to the tpm_chip
> > * @chip: Chip to ref
> > *
> > @@ -363,6 +440,13 @@ int tpm_chip_register(struct tpm_chip *chip)
> > return rc;
> > }
> >
> > + rc = tpm_create_sysfs(&chip->dev);
> > + if (rc) {
> > + tpm_del_legacy_sysfs(chip);
> > + tpm_chip_unregister(chip);
> > + return rc;
> > + }
> > +
> > return 0;
> > }
> > EXPORT_SYMBOL_GPL(tpm_chip_register);
> > @@ -382,6 +466,7 @@ int tpm_chip_register(struct tpm_chip *chip)
> > */
> > void tpm_chip_unregister(struct tpm_chip *chip) {
> > + tpm_remove_sysfs(&chip->dev);
> > tpm_del_legacy_sysfs(chip);
> > tpm_bios_log_teardown(chip);
> > tpm_del_char_device(chip);
> > --
> > 1.7.9.5
>
> You should put the attributes to chip->groups instead of racy creation of
> them.
Thanks for your advice. It is more reasonable in to chip->groups.
Regards,
Limeng
>
> /Jarkko
prev parent reply other threads:[~2017-03-13 12:38 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-03-13 5:21 [PATCH] tpm: Add sysfs interface to show TPM hardware version Meng.Li
2017-03-13 7:10 ` Peter Huewe
2017-03-13 7:47 ` Li, Meng
2017-03-14 18:18 ` [tpmdd-devel] " Ken Goldman
2017-03-14 18:58 ` Peter Huewe
2017-03-14 21:24 ` Jason Gunthorpe
2017-03-14 21:42 ` James Bottomley
2017-03-15 17:25 ` Jason Gunthorpe
2017-03-13 11:48 ` Jarkko Sakkinen
2017-03-13 12:37 ` Li, Meng [this message]
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=529F9A9100AE8045A7A5B5A00A39FBB83DE93249@ALA-MBC.corp.ad.wrs.com \
--to=meng.li@windriver.com \
--cc=jarkko.sakkinen@linux.intel.com \
--cc=jgunthorpe@obsidianresearch.com \
--cc=linux-kernel@vger.kernel.org \
--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).