Skip to content

Commit 0758f7e

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: [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]>
1 parent 40f79e2 commit 0758f7e

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
@@ -4141,10 +4141,13 @@ static int __spi_validate(struct spi_device *spi, struct spi_message *message)
41414141
xfer->tx_nbits != SPI_NBITS_OCTAL)
41424142
return -EINVAL;
41434143
if ((xfer->tx_nbits == SPI_NBITS_DUAL) &&
4144-
!(spi->mode & (SPI_TX_DUAL | SPI_TX_QUAD)))
4144+
!(spi->mode & (SPI_TX_DUAL | SPI_TX_QUAD | SPI_TX_OCTAL)))
41454145
return -EINVAL;
41464146
if ((xfer->tx_nbits == SPI_NBITS_QUAD) &&
4147-
!(spi->mode & SPI_TX_QUAD))
4147+
!(spi->mode & (SPI_TX_QUAD | SPI_TX_OCTAL)))
4148+
return -EINVAL;
4149+
if ((xfer->tx_nbits == SPI_NBITS_OCTAL) &&
4150+
!(spi->mode & SPI_TX_OCTAL))
41484151
return -EINVAL;
41494152
}
41504153
/* Check transfer rx_nbits */
@@ -4157,10 +4160,13 @@ static int __spi_validate(struct spi_device *spi, struct spi_message *message)
41574160
xfer->rx_nbits != SPI_NBITS_OCTAL)
41584161
return -EINVAL;
41594162
if ((xfer->rx_nbits == SPI_NBITS_DUAL) &&
4160-
!(spi->mode & (SPI_RX_DUAL | SPI_RX_QUAD)))
4163+
!(spi->mode & (SPI_RX_DUAL | SPI_RX_QUAD | SPI_RX_OCTAL)))
41614164
return -EINVAL;
41624165
if ((xfer->rx_nbits == SPI_NBITS_QUAD) &&
4163-
!(spi->mode & SPI_RX_QUAD))
4166+
!(spi->mode & (SPI_RX_QUAD | SPI_RX_OCTAL)))
4167+
return -EINVAL;
4168+
if ((xfer->rx_nbits == SPI_NBITS_OCTAL) &&
4169+
!(spi->mode & SPI_RX_OCTAL))
41644170
return -EINVAL;
41654171
}
41664172

0 commit comments

Comments
 (0)