Re: [PATCH] tpm: fix compat 'ppi' link handling in tpm_chip_register()

2015-11-09 Thread Jarkko Sakkinen
On Mon, Nov 09, 2015 at 10:11:41PM -0800, Jeremiah Mahler wrote:
> Jarkko,
> 
> On Sun, Nov 08, 2015 at 09:51:07AM +0200, Jarkko Sakkinen wrote:
> > __compat_only_sysfs_link_entry_to_kobj() was unconditionally called for
> > TPM1 chips, which caused crash on Acer C720 laptop where DSM for the
> > ACPI object did not exist.
> > 
> > There are two reasons for unwanted behavior:
> > 
> > * The code did not check whether
> >   __compat_only_sysfs_link_entry_to_kobj() returned -ENOENT. This is
> >   OK. It just meanst that ppi is not available.
> > * The code did not clean up properly. Compat link should added only
> >   after all other init is done.
> > 
> > This patch sorts out these issues.
> > 
> > Fixes: 9b774d5cf2db
> > Reported-by: Jeremiah Mahler 
> > Signed-off-by: Jarkko Sakkinen 
> > Tested-by: Jeremiah Mahler 
> > ---
> >  drivers/char/tpm/tpm-chip.c | 18 ++
> >  1 file changed, 10 insertions(+), 8 deletions(-)
> > 
> > diff --git a/drivers/char/tpm/tpm-chip.c b/drivers/char/tpm/tpm-chip.c
> > index a5cdce7..45cc39a 100644
> > --- a/drivers/char/tpm/tpm-chip.c
> > +++ b/drivers/char/tpm/tpm-chip.c
> > @@ -226,14 +226,6 @@ int tpm_chip_register(struct tpm_chip *chip)
> > if (rc)
> > goto out_err;
> >  
> > -   if (!(chip->flags & TPM_CHIP_FLAG_TPM2)) {
> > -   rc = __compat_only_sysfs_link_entry_to_kobj(>pdev->kobj,
> > -   >dev.kobj,
> > -   "ppi");
> > -   if (rc)
> > -   goto out_err;
> > -   }
> > -
> > /* Make the chip available. */
> > spin_lock(_lock);
> > list_add_tail_rcu(>list, _chip_list);
> > @@ -241,6 +233,16 @@ int tpm_chip_register(struct tpm_chip *chip)
> >  
> > chip->flags |= TPM_CHIP_FLAG_REGISTERED;
> >  
> > +   if (!(chip->flags & TPM_CHIP_FLAG_TPM2)) {
> > +   rc = __compat_only_sysfs_link_entry_to_kobj(>pdev->kobj,
> > +   >dev.kobj,
> > +   "ppi");
> > +   if (rc && rc != -ENOENT) {
> > +   tpm_chip_unregister(chip);
> > +   return rc;
> > +   }
> > +   }
> > +
> > return 0;
> >  out_err:
> > tpm1_chip_unregister(chip);
> > -- 
> > 2.5.0
> > 
> 
> This patch doesn't apply to the latest linux-next (20151109).  I think I
> may be missing a dependent patch.  Do you know which one?

It is expected as there are 7 other bug fixes that I'm including to the
next pull rquest and this is on top.

> - Jeremiah Mahler

/Jarkko
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH] tpm: fix compat 'ppi' link handling in tpm_chip_register()

2015-11-09 Thread Jeremiah Mahler
Jarkko,

