[v11,05/14] tpm, tpm_tis: Claim locality before writing interrupt registers

Message ID 20221124135538.31020-6-LinoSanfilippo@gmx.de
State New
Headers
Series TPM IRQ fixes |

Commit Message

Lino Sanfilippo Nov. 24, 2022, 1:55 p.m. UTC
  From: Lino Sanfilippo <l.sanfilippo@kunbus.com>

In tpm_tis_probe_single_irq() interrupt registers TPM_INT_VECTOR,
TPM_INT_STATUS and TPM_INT_ENABLE are modified to setup the interrupts.
Currently these modifications are done without holding a locality thus they
have no effect. Fix this by claiming the (default) locality before the
registers are written.

Since now tpm_tis_gen_interrupt() is called with the locality already
claimed remove locality request and release from this function.

Signed-off-by: Lino Sanfilippo <l.sanfilippo@kunbus.com>
Reviewed-by: Jarkko Sakkinen <jarkko@kernel.org>
---
 drivers/char/tpm/tpm_tis_core.c | 20 +++++++++++---------
 1 file changed, 11 insertions(+), 9 deletions(-)
  

Comments

kernel test robot Nov. 24, 2022, 3:21 p.m. UTC | #1
Hi Lino,

I love your patch! Perhaps something to improve:

[auto build test WARNING on 30a0b95b1335e12efef89dd78518ed3e4a71a763]

url:    https://github.com/intel-lab-lkp/linux/commits/Lino-Sanfilippo/TPM-IRQ-fixes/20221124-215932
base:   30a0b95b1335e12efef89dd78518ed3e4a71a763
patch link:    https://lore.kernel.org/r/20221124135538.31020-6-LinoSanfilippo%40gmx.de
patch subject: [PATCH v11 05/14] tpm, tpm_tis: Claim locality before writing interrupt registers
config: m68k-allyesconfig
compiler: m68k-linux-gcc (GCC) 12.1.0
reproduce (this is a W=1 build):
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # https://github.com/intel-lab-lkp/linux/commit/aff4f2aead15a8dd374e43112b120603e7008156
        git remote add linux-review https://github.com/intel-lab-lkp/linux
        git fetch --no-tags linux-review Lino-Sanfilippo/TPM-IRQ-fixes/20221124-215932
        git checkout aff4f2aead15a8dd374e43112b120603e7008156
        # save the config file
        mkdir build_dir && cp config build_dir/.config
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-12.1.0 make.cross W=1 O=build_dir ARCH=m68k SHELL=/bin/bash drivers/char/tpm/

If you fix the issue, kindly add following tag where applicable
| Reported-by: kernel test robot <lkp@intel.com>

All warnings (new ones prefixed by >>):

   drivers/char/tpm/tpm_tis_core.c: In function 'tpm_tis_gen_interrupt':
>> drivers/char/tpm/tpm_tis_core.c:737:13: warning: variable 'ret' set but not used [-Wunused-but-set-variable]
     737 |         int ret;
         |             ^~~


vim +/ret +737 drivers/char/tpm/tpm_tis_core.c

41a5e1cf1fe151 Christophe Ricard 2016-05-19  731  
c80ceaa1aa1671 Lino Sanfilippo   2022-11-24  732  static void tpm_tis_gen_interrupt(struct tpm_chip *chip)
eb5854e764b91a Jarkko Sakkinen   2016-06-12  733  {
eb5854e764b91a Jarkko Sakkinen   2016-06-12  734  	const char *desc = "attempting to generate an interrupt";
eb5854e764b91a Jarkko Sakkinen   2016-06-12  735  	u32 cap2;
eb5854e764b91a Jarkko Sakkinen   2016-06-12  736  	cap_t cap;
d53a6adfb55396 Lukasz Majczak    2021-02-16 @737  	int ret;
eb5854e764b91a Jarkko Sakkinen   2016-06-12  738  
e630af7dfb450d Jarkko Sakkinen   2021-05-10  739  	if (chip->flags & TPM_CHIP_FLAG_TPM2)
e630af7dfb450d Jarkko Sakkinen   2021-05-10  740  		ret = tpm2_get_tpm_pt(chip, 0x100, &cap2, desc);
e630af7dfb450d Jarkko Sakkinen   2021-05-10  741  	else
d53a6adfb55396 Lukasz Majczak    2021-02-16  742  		ret = tpm1_getcap(chip, TPM_CAP_PROP_TIS_TIMEOUT, &cap, desc, 0);
eb5854e764b91a Jarkko Sakkinen   2016-06-12  743  }
eb5854e764b91a Jarkko Sakkinen   2016-06-12  744
  

Patch

diff --git a/drivers/char/tpm/tpm_tis_core.c b/drivers/char/tpm/tpm_tis_core.c
index 81b9726d3ed2..49848268f547 100644
--- a/drivers/char/tpm/tpm_tis_core.c
+++ b/drivers/char/tpm/tpm_tis_core.c
@@ -736,16 +736,10 @@  static void tpm_tis_gen_interrupt(struct tpm_chip *chip)
 	cap_t cap;
 	int ret;
 
-	ret = request_locality(chip, 0);
-	if (ret < 0)
-		return;
-
 	if (chip->flags & TPM_CHIP_FLAG_TPM2)
 		ret = tpm2_get_tpm_pt(chip, 0x100, &cap2, desc);
 	else
 		ret = tpm1_getcap(chip, TPM_CAP_PROP_TIS_TIMEOUT, &cap, desc, 0);
-
-	release_locality(chip, 0);
 }
 
 /* Register the IRQ and issue a command that will cause an interrupt. If an
@@ -768,10 +762,16 @@  static int tpm_tis_probe_irq_single(struct tpm_chip *chip, u32 intmask,
 	}
 	priv->irq = irq;
 
+	rc = request_locality(chip, 0);
+	if (rc < 0)
+		return rc;
+
 	rc = tpm_tis_read8(priv, TPM_INT_VECTOR(priv->locality),
 			   &original_int_vec);
-	if (rc < 0)
+	if (rc < 0) {
+		release_locality(chip, priv->locality);
 		return rc;
+	}
 
 	rc = tpm_tis_write8(priv, TPM_INT_VECTOR(priv->locality), irq);
 	if (rc < 0)
@@ -805,10 +805,12 @@  static int tpm_tis_probe_irq_single(struct tpm_chip *chip, u32 intmask,
 	if (!(chip->flags & TPM_CHIP_FLAG_IRQ)) {
 		tpm_tis_write8(priv, original_int_vec,
 			       TPM_INT_VECTOR(priv->locality));
-		return -1;
+		rc = -1;
 	}
 
-	return 0;
+	release_locality(chip, priv->locality);
+
+	return rc;
 }
 
 /* Try to find the IRQ the TPM is using. This is for legacy x86 systems that