Linux SPI subsystem development
 help / color / mirror / Atom feed
* [PATCH] spi: cadence-quadspi: Add upper limit safety check to baudrate divisor
@ 2022-11-23 21:17 Nathan Barrett-Morrison
  2022-11-24  6:46 ` Dhruva Gole
  2022-11-24 11:40 ` Mark Brown
  0 siblings, 2 replies; 8+ messages in thread
From: Nathan Barrett-Morrison @ 2022-11-23 21:17 UTC (permalink / raw)
  Cc: nathan.morrison, greg.malysa, Mark Brown, open list:SPI SUBSYSTEM,
	open list

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.

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)
+		div = CQSPI_REG_CONFIG_BAUD_MASK;
+
 	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;
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2022-11-24 12:42 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox