Message ID | 20210420141004.59936-1-andriy.shevchenko@linux.intel.com |
---|---|
State | Accepted |
Commit | dbaca8e56ea3f23fa215f48c2d46dd03ede06e02 |
Headers | show |
Series | [v1,1/2] spi: Allow to have all native CSs in use along with GPIOs | expand |
On Tue, Apr 20, 2021 at 06:07:06PM +0300, Andy Shevchenko wrote: > On Tue, Apr 20, 2021 at 03:56:16PM +0100, Mark Brown wrote: > > On Tue, Apr 20, 2021 at 05:10:04PM +0300, Andy Shevchenko wrote: > > > ffz(), that has been used to count unused native CSs, might produce UB > > Bit of an IA there... > UB -- undefined behaviour. > I'll decode it. Should I decode CS as well? CS is fine.
diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c index 36c46feab6d4..9c3730a9f7d5 100644 --- a/drivers/spi/spi.c +++ b/drivers/spi/spi.c @@ -2610,8 +2610,9 @@ static int spi_get_gpio_descs(struct spi_controller *ctlr) } ctlr->unused_native_cs = ffz(native_cs_mask); - if (num_cs_gpios && ctlr->max_native_cs && - ctlr->unused_native_cs >= ctlr->max_native_cs) { + + if ((ctlr->flags & SPI_MASTER_GPIO_SS) && num_cs_gpios && + ctlr->max_native_cs && ctlr->unused_native_cs >= ctlr->max_native_cs) { dev_err(dev, "No unused native chip select available\n"); return -EINVAL; }
The commit 7d93aecdb58d ("spi: Add generic support for unused native cs with cs-gpios") excludes the valid case for the controllers that doesn't need to switch native CS in order to perform the transfer, i.e. when 0 native ... ... <n> - 1 native <n> GPIO <n> + 1 GPIO ... ... where <n> defines maximum of native CSs supported by the controller. To allow this, bail out from spi_get_gpio_descs() conditionally for the controllers which explicitly marked with SPI_MASTER_GPIO_SS. Fixes: 7d93aecdb58d ("spi: Add generic support for unused native cs with cs-gpios") Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com> --- drivers/spi/spi.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)