Skip to content

Commit 179dbd9

Browse files
zmlin1998opsiff
authored andcommitted
spi: Add check for 8-bit transfer with 8 IO mode support
commit 710505212e3272396394f8cf78e3ddfd05df3f22 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: [email protected] Signed-off-by: Cheng Ming Lin <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Mark Brown <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]> (cherry picked from commit 82b29ee8ba906b651950ea73711595136478b6b6)
1 parent ef87257 commit 179dbd9

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

drivers/spi/spi.c

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4084,10 +4084,13 @@ static int __spi_validate(struct spi_device *spi, struct spi_message *message)
40844084
xfer->tx_nbits != SPI_NBITS_OCTAL)
40854085
return -EINVAL;
40864086
if ((xfer->tx_nbits == SPI_NBITS_DUAL) &&
4087-
!(spi->mode & (SPI_TX_DUAL | SPI_TX_QUAD)))
4087+
!(spi->mode & (SPI_TX_DUAL | SPI_TX_QUAD | SPI_TX_OCTAL)))
40884088
return -EINVAL;
40894089
if ((xfer->tx_nbits == SPI_NBITS_QUAD) &&
4090-
!(spi->mode & SPI_TX_QUAD))
4090+
!(spi->mode & (SPI_TX_QUAD | SPI_TX_OCTAL)))
4091+
return -EINVAL;
4092+
if ((xfer->tx_nbits == SPI_NBITS_OCTAL) &&
4093+
!(spi->mode & SPI_TX_OCTAL))
40914094
return -EINVAL;
40924095
}
40934096
/* Check transfer rx_nbits */
@@ -4100,10 +4103,13 @@ static int __spi_validate(struct spi_device *spi, struct spi_message *message)
41004103
xfer->rx_nbits != SPI_NBITS_OCTAL)
41014104
return -EINVAL;
41024105
if ((xfer->rx_nbits == SPI_NBITS_DUAL) &&
4103-
!(spi->mode & (SPI_RX_DUAL | SPI_RX_QUAD)))
4106+
!(spi->mode & (SPI_RX_DUAL | SPI_RX_QUAD | SPI_RX_OCTAL)))
41044107
return -EINVAL;
41054108
if ((xfer->rx_nbits == SPI_NBITS_QUAD) &&
4106-
!(spi->mode & SPI_RX_QUAD))
4109+
!(spi->mode & (SPI_RX_QUAD | SPI_RX_OCTAL)))
4110+
return -EINVAL;
4111+
if ((xfer->rx_nbits == SPI_NBITS_OCTAL) &&
4112+
!(spi->mode & SPI_RX_OCTAL))
41074113
return -EINVAL;
41084114
}
41094115

0 commit comments

Comments
 (0)