mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Peter Hüwe" <PeterHuewe@gmx.de>
To: tpmdd-devel@lists.sourceforge.net
Cc: Mathias Leblanc <mathias.leblanc@st.com>,
	Kent Yoder <key@linux.vnet.ibm.com>,
	Rajiv Andrade <mail@srajiv.net>,
	Marcel Selhorst <tpmdd@selhorst.net>,
	Sirrix AG <tpmdd@sirrix.com>,
	"Jean-Luc Blanc" <jean-luc.blanc@st.com>,
	linux-kernel@vger.kernel.org,
	Matthias Leblanc <matthias.leblanc@gmail.com>
Subject: Re: [tpmdd-devel] [PATCH 1/1] TPM: STMicroelectronics st33 driver SPI
Date: Sun, 28 Apr 2013 03:16:33 +0200	[thread overview]
Message-ID: <201304280316.34094.PeterHuewe@gmx.de> (raw)
In-Reply-To: <1366620606-2952-1-git-send-email-mathias.leblanc@st.com>

Hi Matthias,

it's nice to see that you consider most of the comments, unfortunately I still 
have some left ;)

> +/*
> + * tpm_st33_spi_init initialize driver
> + * @return: 0 if successful, else non zero value.
> + */
> +static int __init tpm_st33_spi_init(void)
> +{
> +	return spi_register_driver(&tpm_st33_spi_driver);
> +}
> +
> +/*
> + * tpm_st33_spi_exit The kernel calls this function during unloading the
> + * module or during shut down process
> + */
> +static void __exit tpm_st33_spi_exit(void)
> +{
> +	spi_unregister_driver(&tpm_st33_spi_driver);
> +}
> +
> +module_init(tpm_st33_spi_init);
> +module_exit(tpm_st33_spi_exit);

Please use module_spi_driver(&tpm_st33_spi_driver); instead
Boilerplate code sucks.


> +	u8 *data_buffer = platform_data->tpm_spi_buffer[0];
> +	struct spi_transfer xfer = {
> +		.tx_buf	 = data_buffer,
> +		.rx_buf	 = platform_data->tpm_spi_buffer[1],
> +	};
> +	struct spi_message msg;
>...
> +	xfer.len = total_length;
> +	spi_message_init(&msg);
> +	spi_message_add_tail(&xfer, &msg);
> +	value = spi_sync(dev, &msg);


Doesn't spi_write fit here ?

static inline int
spi_write(struct spi_device *spi, const void *buf, size_t len)
{
	struct spi_transfer	t = {
			.tx_buf		= buf,
			.len		= len,
		};
	struct spi_message	m;

	spi_message_init(&m);
	spi_message_add_tail(&t, &m);
	return spi_sync(spi, &m);
}

Seems pretty identical.
-> This would save some lines of code,
and again - boilerplate code sucks.
Same applies to spi_read,



The driver generates some gcc warnings:
 drivers/char/tpm/tpm_spi_stm_st33.c: In function 'read8_reg': 
 drivers/char/tpm/tpm_spi_stm_st33.c:180:5: warning: unused variable 'latency'  
[-Wunused-variable]
 drivers/char/tpm/tpm_spi_stm_st33.c: In function 'tpm_stm_spi_status':
 drivers/char/tpm/tpm_spi_stm_st33.c:353:2: warning: 'data' is used  
uninitialized in this function [-Wuninitialized]
 drivers/char/tpm/tpm_spi_stm_st33.c: In function 'get_burstcount':
 drivers/char/tpm/tpm_spi_stm_st33.c:450:12: warning: 'temp' is used  
uninitialized in this function [-Wuninitialized]
 drivers/char/tpm/tpm_spi_stm_st33.c: In function 'check_locality':
 drivers/char/tpm/tpm_spi_stm_st33.c:369:22: warning: 'data' may be used  
uninitialized in this function [-Wuninitialized]



The driver does give me some smatch errors:

$ LANG=C make -j16 C=1 CHECK=smatch
 CHECK   drivers/char/tpm/tpm_spi_stm_st33.c
 drivers/char/tpm/tpm_spi_stm_st33.c:882 tpm_st33_spi_probe() warn: variable  
dereferenced before check 'platform_data' (see line 781)
 drivers/char/tpm/tpm_spi_stm_st33.c:980 tpm_st33_spi_pm_resume() warn: should  
this be a bitwise op?
 drivers/char/tpm/tpm_spi_stm_st33.c:980 tpm_st33_spi_pm_resume() warn: should  
this be a bitwise op?



and some sparse errors:
 drivers/char/tpm/tpm_spi_stm_st33.c:102:35: warning: cast removes address 
space of expression
 drivers/char/tpm/tpm_spi_stm_st33.c:171:35: warning: cast removes address 
