Skip to content

Commit 7105052

Browse files
zmlin1998broonie
authored andcommitted
spi: Add check for 8-bit transfer with 8 IO mode support
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]>
1 parent d7b8f8e commit 7105052

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
@@ -4138,10 +4138,13 @@ static int __spi_validate(struct spi_device *spi, struct spi_message *message)
41384138
xfer->tx_nbits != SPI_NBITS_OCTAL)
41394139
return -EINVAL;
41404140
if ((xfer->tx_nbits == SPI_NBITS_DUAL) &&
4141-
!(spi->mode & (SPI_TX_DUAL | SPI_TX_QUAD)))
4141+
!(spi->mode & (SPI_TX_DUAL | SPI_TX_QUAD | SPI_TX_OCTAL)))
41424142
return -EINVAL;
41434143
if ((xfer->tx_nbits == SPI_NBITS_QUAD) &&
4144-
!(spi->mode & SPI_TX_QUAD))
4144+
!(spi->mode & (SPI_TX_QUAD | SPI_TX_OCTAL)))
4145+
return -EINVAL;
4146+
if ((xfer->tx_nbits == SPI_NBITS_OCTAL) &&
4147+
!(spi->mode & SPI_TX_OCTAL))
41454148
return -EINVAL;
41464149
}
41474150
/* Check transfer rx_nbits */
@@ -4154,10 +4157,13 @@ static int __spi_validate(struct spi_device *spi, struct spi_message *message)
41544157
xfer->rx_nbits != SPI_NBITS_OCTAL)
41554158
return -EINVAL;
41564159
if ((xfer->rx_nbits == SPI_NBITS_DUAL) &&
4157-
!(spi->mode & (SPI_RX_DUAL | SPI_RX_QUAD)))
4160+
!(spi->mode & (SPI_RX_DUAL | SPI_RX_QUAD | SPI_RX_OCTAL)))
41584161
return -EINVAL;
41594162
if ((xfer->rx_nbits == SPI_NBITS_QUAD) &&
4160-
!(spi->mode & SPI_RX_QUAD))
4163+
!(spi->mode & (SPI_RX_QUAD | SPI_RX_OCTAL)))
4164+
return -EINVAL;
4165+
if ((xfer->rx_nbits == SPI_NBITS_OCTAL) &&
4166+
!(spi->mode & SPI_RX_OCTAL))
41614167
return -EINVAL;
41624168
}
41634169

0 commit comments

Comments
 (0)