* [PATCH] spi: Add check for 8-bit transfer with 8 IO mode support
@ 2025-07-14 3:10 Cheng Ming Lin
2025-07-14 16:13 ` Mark Brown
0 siblings, 1 reply; 2+ messages in thread
From: Cheng Ming Lin @ 2025-07-14 3:10 UTC (permalink / raw)
To: broonie
Cc: patrice.chotard, linux-spi, linux-kernel, alvinzhou,
Cheng Ming Lin, stable
From: Cheng Ming Lin <chengminglin@mxic.com.tw>
The current SPI framework does not verify if the SPI device supports
8 IO mode when doing an 8-bit transfer. This patch adds a check to
ensure that if the transfer tx_nbits or rx_nbits is 8, the SPI mode must
support 8 IO. If not, an error is returned, preventing undefined behavior.
Fixes: d6a711a898672 ("spi: Fix OCTAL mode support")
Cc: stable@vger.kernel.org
Signed-off-by: Cheng Ming Lin <chengminglin@mxic.com.tw>
---
drivers/spi/spi.c | 14 ++++++++++----
1 file changed, 10 insertions(+), 4 deletions(-)
diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
index 1bc0fdbb1bd7..0ffa3f9f2870 100644
--- a/drivers/spi/spi.c
+++ b/drivers/spi/spi.c
@@ -4138,10 +4138,13 @@ static int __spi_validate(struct spi_device *spi, struct spi_message *message)
xfer->tx_nbits != SPI_NBITS_OCTAL)
return -EINVAL;
if ((xfer->tx_nbits == SPI_NBITS_DUAL) &&
- !(spi->mode & (SPI_TX_DUAL | SPI_TX_QUAD)))
+ !(spi->mode & (SPI_TX_DUAL | SPI_TX_QUAD | SPI_TX_OCTAL)))
return -EINVAL;
if ((xfer->tx_nbits == SPI_NBITS_QUAD) &&
- !(spi->mode & SPI_TX_QUAD))
+ !(spi->mode & (SPI_TX_QUAD | SPI_TX_OCTAL)))
+ return -EINVAL;
+ if ((xfer->tx_nbits == SPI_NBITS_OCTAL) &&
+ !(spi->mode & SPI_TX_OCTAL))
return -EINVAL;
}
/* Check transfer rx_nbits */
@@ -4154,10 +4157,13 @@ static int __spi_validate(struct spi_device *spi, struct spi_message *message)
xfer->rx_nbits != SPI_NBITS_OCTAL)
return -EINVAL;
if ((xfer->rx_nbits == SPI_NBITS_DUAL) &&
- !(spi->mode & (SPI_RX_DUAL | SPI_RX_QUAD)))
+ !(spi->mode & (SPI_RX_DUAL | SPI_RX_QUAD | SPI_RX_OCTAL)))
return -EINVAL;
if ((xfer->rx_nbits == SPI_NBITS_QUAD) &&
- !(spi->mode & SPI_RX_QUAD))
+ !(spi->mode & (SPI_RX_QUAD | SPI_RX_OCTAL)))
+ return -EINVAL;
+ if ((xfer->rx_nbits == SPI_NBITS_OCTAL) &&
+ !(spi->mode & SPI_RX_OCTAL))
return -EINVAL;
}
--
2.25.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] spi: Add check for 8-bit transfer with 8 IO mode support
2025-07-14 3:10 [PATCH] spi: Add check for 8-bit transfer with 8 IO mode support Cheng Ming Lin
@ 2025-07-14 16:13 ` Mark Brown
0 siblings, 0 replies; 2+ messages in thread
From: Mark Brown @ 2025-07-14 16:13 UTC (permalink / raw)
To: Cheng Ming Lin
Cc: patrice.chotard, linux-spi, linux-kernel, alvinzhou,
Cheng Ming Lin, stable
On Mon, 14 Jul 2025 11:10:23 +0800, Cheng Ming Lin wrote:
> The current SPI framework does not verify if the SPI device supports
> 8 IO mode when doing an 8-bit transfer. This patch adds a check to
> ensure that if the transfer tx_nbits or rx_nbits is 8, the SPI mode must
> support 8 IO. If not, an error is returned, preventing undefined behavior.
>
>
Applied to
https://git.kernel.org/pub/scm/linux/kernel/git/broonie/spi.git for-next
Thanks!
[1/1] spi: Add check for 8-bit transfer with 8 IO mode support
commit: 710505212e3272396394f8cf78e3ddfd05df3f22
All being well this means that it will be integrated into the linux-next
tree (usually sometime in the next 24 hours) and sent to Linus during
the next merge window (or sooner if it is a bug fix), however if
problems are discovered then the patch may be dropped or reverted.
You may get further e-mails resulting from automated or manual testing
and review of the tree, please engage with people reporting problems and
send followup patches addressing any issues that are reported if needed.
If any updates are required or you are submitting further changes they
should be sent as incremental updates against current git, existing
patches will not be replaced.
Please add any relevant lists and maintainers to the CCs when replying
to this mail.
Thanks,
Mark
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2025-07-14 16:13 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-07-14 3:10 [PATCH] spi: Add check for 8-bit transfer with 8 IO mode support Cheng Ming Lin
2025-07-14 16:13 ` Mark Brown
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).