Commit b6b4177c authored by Federico Vaga's avatar Federico Vaga

sw:drv:spi: improve transfer validation

Signed-off-by: Federico Vaga's avatarFederico Vaga <federico.vaga@cern.ch>
parent fb304c93
...@@ -468,9 +468,16 @@ static int spi_ocores_sw_xfer_next_init(struct spi_ocores *sp) ...@@ -468,9 +468,16 @@ static int spi_ocores_sw_xfer_next_init(struct spi_ocores *sp)
return -EINVAL; return -EINVAL;
nbits = spi_ocores_hw_xfer_bits_per_word(sp); nbits = spi_ocores_hw_xfer_bits_per_word(sp);
if (nbits & (~SPI_OCORES_CTRL_CHAR_LEN)) if ((nbits - 1) & (~SPI_OCORES_CTRL_CHAR_LEN))
return -EINVAL; return -EINVAL;
if ((sp->cur_xfer->len << 3) < nbits) {
dev_err(&sp->master->dev,
"Invalid transfer length %d (bits_per_word %d)\n",
sp->cur_xfer->len, nbits);
return -EINVAL;
}
sp->cur_ctrl = sp->ctrl_base; sp->cur_ctrl = sp->ctrl_base;
if (sp->master->cur_msg->spi->mode & SPI_CPHA) { if (sp->master->cur_msg->spi->mode & SPI_CPHA) {
sp->cur_ctrl |= SPI_OCORES_CTRL_Tx_NEG; sp->cur_ctrl |= SPI_OCORES_CTRL_Tx_NEG;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment