Re: [PATCH v4 4/9] spi: restrict CS logical values to a contiguous sequence

From: Andy Shevchenko

Date: Wed Oct 21 2026 - 11:10:40 EST


On Tue, Oct 20, 2026 at 10:57:28PM -0300, Jonathan Santos wrote:
> When a device uses more than one chip select, require the logical CS
> numbers to be consecutive (for example 2, 3, 4). If they aren't,
> __spi_add_device() now fails with -EINVAL and logs which CS breaks
> the sequence.

...

> ---
> Changes in v4:
> * New patch, suggested by Andy. I assume this might have impacts on
> existing users. Should we make something else to complement this?

But do we have any sparse chipselect lists anywhere (in DT?)?

> + /* Restrict CS logical values to a contiguous sequence */
> + for (idx = 1; idx < spi->num_chipselect; idx++) {

... prev = spi_get_chipselect(spi, idx);
... curr = spi_get_chipselect(spi, idx - 1);

> + if (spi_get_chipselect(spi, idx) != spi_get_chipselect(spi, idx - 1) + 1) {
> + dev_err(dev, "cs%d is not consecutive with cs%d\n",
> + spi_get_chipselect(spi, idx),
> + spi_get_chipselect(spi, idx - 1));

if (curr != prev + 1) {
dev_err(dev, "cs%d is not consecutive with cs%d\n", curr, prev);

> + return -EINVAL;
> + }
> + }

--
With Best Regards,
Andy Shevchenko