[v2] tpm/st33zp24: Fix the name collisions in tpm_st33zp24_spi and tpm_i2c_infineon
diff mbox series

Message ID 20190204133749.14176-1-jarkko.sakkinen@linux.intel.com
State New
Headers show
Series
  • [v2] tpm/st33zp24: Fix the name collisions in tpm_st33zp24_spi and tpm_i2c_infineon
Related show

Commit Message

Jarkko Sakkinen Feb. 4, 2019, 1:37 p.m. UTC
Rename TPM_BUFSIZE defined in drivers/char/tpm/st33zp24/st33zp24.h to
ST33ZP24_BUFSIZE.

Rename TPM_BUFSIZE defined in drivers/char/tpm/tpm_i2c_infineon.c to
TPM_I2C_INFINEON_BUFSIZE.

Cc: stable@vger.kernel.org
Fixes: bf38b8710892 ("tpm/tpm_i2c_stm_st33: Split tpm_i2c_tpm_st33 in 2 layers (core + phy)")
Fixes: aad628c1d91a ("char/tpm: Add new driver for Infineon I2C TIS TPM")
Signed-off-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
---
v2: Fix also the name collision in tpm_ic2_infineon.
 drivers/char/tpm/st33zp24/i2c.c      |  2 +-
 drivers/char/tpm/st33zp24/spi.c      |  2 +-
 drivers/char/tpm/st33zp24/st33zp24.h |  4 ++--
 drivers/char/tpm/tpm_i2c_infineon.c  | 15 ++++++++-------
 4 files changed, 12 insertions(+), 11 deletions(-)

Comments

Roberto Sassu Feb. 4, 2019, 1:49 p.m. UTC | #1
On 2/4/2019 2:37 PM, Jarkko Sakkinen wrote:
> Rename TPM_BUFSIZE defined in drivers/char/tpm/st33zp24/st33zp24.h to
> ST33ZP24_BUFSIZE.
> 
> Rename TPM_BUFSIZE defined in drivers/char/tpm/tpm_i2c_infineon.c to
> TPM_I2C_INFINEON_BUFSIZE.

Please also add a prefix to TPM_RETRY in tpm_i2c_nuvoton.c.

Thanks

Roberto


