Skip to content

Commit f60d727

Browse files
andy-shevbroonie
authored andcommitted
spi: Avoid undefined behaviour when counting unused native CSs
ffz(), that has been used to count unused native CSs, might cause undefined behaviour when called against ~0U. To fix that, open code it with ffs(~value) - 1. Fixes: 7d93aec ("spi: Add generic support for unused native cs with cs-gpios") Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com> Link: https://lore.kernel.org/r/20210420164425.40287-2-andriy.shevchenko@linux.intel.com Signed-off-by: Mark Brown <broonie@kernel.org>
1 parent dbaca8e commit f60d727

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

‎drivers/spi/spi.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2611,7 +2611,7 @@ static int spi_get_gpio_descs(struct spi_controller *ctlr)
26112611
native_cs_mask |= BIT(i);
26122612
}
26132613

2614-
ctlr->unused_native_cs = ffz(native_cs_mask);
2614+
ctlr->unused_native_cs = ffs(~native_cs_mask) - 1;
26152615

26162616
if ((ctlr->flags & SPI_MASTER_GPIO_SS) && num_cs_gpios &&
26172617
ctlr->max_native_cs && ctlr->unused_native_cs >= ctlr->max_native_cs) {

0 commit comments

Comments
 (0)