public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: "Jarkko Sakkinen" <jarkko@kernel.org>
To: "Stefan Wahren" <wahrenst@gmx.net>,
	"Peter Huewe" <peterhuewe@gmx.de>,
	"Jason Gunthorpe" <jgg@ziepe.ca>
Cc: <linux-integrity@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
	"Stefan Berger" <stefanb@linux.ibm.com>
Subject: Re: [PATCH RFC 1/2] tpm: tpm_tis_spi: Ensure SPI mode 0
Date: Mon, 09 Sep 2024 20:05:31 +0300	[thread overview]
Message-ID: <D41X15Z6ZQ4K.3HGVA7H9C6PJ5@kernel.org> (raw)
In-Reply-To: <e7d402f4-0463-4bb2-b1ea-afb36a58e59a@gmx.net>

On Fri Sep 6, 2024 at 5:46 PM EEST, Stefan Wahren wrote:
> Am 06.09.24 um 11:47 schrieb Jarkko Sakkinen:
> > On Fri Sep 6, 2024 at 9:09 AM EEST, Stefan Wahren wrote:
> >> According to TCG PC Client Platform TPM Profile (PTP) Specification
> >> only SPI mode 0 is supported. In order to ensure the SPI controller
> >> supports the necessary settings, call spi_setup() and bail out
> >> as soon as possible in error case.
> >>
> >> This change should affect all supported TPM SPI devices, because
> >> tpm_tis_spi_probe is either called direct or indirectly.
> >>
> >> Signed-off-by: Stefan Wahren <wahrenst@gmx.net>
> >> ---
> >>   drivers/char/tpm/tpm_tis_spi_main.c | 11 +++++++++++
> >>   1 file changed, 11 insertions(+)
> >>
> >> diff --git a/drivers/char/tpm/tpm_tis_spi_main.c b/drivers/char/tpm/tpm_tis_spi_main.c
> >> index 61b42c83ced8..e62d297b040e 100644
> >> --- a/drivers/char/tpm/tpm_tis_spi_main.c
> >> +++ b/drivers/char/tpm/tpm_tis_spi_main.c
> >> @@ -248,6 +248,17 @@ static int tpm_tis_spi_write_bytes(struct tpm_tis_data *data, u32 addr,
> >>   int tpm_tis_spi_init(struct spi_device *spi, struct tpm_tis_spi_phy *phy,
> >>   		     int irq, const struct tpm_tis_phy_ops *phy_ops)
> >>   {
> >> +	int ret;
> >> +
> >> +	spi->mode &= ~SPI_MODE_X_MASK;
> >> +	spi->mode |= SPI_MODE_0;
> >> +
> >> +	ret = spi_setup(spi);
> >> +	if (ret < 0) {
> >> +		dev_err(&spi->dev, "SPI setup failed: %d\n", ret);
> >> +		return ret;
> >> +	}
> >> +
> >>   	phy->iobuf = devm_kmalloc(&spi->dev, SPI_HDRSIZE + MAX_SPI_FRAMESIZE, GFP_KERNEL);
> >>   	if (!phy->iobuf)
> >>   		return -ENOMEM;
> >> --
> >> 2.34.1
> >
> > Why?
> SPI protocol driver usually call spi_setup to verify that the SPI
> controller accept the settings (SPI mode, bit, clock rate ...). Bailing
> out early is more helpful for debugging issues.

What problem has this patch solved for you? I think it makes the code
only less robust and more error prone.

BR, Jarkko

  reply	other threads:[~2024-09-09 17:05 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-09-06  6:09 [PATCH RFC 0/2] tpm: Minor improvements Stefan Wahren
2024-09-06  6:09 ` [PATCH RFC 1/2] tpm: tpm_tis_spi: Ensure SPI mode 0 Stefan Wahren
2024-09-06  9:47   ` Jarkko Sakkinen
2024-09-06 14:46     ` Stefan Wahren
2024-09-09 17:05       ` Jarkko Sakkinen [this message]
2024-09-09 17:16         ` Stefan Wahren
2024-09-06  6:09 ` [PATCH RFC 2/2] tpm: tpm_tis: Provide error messages in tpm_tis_core_init Stefan Wahren
2024-09-06  9:50   ` Jarkko Sakkinen
2024-09-06 14:42     ` Stefan Wahren

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=D41X15Z6ZQ4K.3HGVA7H9C6PJ5@kernel.org \
    --to=jarkko@kernel.org \
    --cc=jgg@ziepe.ca \
    --cc=linux-integrity@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=peterhuewe@gmx.de \
    --cc=stefanb@linux.ibm.com \
    --cc=wahrenst@gmx.net \
    /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