Skip to content

Commit 82b29ee

Browse files
zmlin1998gregkh
authored andcommitted
spi: Add check for 8-bit transfer with 8 IO mode support
commit 7105052 upstream. 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: d6a711a ("spi: Fix OCTAL mode support") Cc: stable@vger.kernel.org Signed-off-by: Cheng Ming Lin <chengminglin@mxic.com.tw> Link: https://patch.msgid.link/20250714031023.504752-1-linchengming884@gmail.com Signed-off-by: Mark Brown <broonie@kernel.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 415d496 commit 82b29ee

1 file changed

Lines changed: 10 additions & 4 deletions

File tree

drivers/spi/spi.c

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4011,10 +4011,13 @@ static int __spi_validate(struct spi_device *spi, struct spi_message *message)
40114011
xfer->tx_nbits != SPI_NBITS_OCTAL)
40124012
return -EINVAL;
40134013
if ((xfer->tx_nbits == SPI_NBITS_DUAL) &&
4014-
!(spi->mode & (SPI_TX_DUAL | SPI_TX_QUAD)))
4014+
!(spi->mode & (SPI_TX_DUAL | SPI_TX_QUAD | SPI_TX_OCTAL)))
40154015
return -EINVAL;
40164016
if ((xfer->tx_nbits == SPI_NBITS_QUAD) &&
4017-
!(spi->mode & SPI_TX_QUAD))
4017+
!(spi->mode & (SPI_TX_QUAD | SPI_TX_OCTAL)))
4018+
return -EINVAL;
4019+
if ((xfer->tx_nbits == SPI_NBITS_OCTAL) &&
4020+
!(spi->mode & SPI_TX_OCTAL))
40184021
return -EINVAL;
40194022
}
40204023
/* Check transfer rx_nbits */
@@ -4027,10 +4030,13 @@ static int __spi_validate(struct spi_device *spi, struct spi_message *message)
40274030
xfer->rx_nbits != SPI_NBITS_OCTAL)
40284031
return -EINVAL;
40294032
if ((xfer->rx_nbits == SPI_NBITS_DUAL) &&
4030-
!(spi->mode & (SPI_RX_DUAL | SPI_RX_QUAD)))
4033+
!(spi->mode & (SPI_RX_DUAL | SPI_RX_QUAD | SPI_RX_OCTAL)))
40314034
return -EINVAL;
40324035
if ((xfer->rx_nbits == SPI_NBITS_QUAD) &&
4033-
!(spi->mode & SPI_RX_QUAD))
4036+
!(spi->mode & (SPI_RX_QUAD | SPI_RX_OCTAL)))
4037+
return -EINVAL;
4038+
if ((xfer->rx_nbits == SPI_NBITS_OCTAL) &&
4039+
!(spi->mode & SPI_RX_OCTAL))
40344040
return -EINVAL;
40354041
}
40364042

0 commit comments

Comments
 (0)