Linux SPI subsystem development
 help / color / mirror / Atom feed
From: Dhruva Gole <d-gole@ti.com>
To: Nathan Barrett-Morrison <nathan.morrison@timesys.com>
Cc: <greg.malysa@timesys.com>, Mark Brown <broonie@kernel.org>,
	"open list:SPI SUBSYSTEM" <linux-spi@vger.kernel.org>,
	open list <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] spi: cadence-quadspi: Add upper limit safety check to baudrate divisor
Date: Thu, 24 Nov 2022 12:16:10 +0530	[thread overview]
Message-ID: <9e5264fa-db1a-ed96-5fd8-cbfa4694b8bd@ti.com> (raw)
In-Reply-To: <20221123211705.126900-1-nathan.morrison@timesys.com>

Hi Nathan,
Thanks for your contribution.
However, there are a few issues that I would like you to address.

On 24/11/22 02:47, Nathan Barrett-Morrison wrote:
> While bringing up the cadence-quadspi driver on a customer board,
> I discovered that the baud divisor calculation can exceed the
> peripheral's maximum in some circumstances.  This will prevent it.
What is the peripheral's maximum? Is the peripheral a flash?
Please define what you mean by "some circumstances".

> 
> Signed-off-by: Nathan Barrett-Morrison <nathan.morrison@timesys.com>
> ---
>   drivers/spi/spi-cadence-quadspi.c | 4 ++++
>   1 file changed, 4 insertions(+)
> 
> diff --git a/drivers/spi/spi-cadence-quadspi.c b/drivers/spi/spi-cadence-quadspi.c
> index 447230547945..250575fb7b0e 100644
> --- a/drivers/spi/spi-cadence-quadspi.c
> +++ b/drivers/spi/spi-cadence-quadspi.c
> @@ -1119,6 +1119,10 @@ static void cqspi_config_baudrate_div(struct cqspi_st *cqspi)
>   	/* Recalculate the baudrate divisor based on QSPI specification. */
>   	div = DIV_ROUND_UP(ref_clk_hz, 2 * cqspi->sclk) - 1;
>   
> +	/* Maximum baud divisor */
> +	if (div > CQSPI_REG_CONFIG_BAUD_MASK)

I don't think comparing "greater than" with a MASK is atall a good idea.

> +		div = CQSPI_REG_CONFIG_BAUD_MASK;
I would not encourage this either.


> +
>   	reg = readl(reg_base + CQSPI_REG_CONFIG);
>   	reg &= ~(CQSPI_REG_CONFIG_BAUD_MASK << CQSPI_REG_CONFIG_BAUD_LSB);
>   	reg |= (div & CQSPI_REG_CONFIG_BAUD_MASK) << CQSPI_REG_CONFIG_BAUD_LSB;

Either come up with a better MACRO, or if what I understand
is correct, the peripheral's max value will depend, well
on the _peripheral_ in which case it is that "peripheral" driver's
responsibility to properly tell the controller what to do.


Again, I don't fully understand your situation is as in
what is the peripheral you are using. So please elaborate on that.

Importantly, I would suggest that you _NEVER_ compare ANY value to a
MASK Macro. MASK Macros are meant to MASK bits.



-- 
Thanks and Regards,
Dhruva Gole

  reply	other threads:[~2022-11-24  6:46 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-23 21:17 [PATCH] spi: cadence-quadspi: Add upper limit safety check to baudrate divisor Nathan Barrett-Morrison
2022-11-24  6:46 ` Dhruva Gole [this message]
2022-11-24 11:35   ` Mark Brown
2022-11-24 12:27     ` Dhruva Gole
2022-11-24 12:41       ` Mark Brown
2022-11-24 11:40 ` Mark Brown
2022-11-24 11:53   ` Nathan Barrett-Morrison
2022-11-24 12:02     ` Mark Brown

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=9e5264fa-db1a-ed96-5fd8-cbfa4694b8bd@ti.com \
    --to=d-gole@ti.com \
    --cc=broonie@kernel.org \
    --cc=greg.malysa@timesys.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-spi@vger.kernel.org \
    --cc=nathan.morrison@timesys.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