Skip to content

Commit

Permalink
spi: stm32: fix error check on mbr being -ve
Browse files Browse the repository at this point in the history
The error check of mbr < 0 is always false because mbr is a u32. Make
mbt an int so that a -ve error return from stm32_spi_prepare_mbr can be
detected.

Detected by CoverityScan, CID#1446586 ("Unsigned compared against 0")

Signed-off-by: Colin Ian King <colin.king@canonical.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
  • Loading branch information
Colin Ian King authored and Mark Brown committed Jun 23, 2017
1 parent dcbe0d8 commit a2f07d3
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions drivers/spi/spi-stm32.c
Original file line number Diff line number Diff line change
Expand Up @@ -857,7 +857,7 @@ static int stm32_spi_transfer_one_setup(struct stm32_spi *spi,
}

if (spi->cur_speed != transfer->speed_hz) {
u32 mbr;
int mbr;

/* Update spi->cur_speed with real clock speed */
mbr = stm32_spi_prepare_mbr(spi, transfer->speed_hz);
Expand All @@ -869,7 +869,7 @@ static int stm32_spi_transfer_one_setup(struct stm32_spi *spi,
transfer->speed_hz = spi->cur_speed;

cfg1_clrb |= SPI_CFG1_MBR;
cfg1_setb |= (mbr << SPI_CFG1_MBR_SHIFT) & SPI_CFG1_MBR;
cfg1_setb |= ((u32)mbr << SPI_CFG1_MBR_SHIFT) & SPI_CFG1_MBR;
}

if (cfg1_clrb || cfg1_setb)
Expand Down

0 comments on commit a2f07d3

Please sign in to comment.