Skip to contentSkip to conversation

tpm/tpm_tis: Free IRQ if probing fails

PATCH Superseded Jarkko Sakkinen 2 participants 10 messages Apr 12, 2020 – Apr 16, 2020

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 tpm/tpm_tis: Free IRQ if probing fails

Call devm_free_irq() if we have to revert to polling in order not to unnecessarily reserve the IRQ for the life-cycle of the driver.

Fixes e3837e74a06d ("tpm_tis: Refactor the interrupt setup")
---
 drivers/char/tpm/tpm_tis_core.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/char/tpm/tpm_tis_core.c +4 -1
index 27c6ca031e23..ae6868e7b696 100644
@@ -1062,9 +1062,12 @@ int tpm_tis_core_init(struct device *dev, struct tpm_tis_data *priv, int irq,
 		if (irq) {
 			tpm_tis_probe_irq_single(chip, intmask, IRQF_SHARED,
 						 irq);
-			if (!(chip->flags & TPM_CHIP_FLAG_IRQ))
+			if (!(chip->flags & TPM_CHIP_FLAG_IRQ)) {
 				dev_err(&chip->dev, FW_BUG
 					"TPM interrupt not working, polling instead\n");
+				devm_free_irq(chip->dev.parent, priv->irq,
+					      chip);
+			}
 		} else {
 			tpm_tis_probe_irq(chip, intmask);
 		}
Signature · 1 line
2.25.1
#1 lore raw

Hi Jarkko,

Quoted 16 lines · Jarkko Sakkinen

Call devm_free_irq() if we have to revert to polling in order not to unnecessarily reserve the IRQ for the life-cycle of the driver.

Fixes e3837e74a06d ("tpm_tis: Refactor the interrupt setup")
---
  drivers/char/tpm/tpm_tis_core.c | 5 ++++-
  1 file changed, 4 insertions(+), 1 deletion(-)
drivers/char/tpm/tpm_tis_core.c +0 -0
index 27c6ca031e23..ae6868e7b696 100644

drivers/char/tpm/tpm_tis_core.c int tpm_tis_core_init(struct device *dev, struct tpm_tis_data *priv, int irq, · line 1070

Quoted 10 lines
drivers/char/tpm/tpm_tis_core.c +4 -1
@@ -1062,9 +1062,12 @@ int tpm_tis_core_init(struct device *dev, struct tpm_tis_data *priv, int irq,
  		if (irq) {
  			tpm_tis_probe_irq_single(chip, intmask, IRQF_SHARED,
  						 irq);
-			if (!(chip->flags & TPM_CHIP_FLAG_IRQ))
+			if (!(chip->flags & TPM_CHIP_FLAG_IRQ)) {
  				dev_err(&chip->dev, FW_BUG
  					"TPM interrupt not working, polling instead\n");
+				devm_free_irq(chip->dev.parent, priv->irq,
+					      chip);
+			}

My initial plan was actually to do something similar, but if the probe code is actually ever fixed to work as intended again then this will lead to a double free as then the IRQ-test path of tpm_tis_send() will have called disable_interrupts() which already calls devm_free_irq().

You could check for chip->irq != 0 here to avoid that.

But it all is rather messy, which is why I went with the "#if 0" approach in my patch.

Also we will currently ALWAYS hit the "TPM interrupt not working, polling instead" error because the TPM_CHIP_FLAG_IRQ never gets set. So if we are going to do an interim fix (and we should) we should really also silence that error.

Regards,

Hans

p.s.

I'm currently in contact with Lenovo trying to figure out what is going on here with the always firing IRQ on the X1 8th gen, I guess the fix for that might also help with the T490 issue.

#2 lore raw
Quoted 35 lines · Hans de Goede

Hi Jarkko,

Quoted 16 lines · Jarkko Sakkinen

Call devm_free_irq() if we have to revert to polling in order not to unnecessarily reserve the IRQ for the life-cycle of the driver.

Fixes e3837e74a06d ("tpm_tis: Refactor the interrupt setup")
---
  drivers/char/tpm/tpm_tis_core.c | 5 ++++-
  1 file changed, 4 insertions(+), 1 deletion(-)
drivers/char/tpm/tpm_tis_core.c +0 -0
index 27c6ca031e23..ae6868e7b696 100644

drivers/char/tpm/tpm_tis_core.c int tpm_tis_core_init(struct device *dev, struct tpm_tis_data *priv, int irq, · line 1070

Quoted 10 lines
drivers/char/tpm/tpm_tis_core.c +4 -1
@@ -1062,9 +1062,12 @@ int tpm_tis_core_init(struct device *dev, struct tpm_tis_data *priv, int irq,
  		if (irq) {
  			tpm_tis_probe_irq_single(chip, intmask, IRQF_SHARED,
  						 irq);
-			if (!(chip->flags & TPM_CHIP_FLAG_IRQ))
+			if (!(chip->flags & TPM_CHIP_FLAG_IRQ)) {
  				dev_err(&chip->dev, FW_BUG
  					"TPM interrupt not working, polling instead\n");
+				devm_free_irq(chip->dev.parent, priv->irq,
+					      chip);
+			}

My initial plan was actually to do something similar, but if the probe code is actually ever fixed to work as intended again then this will lead to a double free as then the IRQ-test path of tpm_tis_send() will have called disable_interrupts() which already calls devm_free_irq().

Quoted 4 lines

You could check for chip->irq != 0 here to avoid that.

But it all is rather messy, which is why I went with the "#if 0" approach in my patch.

I think it is right way to fix it. It is a bug independent of the issue we are experiencing.

However, what you are suggesting should be done in addition. Do you have a patch in place or do you want me to refine mine?

/Jarkko

#3 lore raw

Hi,

Quoted 38 lines · Jarkko Sakkinen
Quoted 37 lines · Hans de Goede

Hi Jarkko,

Quoted 16 lines · Jarkko Sakkinen

Call devm_free_irq() if we have to revert to polling in order not to unnecessarily reserve the IRQ for the life-cycle of the driver.

Fixes e3837e74a06d ("tpm_tis: Refactor the interrupt setup")
---
   drivers/char/tpm/tpm_tis_core.c | 5 ++++-
   1 file changed, 4 insertions(+), 1 deletion(-)
drivers/char/tpm/tpm_tis_core.c +0 -0
index 27c6ca031e23..ae6868e7b696 100644

drivers/char/tpm/tpm_tis_core.c int tpm_tis_core_init(struct device *dev, struct tpm_tis_data *priv, int irq, · line 1070

Quoted 10 lines
drivers/char/tpm/tpm_tis_core.c +4 -1
@@ -1062,9 +1062,12 @@ int tpm_tis_core_init(struct device *dev, struct tpm_tis_data *priv, int irq,
   		if (irq) {
   			tpm_tis_probe_irq_single(chip, intmask, IRQF_SHARED,
   						 irq);
-			if (!(chip->flags & TPM_CHIP_FLAG_IRQ))
+			if (!(chip->flags & TPM_CHIP_FLAG_IRQ)) {
   				dev_err(&chip->dev, FW_BUG
   					"TPM interrupt not working, polling instead\n");
+				devm_free_irq(chip->dev.parent, priv->irq,
+					      chip);
+			}

My initial plan was actually to do something similar, but if the probe code is actually ever fixed to work as intended again then this will lead to a double free as then the IRQ-test path of tpm_tis_send() will have called disable_interrupts() which already calls devm_free_irq().

You could check for chip->irq != 0 here to avoid that.

Quoted 8 lines
Quoted 2 lines

But it all is rather messy, which is why I went with the "#if 0" approach in my patch.

I think it is right way to fix it. It is a bug independent of the issue we are experiencing.

However, what you are suggesting should be done in addition. Do you have a patch in place or do you want me to refine mine?

I do not have a patch ready for this, if you can refine yours that would be great.

Regards,

Hans

#4 lore raw
Quoted 44 lines · Hans de Goede

Hi,

Quoted 41 lines · Jarkko Sakkinen
Quoted 39 lines · Hans de Goede

Hi Jarkko,

Quoted 16 lines · Jarkko Sakkinen

Call devm_free_irq() if we have to revert to polling in order not to unnecessarily reserve the IRQ for the life-cycle of the driver.

Fixes e3837e74a06d ("tpm_tis: Refactor the interrupt setup")
---
   drivers/char/tpm/tpm_tis_core.c | 5 ++++-
   1 file changed, 4 insertions(+), 1 deletion(-)
drivers/char/tpm/tpm_tis_core.c +0 -0
index 27c6ca031e23..ae6868e7b696 100644

drivers/char/tpm/tpm_tis_core.c int tpm_tis_core_init(struct device *dev, struct tpm_tis_data *priv, int irq, · line 1070

Quoted 10 lines
drivers/char/tpm/tpm_tis_core.c +4 -1
@@ -1062,9 +1062,12 @@ int tpm_tis_core_init(struct device *dev, struct tpm_tis_data *priv, int irq,
   		if (irq) {
   			tpm_tis_probe_irq_single(chip, intmask, IRQF_SHARED,
   						 irq);
-			if (!(chip->flags & TPM_CHIP_FLAG_IRQ))
+			if (!(chip->flags & TPM_CHIP_FLAG_IRQ)) {
   				dev_err(&chip->dev, FW_BUG
   					"TPM interrupt not working, polling instead\n");
+				devm_free_irq(chip->dev.parent, priv->irq,
+					      chip);
+			}

My initial plan was actually to do something similar, but if the probe code is actually ever fixed to work as intended again then this will lead to a double free as then the IRQ-test path of tpm_tis_send() will have called disable_interrupts() which already calls devm_free_irq().

You could check for chip->irq != 0 here to avoid that.

But it all is rather messy, which is why I went with the "#if 0" approach in my patch.

Quoted 8 lines
Quoted 5 lines

I think it is right way to fix it. It is a bug independent of the issue we are experiencing.

However, what you are suggesting should be done in addition. Do you have a patch in place or do you want me to refine mine?

I do not have a patch ready for this, if you can refine yours that would be great.

Thanks! Just wanted to confirm.

/Jarkko

#5 lore raw

Hi,

Quoted 40 lines · Jarkko Sakkinen
Quoted 39 lines · Hans de Goede

Hi,

Quoted 36 lines · Jarkko Sakkinen
Quoted 35 lines · Hans de Goede

Hi Jarkko,

Quoted 16 lines · Jarkko Sakkinen

Call devm_free_irq() if we have to revert to polling in order not to unnecessarily reserve the IRQ for the life-cycle of the driver.

Fixes e3837e74a06d ("tpm_tis: Refactor the interrupt setup")
---
    drivers/char/tpm/tpm_tis_core.c | 5 ++++-
    1 file changed, 4 insertions(+), 1 deletion(-)
drivers/char/tpm/tpm_tis_core.c +0 -0
index 27c6ca031e23..ae6868e7b696 100644

drivers/char/tpm/tpm_tis_core.c int tpm_tis_core_init(struct device *dev, struct tpm_tis_data *priv, int irq, · line 1070

Quoted 10 lines
drivers/char/tpm/tpm_tis_core.c +4 -1
@@ -1062,9 +1062,12 @@ int tpm_tis_core_init(struct device *dev, struct tpm_tis_data *priv, int irq,
    		if (irq) {
    			tpm_tis_probe_irq_single(chip, intmask, IRQF_SHARED,
    						 irq);
-			if (!(chip->flags & TPM_CHIP_FLAG_IRQ))
+			if (!(chip->flags & TPM_CHIP_FLAG_IRQ)) {
    				dev_err(&chip->dev, FW_BUG
    					"TPM interrupt not working, polling instead\n");
+				devm_free_irq(chip->dev.parent, priv->irq,
+					      chip);
+			}

My initial plan was actually to do something similar, but if the probe code is actually ever fixed to work as intended again then this will lead to a double free as then the IRQ-test path of tpm_tis_send() will have called disable_interrupts() which already calls devm_free_irq().

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

You could check for chip->irq != 0 here to avoid that.

Erm in case you haven't figured it out yet this should be priv->irq != 0, sorry.

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 3 lines

But it all is rather messy, which is why I went with the "#if 0" approach in my patch.

I think it is right way to fix it. It is a bug independent of the issue we are experiencing.

Quoted 7 lines
Quoted 5 lines
Quoted 2 lines

However, what you are suggesting should be done in addition. Do you have a patch in place or do you want me to refine mine?

I do not have a patch ready for this, if you can refine yours that would be great.

Thanks! Just wanted to confirm.

And thank you for working on a (temporary?) fix for this.

Regards,

Hans

#6 lore raw
Quoted 43 lines · Hans de Goede

Hi,

Quoted 40 lines · Jarkko Sakkinen
Quoted 39 lines · Hans de Goede

Hi,

Quoted 36 lines · Jarkko Sakkinen
Quoted 35 lines · Hans de Goede

Hi Jarkko,

Quoted 16 lines · Jarkko Sakkinen

Call devm_free_irq() if we have to revert to polling in order not to unnecessarily reserve the IRQ for the life-cycle of the driver.

Fixes e3837e74a06d ("tpm_tis: Refactor the interrupt setup")
---
    drivers/char/tpm/tpm_tis_core.c | 5 ++++-
    1 file changed, 4 insertions(+), 1 deletion(-)
drivers/char/tpm/tpm_tis_core.c +0 -0
index 27c6ca031e23..ae6868e7b696 100644

drivers/char/tpm/tpm_tis_core.c int tpm_tis_core_init(struct device *dev, struct tpm_tis_data *priv, int irq, · line 1070

Quoted 10 lines
drivers/char/tpm/tpm_tis_core.c +4 -1
@@ -1062,9 +1062,12 @@ int tpm_tis_core_init(struct device *dev, struct tpm_tis_data *priv, int irq,
    		if (irq) {
    			tpm_tis_probe_irq_single(chip, intmask, IRQF_SHARED,
    						 irq);
-			if (!(chip->flags & TPM_CHIP_FLAG_IRQ))
+			if (!(chip->flags & TPM_CHIP_FLAG_IRQ)) {
    				dev_err(&chip->dev, FW_BUG
    					"TPM interrupt not working, polling instead\n");
+				devm_free_irq(chip->dev.parent, priv->irq,
+					      chip);
+			}

My initial plan was actually to do something similar, but if the probe code is actually ever fixed to work as intended again then this will lead to a double free as then the IRQ-test path of tpm_tis_send() will have called disable_interrupts() which already calls devm_free_irq().

Quoted 3 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

You could check for chip->irq != 0 here to avoid that.

Erm in case you haven't figured it out yet this should be priv->irq != 0, sorry.

Yup.

Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 9 lines
Quoted 3 lines

But it all is rather messy, which is why I went with the "#if 0" approach in my patch.

I think it is right way to fix it. It is a bug independent of the issue we are experiencing.

However, what you are suggesting should be done in addition. Do you have a patch in place or do you want me to refine mine?

Quoted 6 lines
Quoted 4 lines
Quoted 2 lines

I do not have a patch ready for this, if you can refine yours that would be great.

Thanks! Just wanted to confirm.

And thank you for working on a (temporary?) fix for this.

As far as I see it, it is orthogonal fix that needs to be backported to stable kernels. This bug predates the issue we're seeing now.

/Jarkko

#7 lore raw
Quoted 63 lines · Jarkko Sakkinen
Quoted 43 lines · Hans de Goede

Hi,

Quoted 40 lines · Jarkko Sakkinen
Quoted 39 lines · Hans de Goede

Hi,

Quoted 36 lines · Jarkko Sakkinen
Quoted 35 lines · Hans de Goede

Hi Jarkko,

Quoted 16 lines · Jarkko Sakkinen

Call devm_free_irq() if we have to revert to polling in order not to unnecessarily reserve the IRQ for the life-cycle of the driver.

Fixes e3837e74a06d ("tpm_tis: Refactor the interrupt setup")
---
    drivers/char/tpm/tpm_tis_core.c | 5 ++++-
    1 file changed, 4 insertions(+), 1 deletion(-)
drivers/char/tpm/tpm_tis_core.c +0 -0
index 27c6ca031e23..ae6868e7b696 100644

drivers/char/tpm/tpm_tis_core.c int tpm_tis_core_init(struct device *dev, struct tpm_tis_data *priv, int irq, · line 1070

Quoted 10 lines
drivers/char/tpm/tpm_tis_core.c +4 -1
@@ -1062,9 +1062,12 @@ int tpm_tis_core_init(struct device *dev, struct tpm_tis_data *priv, int irq,
    		if (irq) {
    			tpm_tis_probe_irq_single(chip, intmask, IRQF_SHARED,
    						 irq);
-			if (!(chip->flags & TPM_CHIP_FLAG_IRQ))
+			if (!(chip->flags & TPM_CHIP_FLAG_IRQ)) {
    				dev_err(&chip->dev, FW_BUG
    					"TPM interrupt not working, polling instead\n");
+				devm_free_irq(chip->dev.parent, priv->irq,
+					      chip);
+			}

My initial plan was actually to do something similar, but if the probe code is actually ever fixed to work as intended again then this will lead to a double free as then the IRQ-test path of tpm_tis_send() will have called disable_interrupts() which already calls devm_free_irq().

Quoted 3 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

You could check for chip->irq != 0 here to avoid that.

Erm in case you haven't figured it out yet this should be priv->irq != 0, sorry.

Yup.

Quoted 13 lines
Quoted 13 lines
Quoted 12 lines
Quoted 9 lines
Quoted 3 lines

But it all is rather messy, which is why I went with the "#if 0" approach in my patch.

I think it is right way to fix it. It is a bug independent of the issue we are experiencing.

However, what you are suggesting should be done in addition. Do you have a patch in place or do you want me to refine mine?

I do not have a patch ready for this, if you can refine yours that would be great.

Quoted 6 lines
Quoted 3 lines
Quoted 1 line

Thanks! Just wanted to confirm.

And thank you for working on a (temporary?) fix for this.

As far as I see it, it is orthogonal fix that needs to be backported to stable kernels. This bug predates the issue we're seeing now.

Hey, I came to other thoughts on "how". Would probably make sense to always call disable_interrupts() aka no sense to add two separate code paths. What do you think?

/Jarkko

#8 lore raw

Hi,

Quoted 66 lines · Jarkko Sakkinen
Quoted 65 lines · Jarkko Sakkinen
Quoted 43 lines · Hans de Goede

Hi,

Quoted 40 lines · Jarkko Sakkinen
Quoted 39 lines · Hans de Goede

Hi,

Quoted 36 lines · Jarkko Sakkinen
Quoted 35 lines · Hans de Goede

Hi Jarkko,

Quoted 16 lines · Jarkko Sakkinen

Call devm_free_irq() if we have to revert to polling in order not to unnecessarily reserve the IRQ for the life-cycle of the driver.

Fixes e3837e74a06d ("tpm_tis: Refactor the interrupt setup")
---
     drivers/char/tpm/tpm_tis_core.c | 5 ++++-
     1 file changed, 4 insertions(+), 1 deletion(-)
drivers/char/tpm/tpm_tis_core.c +0 -0
index 27c6ca031e23..ae6868e7b696 100644

drivers/char/tpm/tpm_tis_core.c int tpm_tis_core_init(struct device *dev, struct tpm_tis_data *priv, int irq, · line 1070

Quoted 10 lines
drivers/char/tpm/tpm_tis_core.c +4 -1
@@ -1062,9 +1062,12 @@ int tpm_tis_core_init(struct device *dev, struct tpm_tis_data *priv, int irq,
     		if (irq) {
     			tpm_tis_probe_irq_single(chip, intmask, IRQF_SHARED,
     						 irq);
-			if (!(chip->flags & TPM_CHIP_FLAG_IRQ))
+			if (!(chip->flags & TPM_CHIP_FLAG_IRQ)) {
     				dev_err(&chip->dev, FW_BUG
     					"TPM interrupt not working, polling instead\n");
+				devm_free_irq(chip->dev.parent, priv->irq,
+					      chip);
+			}

My initial plan was actually to do something similar, but if the probe code is actually ever fixed to work as intended again then this will lead to a double free as then the IRQ-test path of tpm_tis_send() will have called disable_interrupts() which already calls devm_free_irq().

Quoted 3 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

You could check for chip->irq != 0 here to avoid that.

Erm in case you haven't figured it out yet this should be priv->irq != 0, sorry.

Yup.

Quoted 15 lines
Quoted 14 lines
Quoted 4 lines
Quoted 4 lines
Quoted 3 lines

But it all is rather messy, which is why I went with the "#if 0" approach in my patch.

Quoted 8 lines
Quoted 5 lines

I think it is right way to fix it. It is a bug independent of the issue we are experiencing.

However, what you are suggesting should be done in addition. Do you have a patch in place or do you want me to refine mine?

I do not have a patch ready for this, if you can refine yours that would be great.

Thanks! Just wanted to confirm.

Quoted 8 lines
Quoted 4 lines
Quoted 1 line

And thank you for working on a (temporary?) fix for this.

As far as I see it, it is orthogonal fix that needs to be backported to stable kernels. This bug predates the issue we're seeing now.

Hey, I came to other thoughts on "how". Would probably make sense to always call disable_interrupts() aka no sense to add two separate code paths. What do you think?

Sounds good, I guess it would be best to combine that with a:

	if (priv->irq == 0)
		return;

At the top of disable_interrupts() and then unconditionally call disable_interrupts() where your v1 of this patch calls devm_free_irq(). That would be a reasonable clean solution I think.

Regards,

Hans

#9 lore raw
Quoted 9 lines · Hans de Goede

Sounds good, I guess it would be best to combine that with a:

	if (priv->irq == 0)
		return;

At the top of disable_interrupts() and then unconditionally call disable_interrupts() where your v1 of this patch calls devm_free_irq(). That would be a reasonable clean solution I think.

Great, this was my plan (just wanted to double check).

/Jarkko