> Cc: stable@vger.kernel.org
> Fixes: bf38b8710892 ("tpm/tpm_i2c_stm_st33: Split tpm_i2c_tpm_st33 in 2 layers (core + phy)")
> Fixes: aad628c1d91a ("char/tpm: Add new driver for Infineon I2C TIS TPM")
> Signed-off-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
> ---
> v2: Fix also the name collision in tpm_ic2_infineon.
>   drivers/char/tpm/st33zp24/i2c.c      |  2 +-
>   drivers/char/tpm/st33zp24/spi.c      |  2 +-
>   drivers/char/tpm/st33zp24/st33zp24.h |  4 ++--
>   drivers/char/tpm/tpm_i2c_infineon.c  | 15 ++++++++-------
>   4 files changed, 12 insertions(+), 11 deletions(-)
> 
> diff --git a/drivers/char/tpm/st33zp24/i2c.c b/drivers/char/tpm/st33zp24/i2c.c
> index be5d1abd3e8e..8390c5b54c3b 100644
> --- a/drivers/char/tpm/st33zp24/i2c.c
> +++ b/drivers/char/tpm/st33zp24/i2c.c
> @@ -33,7 +33,7 @@
>   
>   struct st33zp24_i2c_phy {
>   	struct i2c_client *client;
> -	u8 buf[TPM_BUFSIZE + 1];
> +	u8 buf[ST33ZP24_BUFSIZE + 1];
>   	int io_lpcpd;
>   };
>   
> diff --git a/drivers/char/tpm/st33zp24/spi.c b/drivers/char/tpm/st33zp24/spi.c
> index d7909ab287a8..ff019a1e3c68 100644
> --- a/drivers/char/tpm/st33zp24/spi.c
> +++ b/drivers/char/tpm/st33zp24/spi.c
> @@ -63,7 +63,7 @@
>    * some latency byte before the answer is available (max 15).
>    * We have 2048 + 1024 + 15.
>    */
> -#define ST33ZP24_SPI_BUFFER_SIZE (TPM_BUFSIZE + (TPM_BUFSIZE / 2) +\
> +#define ST33ZP24_SPI_BUFFER_SIZE (ST33ZP24_BUFSIZE + (ST33ZP24_BUFSIZE / 2) +\
>   				  MAX_SPI_LATENCY)
>   
>   
> diff --git a/drivers/char/tpm/st33zp24/st33zp24.h b/drivers/char/tpm/st33zp24/st33zp24.h
> index 6f4a4198af6a..20da0a84988d 100644
> --- a/drivers/char/tpm/st33zp24/st33zp24.h
> +++ b/drivers/char/tpm/st33zp24/st33zp24.h
> @@ -18,8 +18,8 @@
>   #ifndef __LOCAL_ST33ZP24_H__
>   #define __LOCAL_ST33ZP24_H__
>   
> -#define TPM_WRITE_DIRECTION             0x80
> -#define TPM_BUFSIZE                     2048
> +#define TPM_WRITE_DIRECTION	0x80
> +#define ST33ZP24_BUFSIZE	2048
>   
>   struct st33zp24_dev {
>   	struct tpm_chip *chip;
> diff --git a/drivers/char/tpm/tpm_i2c_infineon.c b/drivers/char/tpm/tpm_i2c_infineon.c
> index 9086edc9066b..b9d5a1dda8d2 100644
> --- a/drivers/char/tpm/tpm_i2c_infineon.c
> +++ b/drivers/char/tpm/tpm_i2c_infineon.c
> @@ -26,8 +26,7 @@
>   #include <linux/wait.h>
>   #include "tpm.h"
>   
> -/* max. buffer size supported by our TPM */
> -#define TPM_BUFSIZE 1260
> +#define TPM_I2C_INFINEON_MAX_BUFSIZE 1260
>   
>   /* max. number of iterations after I2C NAK */
>   #define MAX_COUNT 3
> @@ -63,11 +62,13 @@ enum i2c_chip_type {
>   	UNKNOWN,
>   };
>   
> -/* Structure to store I2C TPM specific stuff */
>   struct tpm_inf_dev {
>   	struct i2c_client *client;
>   	int locality;
> -	u8 buf[TPM_BUFSIZE + sizeof(u8)]; /* max. buffer size + addr */
> +	/* In addition to the data itself, the buffer must fit the 7-bit I2C
> +	 * address and the direction bit.
> +	 */
> +	u8 buf[TPM_I2C_INFINEON_MAX_BUFSIZE + 1];
>   	struct tpm_chip *chip;
>   	enum i2c_chip_type chip_type;
>   	unsigned int adapterlimit;
> @@ -219,7 +220,7 @@ static int iic_tpm_write_generic(u8 addr, u8 *buffer, size_t len,
>   		.buf = tpm_dev.buf
>   	};
>   
> -	if (len > TPM_BUFSIZE)
> +	if (len > TPM_I2C_INFINEON_MAX_BUFSIZE)
>   		return -EINVAL;
>   
>   	if (!tpm_dev.client->adapter->algo->master_xfer)
> @@ -527,8 +528,8 @@ static int tpm_tis_i2c_send(struct tpm_chip *chip, u8 *buf, size_t len)
>   	u8 retries = 0;
>   	u8 sts = TPM_STS_GO;
>   
> -	if (len > TPM_BUFSIZE)
> -		return -E2BIG;	/* command is too long for our tpm, sorry */
> +	if (len > TPM_I2C_INFINEON_BUFSIZE)
> +		return -E2BIG;
>   
>   	if (request_locality(chip, 0) < 0)
>   		return -EBUSY;
>
Jarkko Sakkinen Feb. 4, 2019, 11:31 p.m. UTC | #2
On Mon, Feb 04, 2019 at 02:49:54PM +0100, Roberto Sassu wrote:
> On 2/4/2019 2:37 PM, Jarkko Sakkinen wrote:
> > Rename TPM_BUFSIZE defined in drivers/char/tpm/st33zp24/st33zp24.h to
> > ST33ZP24_BUFSIZE.
> > 
> > Rename TPM_BUFSIZE defined in drivers/char/tpm/tpm_i2c_infineon.c to
> > TPM_I2C_INFINEON_BUFSIZE.
> 
> Please also add a prefix to TPM_RETRY in tpm_i2c_nuvoton.c.

Thanks, can do.

/Jarkko
Jarkko Sakkinen Feb. 4, 2019, 11:40 p.m. UTC | #3
On Tue, Feb 05, 2019 at 01:31:17AM +0200, Jarkko Sakkinen wrote:
> On Mon, Feb 04, 2019 at 02:49:54PM +0100, Roberto Sassu wrote:
> > On 2/4/2019 2:37 PM, Jarkko Sakkinen wrote:
> > > Rename TPM_BUFSIZE defined in drivers/char/tpm/st33zp24/st33zp24.h to
> > > ST33ZP24_BUFSIZE.
> > > 
> > > Rename TPM_BUFSIZE defined in drivers/char/tpm/tpm_i2c_infineon.c to
> > > TPM_I2C_INFINEON_BUFSIZE.
> > 
> > Please also add a prefix to TPM_RETRY in tpm_i2c_nuvoton.c.
> 
> Thanks, can do.

TPM_RETRY defined in

  32d33b29ba07 ("TPM: Retry SaveState command in suspend path")

has nothing to do with time. I'll also remove the comment about 5
seconds.

The definitions for TPM_RETRY seem fairly arbitrary. Jason, could
tpm_i2c_nuvoton also use the same constant as tpm_tis_spi and TPM 1.2
suspend, try max 50 times instead of five?

/Jarkko
kbuild test robot Feb. 5, 2019, 7:42 a.m. UTC | #4
Hi Jarkko,

I love your patch! Yet something to improve:

[auto build test ERROR on jss-tpmdd/next]
[also build test ERROR on v5.0-rc4 next-20190204]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]

url:    https://github.com/0day-ci/linux/commits/Jarkko-Sakkinen/tpm-st33zp24-Fix-the-name-collisions-in-tpm_st33zp24_spi-and-tpm_i2c_infineon/20190205-150003
base:   git://git.infradead.org/users/jjs/linux-tpmdd next
config: nds32-allyesconfig (attached as .config)
compiler: nds32le-linux-gcc (GCC) 6.4.0
reproduce:
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # save the attached .config to linux build tree
        GCC_VERSION=6.4.0 make.cross ARCH=nds32 

All errors (new ones prefixed by >>):

   drivers/char/tpm/tpm_i2c_infineon.c: In function 'tpm_tis_i2c_send':
>> drivers/char/tpm/tpm_i2c_infineon.c:531:12: error: 'TPM_I2C_INFINEON_BUFSIZE' undeclared (first use in this function)
     if (len > TPM_I2C_INFINEON_BUFSIZE)
               ^~~~~~~~~~~~~~~~~~~~~~~~
   drivers/char/tpm/tpm_i2c_infineon.c:531:12: note: each undeclared identifier is reported only once for each function it appears in

vim +/TPM_I2C_INFINEON_BUFSIZE +531 drivers/char/tpm/tpm_i2c_infineon.c

   522	
   523	static int tpm_tis_i2c_send(struct tpm_chip *chip, u8 *buf, size_t len)
   524	{
   525		int rc, status;
   526		ssize_t burstcnt;
   527		size_t count = 0;
   528		u8 retries = 0;
   529		u8 sts = TPM_STS_GO;
   530	
 > 531		if (len > TPM_I2C_INFINEON_BUFSIZE)
   532			return -E2BIG;
   533	
   534		if (request_locality(chip, 0) < 0)
   535			return -EBUSY;
   536	
   537		status = tpm_tis_i2c_status(chip);
   538		if ((status & TPM_STS_COMMAND_READY) == 0) {
   539			tpm_tis_i2c_ready(chip);
   540			if (wait_for_stat
   541			    (chip, TPM_STS_COMMAND_READY,
   542			     chip->timeout_b, &status) < 0) {
   543				rc = -ETIME;
   544				goto out_err;
   545			}
   546		}
   547	
   548		while (count < len - 1) {
   549			burstcnt = get_burstcount(chip);
   550	
   551			/* burstcnt < 0 = TPM is busy */
   552			if (burstcnt < 0)
   553				return burstcnt;
   554	
   555			if (burstcnt > (len - 1 - count))
   556				burstcnt = len - 1 - count;
   557	
   558			rc = iic_tpm_write(TPM_DATA_FIFO(tpm_dev.locality),
   559					   &(buf[count]), burstcnt);
   560			if (rc == 0)
   561				count += burstcnt;
   562			else if (rc < 0)
   563				retries++;
   564	
   565			/* avoid endless loop in case of broken HW */
   566			if (retries > MAX_COUNT_LONG) {
   567				rc = -EIO;
   568				goto out_err;
   569			}
   570	
   571			wait_for_stat(chip, TPM_STS_VALID,
   572				      chip->timeout_c, &status);
   573	
   574			if ((status & TPM_STS_DATA_EXPECT) == 0) {
   575				rc = -EIO;
   576				goto out_err;
   577			}
   578		}
   579	
   580		/* write last byte */
   581		iic_tpm_write(TPM_DATA_FIFO(tpm_dev.locality), &(buf[count]), 1);
   582		wait_for_stat(chip, TPM_STS_VALID, chip->timeout_c, &status);
   583		if ((status & TPM_STS_DATA_EXPECT) != 0) {
   584			rc = -EIO;
   585			goto out_err;
   586		}
   587	
   588		/* go and do it */
   589		iic_tpm_write(TPM_STS(tpm_dev.locality), &sts, 1);
   590	
   591		return len;
   592	out_err:
   593		tpm_tis_i2c_ready(chip);
   594		/* The TPM needs some time to clean up here,
   595		 * so we sleep rather than keeping the bus busy
   596		 */
   597		usleep_range(SLEEP_DURATION_RESET_LOW, SLEEP_DURATION_RESET_HI);
   598		release_locality(chip, tpm_dev.locality, 0);
   599		return rc;
   600	}
   601	

---
0-DAY kernel test infrastructure                Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all                   Intel Corporation
Roberto Sassu Feb. 5, 2019, 8:08 a.m. UTC | #5
On 2/5/2019 12:40 AM, Jarkko Sakkinen wrote:
> On Tue, Feb 05, 2019 at 01:31:17AM +0200, Jarkko Sakkinen wrote:
>> On Mon, Feb 04, 2019 at 02:49:54PM +0100, Roberto Sassu wrote:
>>> On 2/4/2019 2:37 PM, Jarkko Sakkinen wrote:
>>>> Rename TPM_BUFSIZE defined in drivers/char/tpm/st33zp24/st33zp24.h to
>>>> ST33ZP24_BUFSIZE.
>>>>
>>>> Rename TPM_BUFSIZE defined in drivers/char/tpm/tpm_i2c_infineon.c to
>>>> TPM_I2C_INFINEON_BUFSIZE.
>>>
>>> Please also add a prefix to TPM_RETRY in tpm_i2c_nuvoton.c.
>>
>> Thanks, can do.
> 
> TPM_RETRY defined in
> 
>    32d33b29ba07 ("TPM: Retry SaveState command in suspend path")
> 
> has nothing to do with time. I'll also remove the comment about 5
> seconds.

I'll do the same for patch 4/6.

Roberto


> The definitions for TPM_RETRY seem fairly arbitrary. Jason, could
> tpm_i2c_nuvoton also use the same constant as tpm_tis_spi and TPM 1.2
> suspend, try max 50 times instead of five?
> 
> /Jarkko
>
kbuild test robot Feb. 5, 2019, 8:10 a.m. UTC | #6
Hi Jarkko,

I love your patch! Yet something to improve:

[auto build test ERROR on jss-tpmdd/next]
[also build test ERROR on v5.0-rc4 next-20190204]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]