On Sun, Nov 08, 2015 at 09:51:07AM +0200, Jarkko Sakkinen wrote:
> __compat_only_sysfs_link_entry_to_kobj() was unconditionally called for
> TPM1 chips, which caused crash on Acer C720 laptop where DSM for the
> ACPI object did not exist.
> 
> There are two reasons for unwanted behavior:
> 
> * The code did not check whether
>   __compat_only_sysfs_link_entry_to_kobj() returned -ENOENT. This is
>   OK. It just meanst that ppi is not available.
> * The code did not clean up properly. Compat link should added only
>   after all other init is done.
> 
> This patch sorts out these issues.
> 
> Fixes: 9b774d5cf2db
> Reported-by: Jeremiah Mahler 
> Signed-off-by: Jarkko Sakkinen 
> Tested-by: Jeremiah Mahler 
> ---
>  drivers/char/tpm/tpm-chip.c | 18 ++
>  1 file changed, 10 insertions(+), 8 deletions(-)
> 
> diff --git a/drivers/char/tpm/tpm-chip.c b/drivers/char/tpm/tpm-chip.c
> index a5cdce7..45cc39a 100644
> --- a/drivers/char/tpm/tpm-chip.c
> +++ b/drivers/char/tpm/tpm-chip.c
> @@ -226,14 +226,6 @@ int tpm_chip_register(struct tpm_chip *chip)
>   if (rc)
>   goto out_err;
>  
> - if (!(chip->flags & TPM_CHIP_FLAG_TPM2)) {
> - rc = __compat_only_sysfs_link_entry_to_kobj(>pdev->kobj,
> - >dev.kobj,
> - "ppi");
> - if (rc)
> - goto out_err;
> - }
> -
>   /* Make the chip available. */
>   spin_lock(_lock);
>   list_add_tail_rcu(>list, _chip_list);
> @@ -241,6 +233,16 @@ int tpm_chip_register(struct tpm_chip *chip)
>  
>   chip->flags |= TPM_CHIP_FLAG_REGISTERED;
>  
> + if (!(chip->flags & TPM_CHIP_FLAG_TPM2)) {
> + rc = __compat_only_sysfs_link_entry_to_kobj(>pdev->kobj,
> + >dev.kobj,
> + "ppi");
> + if (rc && rc != -ENOENT) {
> + tpm_chip_unregister(chip);
> + return rc;
> + }
> + }
> +
>   return 0;
>  out_err:
>   tpm1_chip_unregister(chip);
> -- 
> 2.5.0
> 

This patch doesn't apply to the latest linux-next (20151109).  I think I
may be missing a dependent patch.  Do you know which one?

-- 
- Jeremiah Mahler
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH] tpm: fix compat 'ppi' link handling in tpm_chip_register()

2015-11-09 Thread Jarkko Sakkinen
On Mon, Nov 09, 2015 at 03:47:20PM -0700, Jason Gunthorpe wrote:
> On Sun, Nov 08, 2015 at 09:51:07AM +0200, Jarkko Sakkinen wrote:
> > +   if (rc && rc != -ENOENT) {
> > +   tpm_chip_unregister(chip);
> > +   return rc;
> > +   }
> > +   }
> 
> This is still goofy looking, the list_add_tail_rcu should be the last
> thing done and cannot fail. Just code this with the usual goto based
> unwind and goto to do tpm_dev_del_device for the above failure.

Agreed that this would be cleaner.

> > +
> > return 0;
> >  out_err:
> > tpm1_chip_unregister(chip);
> 
> Which avoids calling tpm1_chip_unregister and tpm_chip_unregister in
> the same function, which looks so wrong to a casual read..

I'm not going to change the current patch at this point of release
cycle but this clean up definitely makes sense later on.

> Jason

/Jarkko
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH] tpm: fix compat 'ppi' link handling in tpm_chip_register()

2015-11-09 Thread Jason Gunthorpe
On Sun, Nov 08, 2015 at 09:51:07AM +0200, Jarkko Sakkinen wrote:
> + if (rc && rc != -ENOENT) {
> + tpm_chip_unregister(chip);
> + return rc;
> + }
> + }

This is still goofy looking, the list_add_tail_rcu should be the last
thing done and cannot fail. Just code this with the usual goto based
unwind and goto to do tpm_dev_del_device for the above failure.

> +
>   return 0;
>  out_err:
>   tpm1_chip_unregister(chip);

Which avoids calling tpm1_chip_unregister and tpm_chip_unregister in
the same function, which looks so wrong to a casual read..

Jason
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH] tpm: fix compat 'ppi' link handling in tpm_chip_register()