space of expression
 drivers/char/tpm/tpm_spi_stm_st33.c:299:19: warning: cast removes address 
space of expression
 drivers/char/tpm/tpm_spi_stm_st33.c:311:15: warning: symbol 
'wait_for_serirq_timeout' was not declared. Should it be static?
 drivers/char/tpm/tpm_spi_stm_st33.c:546:19: warning: cast removes address 
space of expression





And here are some other, rather subjective remarks:

> +		for (; nbr_dummy_bytes < total_length &&
> +			 ((u8 *)xfer.rx_buf)[nbr_dummy_bytes] == 0;
> +			 nbr_dummy_bytes++)
> +			;

Not sure if it would be easier to read using a while and putting the increment 
into the loop body

>+		while (nbr_dummy_bytes < total_length && 
>+			((u8 *)xfer.rx_buf)[nbr_dummy_bytes] == 0)
>+			 nbr_dummy_bytes++;

I usually don't like empty loop bodies, as they tend to be overlooked.



> +static u32 SPI_WRITE_DATA(struct tpm_chip *tpm, u8 tpm_register,
> +			  u8 *tpm_data, u16 tpm_size)
> +{
> +	u8 value = 0;
> +	value = write8_reg(tpm, tpm_register, tpm_data, tpm_size);
> +
> +	switch (value) {
> +	case TPM_ST_SPI_OK:
> +		return TPM_ST_SPI_OK;
> +	case 0:
> +		return 0;
> +	default:
> +		return -EBUSY;
> +	}
> +} /* SPI_WRITE_DATA() */

Why do you need a wrapper function here for the return code?
write8_reg is only called from this location, so why doesn't it return the 
correct error code directly?
*confused*


Same applies to read8_reg.




> +static int _wait_for_interrupt_serirq_timeout(struct tpm_chip *chip,
> +					unsigned long timeout)
Is only called from wait_for_serirq_timeout - I'm not really sure if it helps 
readability to have a separate function.




> +	.resume = tpm_st33_spi_pm_resume,
> +	.suspend = tpm_st33_spi_pm_suspend,
Maybe use 
SIMPLE_DEV_PM_OPS 
instead as it is (afaik) the new standard way for PM_OPS.
The conversion should be pretty similar to the one in your I2C TPM driver:
https://github.com/shpedoikal/linux/commit/d459335381eca1cb91fefb87021d3d172342e55a


Regards,
Peter


  parent reply	other threads:[~2013-04-28  1:12 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-04-22  8:50 Mathias Leblanc
2013-04-22 15:26 ` [tpmdd-devel] " Kent Yoder
2013-04-22 16:32   ` Mathias LEBLANC
2013-04-22 18:31     ` Kent Yoder
2013-04-25 15:40       ` Mathias LEBLANC
2013-04-26 14:29         ` Kent Yoder
2013-04-28  1:16 ` Peter Hüwe [this message]
2013-04-29 14:15   ` Kent Yoder
  -- strict thread matches above, loose matches on Subject: below --
2013-05-15 13:53 Matthias Leblanc
2013-05-15 22:29 ` [tpmdd-devel] " Peter Hüwe
2013-05-16  8:45   ` Mathias LEBLANC
2013-05-16 19:03     ` Peter Hüwe
2013-05-17 12:26       ` Mathias LEBLANC
2013-05-07 10:16 Matthias Leblanc
     [not found] ` <-7985513476024686594@unknownmsgid>
2013-05-10 15:06   ` [tpmdd-devel] " Kent Yoder
2013-05-13 15:30     ` Mathias LEBLANC
2013-05-13 15:56       ` Kent Yoder
2013-04-12  8:44 Matthias Leblanc
2013-04-17 21:31 ` [tpmdd-devel] " Kent Yoder
2013-04-19 16:06   ` Mathias LEBLANC
2013-04-09 14:42 Matthias Leblanc
2013-04-10 20:32 ` [tpmdd-devel] " Peter Hüwe
2013-04-11  8:58   ` Mathias LEBLANC
2013-04-11 21:44     ` Peter Hüwe
2013-03-25 15:08 Matthias Leblanc
2013-03-25 16:44 ` [tpmdd-devel] " Kent Yoder
2013-03-25 16:48   ` Mathias LEBLANC

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=201304280316.34094.PeterHuewe@gmx.de \
    --to=peterhuewe@gmx.de \
    --cc=jean-luc.blanc@st.com \
    --cc=key@linux.vnet.ibm.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mail@srajiv.net \
    --cc=mathias.leblanc@st.com \
    --cc=matthias.leblanc@gmail.com \
    --cc=tpmdd-devel@lists.sourceforge.net \
    --cc=tpmdd@selhorst.net \
    --cc=tpmdd@sirrix.com \
    /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

Powered by JetHome