Re: [PATCH 06/10] spi: cadence-quadspi: Bound chip select against f_pdata array size
From: Lee Jones
Date: Thu Nov 19 2026 - 10:33:05 EST
On Thu, 19 Nov 2026, Théo Lebrun wrote:
> On Thu Nov 19, 2026 at 3:33 PM CET, Lee Jones wrote:
> > On Thu, 19 Nov 2026, Théo Lebrun wrote:
> >> On Thu Nov 19, 2026 at 10:17 AM CET, Lee Jones wrote:
> >> > @@ -1761,8 +1762,9 @@ static int cqspi_setup_flash(struct cqspi_st *cqspi)
> >> > - if (cs >= cqspi->num_chipselect) {
> >> > - dev_err(dev, "Chip select %d out of range.\n", cs);
> >> > + if (cs >= cqspi->num_chipselect ||
> >> > + cs >= CQSPI_MAX_CHIPSELECT) {
> >> > + dev_err(dev, "Chip select %u out of range.\n", cs);
> >> > return -EINVAL;
> >> > }
> >>
> >> OK this does fix the bug. Here is another proposal though:
> >> ensure at probe that cqspi->num_chipselect <= CQSPI_MAX_CHIPSELECT.
> >
> > One slight hesitation with this.
> >
> > In cqspi_of_get_pdata(), CQSPI_MAX_CHIPSELECT used to be 16 prior to:
> >
> > 7cc3522aedb5 ("spi: cadence-qspi: set maximum chip-select to 4")
> >
> > ... and cqspi_setup_flash() overwrites cqspi->num_chipselect with max_cs
> > + 1 at the end anyway.
> >
> > Thus if an older or out-of-tree DTB (e.g. with cdns,is-decoded-cs) still
> > has `num-cs = <16>` while only populating flash@0, failing probe in
> > cqspi_of_get_pdata() would break a working board, whereas clamping
> > num_chipselect or checking cs against CQSPI_MAX_CHIPSELECT only rejects
> > child nodes that would actually overflow f_pdata[].
> >
> > That said, no in-tree DTS hits this, so if you prefer rejecting
> > (cqspi->num_chipselect > CQSPI_MAX_CHIPSELECT) or clamping it, let me
> > know and I will happily make it so.
>
> I still prefer the clamping or erroring from probe. A devicetree (ie
> hardware description) which tells us this controller has 16 CS has, is
> and will always be wrong. I don't see why we'd want to bother with this
> edge-case.
Noted. Thanks.
--
Lee Jones