2015-11-09 Thread Jarkko Sakkinen
On Mon, Nov 09, 2015 at 03:47:20PM -0700, Jason Gunthorpe wrote:
> On Sun, Nov 08, 2015 at 09:51:07AM +0200, Jarkko Sakkinen wrote:
> > +   if (rc && rc != -ENOENT) {
> > +   tpm_chip_unregister(chip);
> > +   return rc;
> > +   }
> > +   }
> 
> This is still goofy looking, the list_add_tail_rcu should be the last
> thing done and cannot fail. Just code this with the usual goto based
> unwind and goto to do tpm_dev_del_device for the above failure.

Agreed that this would be cleaner.

> > +
> > return 0;
> >  out_err:
> > tpm1_chip_unregister(chip);
> 
> Which avoids calling tpm1_chip_unregister and tpm_chip_unregister in
> the same function, which looks so wrong to a casual read..

I'm not going to change the current patch at this point of release
cycle but this clean up definitely makes sense later on.

> Jason

/Jarkko
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH] tpm: fix compat 'ppi' link handling in tpm_chip_register()

2015-11-09 Thread Jeremiah Mahler
Jarkko,

On Sun, Nov 08, 2015 at 09:51:07AM +0200, Jarkko Sakkinen wrote:
> __compat_only_sysfs_link_entry_to_kobj() was unconditionally called for
> TPM1 chips, which caused crash on Acer C720 laptop where DSM for the
> ACPI object did not exist.
> 
> There are two reasons for unwanted behavior:
> 
> * The code did not check whether
>   __compat_only_sysfs_link_entry_to_kobj() returned -ENOENT. This is
>   OK. It just meanst that ppi is not available.
> * The code did not clean up properly. Compat link should added only
>   after all other init is done.
> 
> This patch sorts out these issues.
> 
> Fixes: 9b774d5cf2db
> Reported-by: Jeremiah Mahler 
> Signed-off-by: Jarkko Sakkinen 
> Tested-by: Jeremiah Mahler 
> ---
>  drivers/char/tpm/tpm-chip.c | 18 ++
>  1 file changed, 10 insertions(+), 8 deletions(-)
> 
> diff --git a/drivers/char/tpm/tpm-chip.c b/drivers/char/tpm/tpm-chip.c
> index a5cdce7..45cc39a 100644
> --- a/drivers/char/tpm/tpm-chip.c
> +++ b/drivers/char/tpm/tpm-chip.c
> @@ -226,14 +226,6 @@ int tpm_chip_register(struct tpm_chip *chip)
>   if (rc)
>   goto out_err;
>  
> - if (!(chip->flags & TPM_CHIP_FLAG_TPM2)) {
> - rc = __compat_only_sysfs_link_entry_to_kobj(>pdev->kobj,
> - >dev.kobj,
> - "ppi");
> - if (rc)
> - goto out_err;
> - }
> -
>   /* Make the chip available. */
>   spin_lock(_lock);
>   list_add_tail_rcu(>list, _chip_list);
> @@ -241,6 +233,16 @@ int tpm_chip_register(struct tpm_chip *chip)
>  
>   chip->flags |= TPM_CHIP_FLAG_REGISTERED;
>  
> + if (!(chip->flags & TPM_CHIP_FLAG_TPM2)) {
> + rc = __compat_only_sysfs_link_entry_to_kobj(>pdev->kobj,
> + >dev.kobj,
> + "ppi");
> + if (rc && rc != -ENOENT) {
> + tpm_chip_unregister(chip);
> + return rc;
> + }
> + }
> +
>   return 0;
>  out_err:
>   tpm1_chip_unregister(chip);
> -- 
> 2.5.0
> 

This patch doesn't apply to the latest linux-next (20151109).  I think I
may be missing a dependent patch.  Do you know which one?

-- 
- Jeremiah Mahler
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH] tpm: fix compat 'ppi' link handling in tpm_chip_register()