url:    https://github.com/0day-ci/linux/commits/Jarkko-Sakkinen/tpm-st33zp24-Fix-the-name-collisions-in-tpm_st33zp24_spi-and-tpm_i2c_infineon/20190205-150003
base:   git://git.infradead.org/users/jjs/linux-tpmdd next
config: x86_64-randconfig-x013-201905 (attached as .config)
compiler: gcc-8 (Debian 8.2.0-14) 8.2.0
reproduce:
        # save the attached .config to linux build tree
        make ARCH=x86_64 

All errors (new ones prefixed by >>):

   drivers/char//tpm/tpm_i2c_infineon.c: In function 'tpm_tis_i2c_send':
>> drivers/char//tpm/tpm_i2c_infineon.c:531:12: error: 'TPM_I2C_INFINEON_BUFSIZE' undeclared (first use in this function); did you mean 'TPM_I2C_INFINEON_MAX_BUFSIZE'?
     if (len > TPM_I2C_INFINEON_BUFSIZE)
               ^~~~~~~~~~~~~~~~~~~~~~~~
               TPM_I2C_INFINEON_MAX_BUFSIZE
   drivers/char//tpm/tpm_i2c_infineon.c:531:12: note: each undeclared identifier is reported only once for each function it appears in

vim +531 drivers/char//tpm/tpm_i2c_infineon.c

   522	
   523	static int tpm_tis_i2c_send(struct tpm_chip *chip, u8 *buf, size_t len)
   524	{
   525		int rc, status;
   526		ssize_t burstcnt;
   527		size_t count = 0;
   528		u8 retries = 0;
   529		u8 sts = TPM_STS_GO;
   530	
 > 531		if (len > TPM_I2C_INFINEON_BUFSIZE)
   532			return -E2BIG;
   533	
   534		if (request_locality(chip, 0) < 0)
   535			return -EBUSY;
   536	
   537		status = tpm_tis_i2c_status(chip);
   538		if ((status & TPM_STS_COMMAND_READY) == 0) {
   539			tpm_tis_i2c_ready(chip);
   540			if (wait_for_stat
   541			    (chip, TPM_STS_COMMAND_READY,
   542			     chip->timeout_b, &status) < 0) {
   543				rc = -ETIME;
   544				goto out_err;
   545			}
   546		}
   547	
   548		while (count < len - 1) {
   549			burstcnt = get_burstcount(chip);
   550	
   551			/* burstcnt < 0 = TPM is busy */
   552			if (burstcnt < 0)
   553				return burstcnt;
   554	
   555			if (burstcnt > (len - 1 - count))
   556				burstcnt = len - 1 - count;
   557	
   558			rc = iic_tpm_write(TPM_DATA_FIFO(tpm_dev.locality),
   559					   &(buf[count]), burstcnt);
   560			if (rc == 0)
   561				count += burstcnt;
   562			else if (rc < 0)
   563				retries++;
   564	
   565			/* avoid endless loop in case of broken HW */
   566			if (retries > MAX_COUNT_LONG) {
   567				rc = -EIO;
   568				goto out_err;
   569			}
   570	
   571			wait_for_stat(chip, TPM_STS_VALID,
   572				      chip->timeout_c, &status);
   573	
   574			if ((status & TPM_STS_DATA_EXPECT) == 0) {
   575				rc = -EIO;
   576				goto out_err;
   577			}
   578		}
   579	
   580		/* write last byte */
   581		iic_tpm_write(TPM_DATA_FIFO(tpm_dev.locality), &(buf[count]), 1);
   582		wait_for_stat(chip, TPM_STS_VALID, chip->timeout_c, &status);
   583		if ((status & TPM_STS_DATA_EXPECT) != 0) {
   584			rc = -EIO;
   585			goto out_err;
   586		}
   587	
   588		/* go and do it */
   589		iic_tpm_write(TPM_STS(tpm_dev.locality), &sts, 1);
   590	
   591		return len;
   592	out_err:
   593		tpm_tis_i2c_ready(chip);
   594		/* The TPM needs some time to clean up here,
   595		 * so we sleep rather than keeping the bus busy
   596		 */
   597		usleep_range(SLEEP_DURATION_RESET_LOW, SLEEP_DURATION_RESET_HI);
   598		release_locality(chip, tpm_dev.locality, 0);
   599		return rc;
   600	}
   601	

