Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1598851 > unrolled thread

[PATCH] tpm: Add sysfs interface to show TPM hardware version

Started by<Meng.Li@windriver.com>
First post2017-03-13 06:30 +0100
Last post2017-03-13 13:40 +0100
Articles 5 — 4 participants

Back to article view | Back to linux.kernel


Contents

  [PATCH] tpm: Add sysfs interface to show TPM hardware version <Meng.Li@windriver.com> - 2017-03-13 06:30 +0100
    Re: [PATCH] tpm: Add sysfs interface to show TPM hardware version Peter Huewe <peterhuewe@gmx.de> - 2017-03-13 08:20 +0100
      RE: [PATCH] tpm: Add sysfs interface to show TPM hardware version "Li, Meng" <Meng.Li@windriver.com> - 2017-03-13 08:50 +0100
    Re: [PATCH] tpm: Add sysfs interface to show TPM hardware version Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com> - 2017-03-13 12:50 +0100
      RE: [PATCH] tpm: Add sysfs interface to show TPM hardware version "Li, Meng" <Meng.Li@windriver.com> - 2017-03-13 13:40 +0100

#1598851 — [PATCH] tpm: Add sysfs interface to show TPM hardware version

From<Meng.Li@windriver.com>
Date2017-03-13 06:30 +0100
Subject[PATCH] tpm: Add sysfs interface to show TPM hardware version
Message-ID<tkqIq-46N-3@gated-at.bofh.it>
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
@@ -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)
+{
+	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;
+}
+
+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

[toc] | [next] | [standalone]


#1598910

FromPeter Huewe <peterhuewe@gmx.de>
Date2017-03-13 08:20 +0100
Message-ID<tksqR-5qK-7@gated-at.bofh.it>
In reply to#1598851
Hi,
Thanks for your patch.

Am 13. März 2017 06:21:57 MEZ schrieb Meng.Li@windriver.com:
>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.
It's not really the hardware version but the "TPM Family" according to tcg.

And yes you are right there is currently no way, except for trial and error, for the userspace to determine this.
So an interface to get this information makes sense to me.
>
>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
>@@ -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)
>+{
>+	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;
>+}
Since it does not do anything
I would not create this function and leave the sysfs node as S_IRUGO.

>+
>+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);

-- 
Sent from my mobile

[toc] | [prev] | [next] | [standalone]


#1598923

From"Li, Meng" <Meng.Li@windriver.com>
Date2017-03-13 08:50 +0100
Message-ID<tksTT-5Fi-3@gated-at.bofh.it>
In reply to#1598910

> -----Original Message-----
> From: Peter Huewe [mailto:peterhuewe@gmx.de]
> Sent: Monday, March 13, 2017 3:11 PM
> To: Li, Meng; linux-kernel@vger.kernel.org
> Cc: tpmdd@selhorst.net; jarkko.sakkinen@linux.intel.com;
> jgunthorpe@obsidianresearch.com; tpmdd-devel@lists.sourceforge.net
> Subject: Re: [PATCH] tpm: Add sysfs interface to show TPM hardware
> version
> 
> Hi,
> Thanks for your patch.

Hi Peter,

Thanks for reviewing this patch in your busy time.
I will do modification according to your comment and then send the next patch reviewing.

Thanks,
Limeng

> 
> Am 13. März 2017 06:21:57 MEZ schrieb Meng.Li@windriver.com:
> >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.
> It's not really the hardware version but the "TPM Family" according to tcg.
> 
> And yes you are right there is currently no way, except for trial and error, for
> the userspace to determine this.
> So an interface to get this information makes sense to me.
> >
> >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
> >@@ -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) {
> >+	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;
> >+}
> Since it does not do anything
> I would not create this function and leave the sysfs node as S_IRUGO.
> 
> >+
> >+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);
> 
> --
> Sent from my mobile

[toc] | [prev] | [next] | [standalone]


#1599243

FromJarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
Date2017-03-13 12:50 +0100
Message-ID<tkwEa-8nq-17@gated-at.bofh.it>
In reply to#1598851
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_

> @@ -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.

/Jarkko

[toc] | [prev] | [next] | [standalone]


#1599289

From"Li, Meng" <Meng.Li@windriver.com>
Date2017-03-13 13:40 +0100
Message-ID<tkxqz-uQ-37@gated-at.bofh.it>
In reply to#1599243

> -----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

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web