2015-11-09 Thread Jarkko Sakkinen
On Mon, Nov 09, 2015 at 10:11:41PM -0800, Jeremiah Mahler wrote:
> Jarkko,
> 
> On Sun, Nov 08, 2015 at 09:51:07AM +0200, Jarkko Sakkinen wrote:
> > __compat_only_sysfs_link_entry_to_kobj() was unconditionally called for
> > TPM1 chips, which caused crash on Acer C720 laptop where DSM for the
> > ACPI object did not exist.
> > 
> > There are two reasons for unwanted behavior:
> > 
> > * The code did not check whether
> >   __compat_only_sysfs_link_entry_to_kobj() returned -ENOENT. This is
> >   OK. It just meanst that ppi is not available.
> > * The code did not clean up properly. Compat link should added only
> >   after all other init is done.
> > 
> > This patch sorts out these issues.
> > 
> > Fixes: 9b774d5cf2db
> > Reported-by: Jeremiah Mahler 
> > Signed-off-by: Jarkko Sakkinen 
> > Tested-by: Jeremiah Mahler 
> > ---
> >  drivers/char/tpm/tpm-chip.c | 18 ++
> >  1 file changed, 10 insertions(+), 8 deletions(-)
> > 
> > diff --git a/drivers/char/tpm/tpm-chip.c b/drivers/char/tpm/tpm-chip.c
> > index a5cdce7..45cc39a 100644
> > --- a/drivers/char/tpm/tpm-chip.c
> > +++ b/drivers/char/tpm/tpm-chip.c
> > @@ -226,14 +226,6 @@ int tpm_chip_register(struct tpm_chip *chip)
> > if (rc)
> > goto out_err;
> >  
> > -   if (!(chip->flags & TPM_CHIP_FLAG_TPM2)) {
> > -   rc = __compat_only_sysfs_link_entry_to_kobj(>pdev->kobj,
> > -   >dev.kobj,
> > -   "ppi");
> > -   if (rc)
> > -   goto out_err;
> > -   }
> > -
> > /* Make the chip available. */
> > spin_lock(_lock);
> > list_add_tail_rcu(>list, _chip_list);
> > @@ -241,6 +233,16 @@ int tpm_chip_register(struct tpm_chip *chip)
> >  
> > chip->flags |= TPM_CHIP_FLAG_REGISTERED;
> >  
> > +   if (!(chip->flags & TPM_CHIP_FLAG_TPM2)) {
> > +   rc = __compat_only_sysfs_link_entry_to_kobj(>pdev->kobj,
> > +   >dev.kobj,
> > +   "ppi");
> > +   if (rc && rc != -ENOENT) {
> > +   tpm_chip_unregister(chip);
> > +   return rc;
> > +   }
> > +   }
> > +
> > return 0;
> >  out_err:
> > tpm1_chip_unregister(chip);
> > -- 
> > 2.5.0
> > 
> 
> This patch doesn't apply to the latest linux-next (20151109).  I think I
> may be missing a dependent patch.  Do you know which one?

It is expected as there are 7 other bug fixes that I'm including to the
next pull rquest and this is on top.

> - Jeremiah Mahler

/Jarkko
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH] tpm: fix compat 'ppi' link handling in tpm_chip_register()

2015-11-09 Thread Jason Gunthorpe
On Sun, Nov 08, 2015 at 09:51:07AM +0200, Jarkko Sakkinen wrote:
> + if (rc && rc != -ENOENT) {
> + tpm_chip_unregister(chip);
> + return rc;
> + }
> + }

This is still goofy looking, the list_add_tail_rcu should be the last
thing done and cannot fail. Just code this with the usual goto based
unwind and goto to do tpm_dev_del_device for the above failure.

> +
>   return 0;
>  out_err:
>   tpm1_chip_unregister(chip);

Which avoids calling tpm1_chip_unregister and tpm_chip_unregister in
the same function, which looks so wrong to a casual read..

Jason
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH] tpm: fix compat 'ppi' link handling in tpm_chip_register()

2015-11-07 Thread Jarkko Sakkinen
__compat_only_sysfs_link_entry_to_kobj() was unconditionally called for
TPM1 chips, which caused crash on Acer C720 laptop where DSM for the
ACPI object did not exist.

There are two reasons for unwanted behavior:

* The code did not check whether
  __compat_only_sysfs_link_entry_to_kobj() returned -ENOENT. This is
  OK. It just meanst that ppi is not available.
* The code did not clean up properly. Compat link should added only
  after all other init is done.

This patch sorts out these issues.