---
0-DAY kernel test infrastructure                Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all                   Intel Corporation
Jarkko Sakkinen Feb. 5, 2019, 8:36 a.m. UTC | #7
On Tue, Feb 05, 2019 at 09:08:33AM +0100, Roberto Sassu wrote:
> On 2/5/2019 12:40 AM, Jarkko Sakkinen wrote:
> > On Tue, Feb 05, 2019 at 01:31:17AM +0200, Jarkko Sakkinen wrote:
> > > On Mon, Feb 04, 2019 at 02:49:54PM +0100, Roberto Sassu wrote:
> > > > On 2/4/2019 2:37 PM, Jarkko Sakkinen wrote:
> > > > > Rename TPM_BUFSIZE defined in drivers/char/tpm/st33zp24/st33zp24.h to
> > > > > ST33ZP24_BUFSIZE.
> > > > > 
> > > > > Rename TPM_BUFSIZE defined in drivers/char/tpm/tpm_i2c_infineon.c to
> > > > > TPM_I2C_INFINEON_BUFSIZE.
> > > > 
> > > > Please also add a prefix to TPM_RETRY in tpm_i2c_nuvoton.c.
> > > 
> > > Thanks, can do.
> > 
> > TPM_RETRY defined in
> > 
> >    32d33b29ba07 ("TPM: Retry SaveState command in suspend path")
> > 
> > has nothing to do with time. I'll also remove the comment about 5
> > seconds.
> 
> I'll do the same for patch 4/6.

