未验证 提交 f60d7270 编写于 作者: A Andy Shevchenko 提交者: Mark Brown

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: 7d93aecd ("spi: Add generic support for unused native cs with cs-gpios")
Signed-off-by: NAndy Shevchenko <andriy.shevchenko@linux.intel.com>
Link: https://lore.kernel.org/r/20210420164425.40287-2-andriy.shevchenko@linux.intel.comSigned-off-by: NMark Brown <broonie@kernel.org>
上级 dbaca8e5
...@@ -2611,7 +2611,7 @@ static int spi_get_gpio_descs(struct spi_controller *ctlr) ...@@ -2611,7 +2611,7 @@ static int spi_get_gpio_descs(struct spi_controller *ctlr)
native_cs_mask |= BIT(i); 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 && if ((ctlr->flags & SPI_MASTER_GPIO_SS) && num_cs_gpios &&
ctlr->max_native_cs && ctlr->unused_native_cs >= ctlr->max_native_cs) { ctlr->max_native_cs && ctlr->unused_native_cs >= ctlr->max_native_cs) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册