Fixes: 9b774d5cf2db
Reported-by: Jeremiah Mahler 
Signed-off-by: Jarkko Sakkinen 
Tested-by: Jeremiah Mahler 
---
 drivers/char/tpm/tpm-chip.c | 18 ++
 1 file changed, 10 insertions(+), 8 deletions(-)

diff --git a/drivers/char/tpm/tpm-chip.c b/drivers/char/tpm/tpm-chip.c
index a5cdce7..45cc39a 100644
--- a/drivers/char/tpm/tpm-chip.c
+++ b/drivers/char/tpm/tpm-chip.c
@@ -226,14 +226,6 @@ int tpm_chip_register(struct tpm_chip *chip)
if (rc)
goto out_err;
 
-   if (!(chip->flags & TPM_CHIP_FLAG_TPM2)) {
-   rc = __compat_only_sysfs_link_entry_to_kobj(>pdev->kobj,
-   >dev.kobj,
-   "ppi");
-   if (rc)
-   goto out_err;
-   }
-
/* Make the chip available. */
spin_lock(_lock);
list_add_tail_rcu(>list, _chip_list);
@@ -241,6 +233,16 @@ int tpm_chip_register(struct tpm_chip *chip)
 
chip->flags |= TPM_CHIP_FLAG_REGISTERED;
 
+   if (!(chip->flags & TPM_CHIP_FLAG_TPM2)) {
+   rc = __compat_only_sysfs_link_entry_to_kobj(>pdev->kobj,
+   >dev.kobj,
+   "ppi");
+   if (rc && rc != -ENOENT) {
+   tpm_chip_unregister(chip);
+   return rc;
+   }
+   }
+
return 0;
 out_err:
tpm1_chip_unregister(chip);
-- 
2.5.0

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH] tpm: fix compat 'ppi' link handling in tpm_chip_register()

2015-11-07 Thread Jarkko Sakkinen
__compat_only_sysfs_link_entry_to_kobj() was unconditionally called for
TPM1 chips, which caused crash on Acer C720 laptop where DSM for the
ACPI object did not exist.

There are two reasons for unwanted behavior:

* The code did not check whether
  __compat_only_sysfs_link_entry_to_kobj() returned -ENOENT. This is
  OK. It just meanst that ppi is not available.
* The code did not clean up properly. Compat link should added only
  after all other init is done.

This patch sorts out these issues.

Fixes: 9b774d5cf2db
Reported-by: Jeremiah Mahler 
Signed-off-by: Jarkko Sakkinen 
Tested-by: Jeremiah Mahler 
---
 drivers/char/tpm/tpm-chip.c | 18 ++
 1 file changed, 10 insertions(+), 8 deletions(-)

diff --git a/drivers/char/tpm/tpm-chip.c b/drivers/char/tpm/tpm-chip.c
index a5cdce7..45cc39a 100644
--- a/drivers/char/tpm/tpm-chip.c
+++ b/drivers/char/tpm/tpm-chip.c
@@ -226,14 +226,6 @@ int tpm_chip_register(struct tpm_chip *chip)
if (rc)
goto out_err;
 
-   if (!(chip->flags & TPM_CHIP_FLAG_TPM2)) {
-   rc = __compat_only_sysfs_link_entry_to_kobj(>pdev->kobj,
-   >dev.kobj,
-   "ppi");
-   if (rc)
-   goto out_err;
-   }
-
/* Make the chip available. */
spin_lock(_lock);
list_add_tail_rcu(>list, _chip_list);
@@ -241,6 +233,16 @@ int tpm_chip_register(struct tpm_chip *chip)
 
chip->flags |= TPM_CHIP_FLAG_REGISTERED;
 
+   if (!(chip->flags & TPM_CHIP_FLAG_TPM2)) {
+   rc = __compat_only_sysfs_link_entry_to_kobj(>pdev->kobj,
+   >dev.kobj,
+   "ppi");
+   if (rc && rc != -ENOENT) {
+   tpm_chip_unregister(chip);
+   return rc;
+   }
+   }
+
return 0;
 out_err:
tpm1_chip_unregister(chip);
-- 
2.5.0

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/