From: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
To: Andrey Pronin <apronin@chromium.org>
Cc: Peter Huewe <peterhuewe@gmx.de>,
Marcel Selhorst <tpmdd@selhorst.net>,
Jason Gunthorpe <jgunthorpe@obsidianresearch.com>,
tpmdd-devel@lists.sourceforge.net, linux-kernel@vger.kernel.org,
groeck@chromium.org, smbarber@chromium.org,
dianders@chromium.org
Subject: Re: [PATCH 1/2] tpm: add sysfs attributes for tpm2
Date: Mon, 18 Jul 2016 22:16:56 +0300 [thread overview]
Message-ID: <20160718191656.GP31463@intel.com> (raw)
In-Reply-To: <1468547496-16215-2-git-send-email-apronin@chromium.org>
On Thu, Jul 14, 2016 at 06:51:35PM -0700, Andrey Pronin wrote:
> Break sysfs attributes into common and TPM 1.2/2.0-specific, and
> create sysfs groups for TPM2.0.
I agree with Jasons comments and wait for revised version.
/Jarkko
> Signed-off-by: Andrey Pronin <apronin@chromium.org>
> ---
> drivers/char/tpm/tpm-chip.c | 48 ++++++++++++++++++++++++++++----------------
> drivers/char/tpm/tpm-sysfs.c | 24 ++++++++++++++++++++--
> 2 files changed, 53 insertions(+), 19 deletions(-)
>
> diff --git a/drivers/char/tpm/tpm-chip.c b/drivers/char/tpm/tpm-chip.c
> index 5a2f043..6c72671 100644
> --- a/drivers/char/tpm/tpm-chip.c
> +++ b/drivers/char/tpm/tpm-chip.c
> @@ -281,8 +281,6 @@ static int tpm1_chip_register(struct tpm_chip *chip)
> if (chip->flags & TPM_CHIP_FLAG_TPM2)
> return 0;
>
> - tpm_sysfs_add_device(chip);
> -
> chip->bios_dir = tpm_bios_log_setup(dev_name(&chip->dev));
>
> return 0;
> @@ -300,14 +298,21 @@ static void tpm1_chip_unregister(struct tpm_chip *chip)
> static void tpm_del_legacy_sysfs(struct tpm_chip *chip)
> {
> struct attribute **i;
> + int ngrp;
>
> - if (chip->flags & (TPM_CHIP_FLAG_TPM2 | TPM_CHIP_FLAG_VIRTUAL))
> + if (chip->flags & TPM_CHIP_FLAG_VIRTUAL)
> return;
>
> - sysfs_remove_link(&chip->dev.parent->kobj, "ppi");
> -
> - for (i = chip->groups[0]->attrs; *i != NULL; ++i)
> - sysfs_remove_link(&chip->dev.parent->kobj, (*i)->name);
> + for (ngrp = 0; ngrp < chip->groups_cnt; ++ngrp) {
> + if (chip->groups[ngrp]->name) {
> + sysfs_remove_link(&chip->dev.parent->kobj,
> + chip->groups[ngrp]->name);
> + } else {
> + for (i = chip->groups[ngrp]->attrs; *i != NULL; ++i)
> + sysfs_remove_link(&chip->dev.parent->kobj,
> + (*i)->name);
> + }
> + }
> }
>
> /* For compatibility with legacy sysfs paths we provide symlinks from the
> @@ -317,20 +322,27 @@ static void tpm_del_legacy_sysfs(struct tpm_chip *chip)
> static int tpm_add_legacy_sysfs(struct tpm_chip *chip)
> {
> struct attribute **i;
> - int rc;
> + int rc = 0;
> + int ngrp;
>
> - if (chip->flags & (TPM_CHIP_FLAG_TPM2 | TPM_CHIP_FLAG_VIRTUAL))
> + if (chip->flags & TPM_CHIP_FLAG_VIRTUAL)
> return 0;
>
> - rc = __compat_only_sysfs_link_entry_to_kobj(
> - &chip->dev.parent->kobj, &chip->dev.kobj, "ppi");
> - if (rc && rc != -ENOENT)
> - return rc;
> -
> /* All the names from tpm-sysfs */
> - for (i = chip->groups[0]->attrs; *i != NULL; ++i) {
> - rc = __compat_only_sysfs_link_entry_to_kobj(
> - &chip->dev.parent->kobj, &chip->dev.kobj, (*i)->name);
> + for (ngrp = 0; ngrp < chip->groups_cnt; ++ngrp) {
> + if (chip->groups[ngrp]->name) {
> + rc = __compat_only_sysfs_link_entry_to_kobj(
> + &chip->dev.parent->kobj, &chip->dev.kobj,
> + chip->groups[ngrp]->name);
> + } else {
> + for (i = chip->groups[ngrp]->attrs;
> + (*i != NULL) && !rc;
> + ++i)
> + rc = __compat_only_sysfs_link_entry_to_kobj(
> + &chip->dev.parent->kobj,
> + &chip->dev.kobj,
> + (*i)->name);
> + }
> if (rc) {
> tpm_del_legacy_sysfs(chip);
> return rc;
> @@ -354,6 +366,8 @@ int tpm_chip_register(struct tpm_chip *chip)
> {
> int rc;
>
> + tpm_sysfs_add_device(chip);
> +
> rc = tpm1_chip_register(chip);
> if (rc)
> return rc;
> diff --git a/drivers/char/tpm/tpm-sysfs.c b/drivers/char/tpm/tpm-sysfs.c
> index b46cf70..95ce90d 100644
> --- a/drivers/char/tpm/tpm-sysfs.c
> +++ b/drivers/char/tpm/tpm-sysfs.c
> @@ -265,6 +265,12 @@ static ssize_t timeouts_show(struct device *dev, struct device_attribute *attr,
> static DEVICE_ATTR_RO(timeouts);
>
> static struct attribute *tpm_dev_attrs[] = {
> + &dev_attr_durations.attr,
> + &dev_attr_timeouts.attr,
> + NULL,
> +};
> +
> +static struct attribute *tpm1_dev_attrs[] = {
> &dev_attr_pubek.attr,
> &dev_attr_pcrs.attr,
> &dev_attr_enabled.attr,
> @@ -273,8 +279,10 @@ static struct attribute *tpm_dev_attrs[] = {
> &dev_attr_temp_deactivated.attr,
> &dev_attr_caps.attr,
> &dev_attr_cancel.attr,
> - &dev_attr_durations.attr,
> - &dev_attr_timeouts.attr,
> + NULL,
> +};
> +
> +static struct attribute *tpm2_dev_attrs[] = {
> NULL,
> };
>
> @@ -282,6 +290,14 @@ static const struct attribute_group tpm_dev_group = {
> .attrs = tpm_dev_attrs,
> };
>
> +static const struct attribute_group tpm1_dev_group = {
> + .attrs = tpm1_dev_attrs,
> +};
> +
> +static const struct attribute_group tpm2_dev_group = {
> + .attrs = tpm2_dev_attrs,
> +};
> +
> void tpm_sysfs_add_device(struct tpm_chip *chip)
> {
> /* The sysfs routines rely on an implicit tpm_try_get_ops, device_del
> @@ -290,4 +306,8 @@ void tpm_sysfs_add_device(struct tpm_chip *chip)
> */
> WARN_ON(chip->groups_cnt != 0);
> chip->groups[chip->groups_cnt++] = &tpm_dev_group;
> + if (chip->flags & TPM_CHIP_FLAG_TPM2)
> + chip->groups[chip->groups_cnt++] = &tpm2_dev_group;
> + else
> + chip->groups[chip->groups_cnt++] = &tpm1_dev_group;
> }
> --
> 2.6.6
>
next prev parent reply other threads:[~2016-07-18 19:17 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-07-15 1:51 [PATCH 0/2] tpm: driver- and tpm2-specific sysfs attributes Andrey Pronin
2016-07-15 1:51 ` [PATCH 1/2] tpm: add sysfs attributes for tpm2 Andrey Pronin
2016-07-15 3:21 ` Jason Gunthorpe
2016-07-15 3:32 ` Andrey Pronin
2016-07-15 3:34 ` Jason Gunthorpe
2016-07-15 16:56 ` Andrey Pronin
2016-07-15 17:09 ` Jason Gunthorpe
2016-07-18 19:16 ` Jarkko Sakkinen [this message]
2016-07-15 1:51 ` [PATCH 2/2] tpm: support driver-specific sysfs attrs in tpm_tis_core Andrey Pronin
2016-07-15 3:23 ` Jason Gunthorpe
2016-07-15 3:35 ` Andrey Pronin
2016-07-18 19:20 ` Jarkko Sakkinen
2016-07-18 19:11 ` Jarkko Sakkinen
2016-07-18 19:17 ` Andrey Pronin
2016-07-20 2:51 ` [PATCH v2] tpm: add sysfs attributes for tpm2 Andrey Pronin
2016-07-20 17:05 ` Jason Gunthorpe
2016-07-20 17:41 ` Andrey Pronin
2016-07-28 4:06 ` [PATCH v3] " Andrey Pronin
2016-08-09 10:25 ` 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=20160718191656.GP31463@intel.com \
--to=jarkko.sakkinen@linux.intel.com \
--cc=apronin@chromium.org \
--cc=dianders@chromium.org \
--cc=groeck@chromium.org \
--cc=jgunthorpe@obsidianresearch.com \
--cc=linux-kernel@vger.kernel.org \
--cc=peterhuewe@gmx.de \
--cc=smbarber@chromium.org \
--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).