Yep. I'll post a new patch ASAP.

/Jarkko
James Bottomley Feb. 5, 2019, 7:40 p.m. UTC | #8
On Mon, 2019-02-04 at 15:37 +0200, Jarkko Sakkinen wrote:
> diff --git a/drivers/char/tpm/tpm_i2c_infineon.c
> b/drivers/char/tpm/tpm_i2c_infineon.c
> index 9086edc9066b..b9d5a1dda8d2 100644
> --- a/drivers/char/tpm/tpm_i2c_infineon.c
> +++ b/drivers/char/tpm/tpm_i2c_infineon.c
[...]
> @@ -527,8 +528,8 @@ static int tpm_tis_i2c_send(struct tpm_chip
> *chip, u8 *buf, size_t len)
>  	u8 retries = 0;
>  	u8 sts = TPM_STS_GO;
>  
> -	if (len > TPM_BUFSIZE)
> -		return -E2BIG;	/* command is too long for our
> tpm, sorry */
> +	if (len > TPM_I2C_INFINEON_BUFSIZE)

TPM_I2C_INFINEON_MAX_BUFSIZE, surely, otherwise it won't compile ...
the kbuild robot just spotted this as well.

James
Jarkko Sakkinen Feb. 5, 2019, 8:59 p.m. UTC | #9
On Tue, Feb 05, 2019 at 02:40:22PM -0500, James Bottomley wrote:
> On Mon, 2019-02-04 at 15:37 +0200, Jarkko Sakkinen wrote:
> > diff --git a/drivers/char/tpm/tpm_i2c_infineon.c
> > b/drivers/char/tpm/tpm_i2c_infineon.c
> > index 9086edc9066b..b9d5a1dda8d2 100644
> > --- a/drivers/char/tpm/tpm_i2c_infineon.c
> > +++ b/drivers/char/tpm/tpm_i2c_infineon.c
> [...]
> > @@ -527,8 +528,8 @@ static int tpm_tis_i2c_send(struct tpm_chip
> > *chip, u8 *buf, size_t len)
> >  	u8 retries = 0;
> >  	u8 sts = TPM_STS_GO;
> >  
> > -	if (len > TPM_BUFSIZE)
> > -		return -E2BIG;	/* command is too long for our
> > tpm, sorry */
> > +	if (len > TPM_I2C_INFINEON_BUFSIZE)
> 
> TPM_I2C_INFINEON_MAX_BUFSIZE, surely, otherwise it won't compile ...
> the kbuild robot just spotted this as well.

