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: 7d93aecdb5 ("spi: Add generic support for unused native cs with cs-gpios")
Signed-off-by: Andy Shevchenko <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Mark Brown <[email protected]>
This commit is contained in:
Andy Shevchenko authored and Mark Brown committed 2021-04-21 15:49:54 +01:00
1 parent dbaca8e56e
commit f60d7270c8
1 file changed
+1 -1
+1 -1
View File
@@ -2611,7 +2611,7 @@ static int spi_get_gpio_descs(struct spi_controller *ctlr)
native_cs_mask |= BIT(i);
}
ctlr->unused_native_cs = ffz(native_cs_mask);
ctlr->unused_native_cs = ffs(~native_cs_mask) - 1;
if ((ctlr->flags & SPI_MASTER_GPIO_SS) && num_cs_gpios &&
ctlr->max_native_cs && ctlr->unused_native_cs >= ctlr->max_native_cs) {