Correct, unluckily, I had unstaged diff.

/Jarkko

Patch
diff mbox series

diff --git a/drivers/char/tpm/st33zp24/i2c.c b/drivers/char/tpm/st33zp24/i2c.c
index be5d1abd3e8e..8390c5b54c3b 100644
--- a/drivers/char/tpm/st33zp24/i2c.c
+++ b/drivers/char/tpm/st33zp24/i2c.c
@@ -33,7 +33,7 @@ 
 
 struct st33zp24_i2c_phy {
 	struct i2c_client *client;
-	u8 buf[TPM_BUFSIZE + 1];
+	u8 buf[ST33ZP24_BUFSIZE + 1];
 	int io_lpcpd;
 };
 
diff --git a/drivers/char/tpm/st33zp24/spi.c b/drivers/char/tpm/st33zp24/spi.c
index d7909ab287a8..ff019a1e3c68 100644
--- a/drivers/char/tpm/st33zp24/spi.c
+++ b/drivers/char/tpm/st33zp24/spi.c
@@ -63,7 +63,7 @@ 
  * some latency byte before the answer is available (max 15).
  * We have 2048 + 1024 + 15.
  */
-#define ST33ZP24_SPI_BUFFER_SIZE (TPM_BUFSIZE + (TPM_BUFSIZE / 2) +\
+#define ST33ZP24_SPI_BUFFER_SIZE (ST33ZP24_BUFSIZE + (ST33ZP24_BUFSIZE / 2) +\
 				  MAX_SPI_LATENCY)
 
 
diff --git a/drivers/char/tpm/st33zp24/st33zp24.h b/drivers/char/tpm/st33zp24/st33zp24.h
index 6f4a4198af6a..20da0a84988d 100644
--- a/drivers/char/tpm/st33zp24/st33zp24.h
+++ b/drivers/char/tpm/st33zp24/st33zp24.h
@@ -18,8 +18,8 @@ 
 #ifndef __LOCAL_ST33ZP24_H__
 #define __LOCAL_ST33ZP24_H__
 
-#define TPM_WRITE_DIRECTION             0x80
-#define TPM_BUFSIZE                     2048
+#define TPM_WRITE_DIRECTION	0x80
+#define ST33ZP24_BUFSIZE	2048
 
 struct st33zp24_dev {
 	struct tpm_chip *chip;
diff --git a/drivers/char/tpm/tpm_i2c_infineon.c b/drivers/char/tpm/tpm_i2c_infineon.c
index 9086edc9066b..b9d5a1dda8d2 100644
--- a/drivers/char/tpm/tpm_i2c_infineon.c
+++ b/drivers/char/tpm/tpm_i2c_infineon.c
@@ -26,8 +26,7 @@ 
 #include <linux/wait.h>
 #include "tpm.h"
 
-/* max. buffer size supported by our TPM */
-#define TPM_BUFSIZE 1260
+#define TPM_I2C_INFINEON_MAX_BUFSIZE 1260
 
 /* max. number of iterations after I2C NAK */
 #define MAX_COUNT 3
@@ -63,11 +62,13 @@  enum i2c_chip_type {
 	UNKNOWN,
 };
 
-/* Structure to store I2C TPM specific stuff */
 struct tpm_inf_dev {
 	struct i2c_client *client;
 	int locality;
-	u8 buf[TPM_BUFSIZE + sizeof(u8)]; /* max. buffer size + addr */
+	/* In addition to the data itself, the buffer must fit the 7-bit I2C
+	 * address and the direction bit.
+	 */
+	u8 buf[TPM_I2C_INFINEON_MAX_BUFSIZE + 1];
 	struct tpm_chip *chip;
 	enum i2c_chip_type chip_type;
 	unsigned int adapterlimit;
@@ -219,7 +220,7 @@  static int iic_tpm_write_generic(u8 addr, u8 *buffer, size_t len,
 		.buf = tpm_dev.buf
 	};
 
-	if (len > TPM_BUFSIZE)
+	if (len > TPM_I2C_INFINEON_MAX_BUFSIZE)
 		return -EINVAL;
 
 	if (!tpm_dev.client->adapter->algo->master_xfer)
@@ -527,8 +528,8 @@  static int tpm_tis_i2c_send(struct tpm_chip *chip, u8 *buf, size_t len)
 	u8 retries = 0;
 	u8 sts = TPM_STS_GO;
 
-	if (len > TPM_BUFSIZE)
-		return -E2BIG;	/* command is too long for our tpm, sorry */
+	if (len > TPM_I2C_INFINEON_BUFSIZE)
+		return -E2BIG;
 
 	if (request_locality(chip, 0) < 0)
 		return -EBUSY;