From: "Théo Lebrun" <theo.lebrun@bootlin.com>
To: "Lee Jones" <lee@kernel.org>
Cc: "Mark Brown" <broonie@kernel.org>, "Foon Tan" <lftan@altera.com>,
"Graham Moore" <grmoore@opensource.altera.com>,
"Murugan R" <vadivel.muruganx.ramuthevar@intel.com>,
"Vignesh Raghavendra" <vigneshr@ti.com>,
"Pratyush Yadav" <p.yadav@ti.com>, "Dhruva Gole" <d-gole@ti.com>,
linux-spi@vger.kernel.org, linux-kernel@vger.kernel.org,
"Miquèl Raynal" <miquel.raynal@bootlin.com>,
"Thomas Petazzoni" <thomas.petazzoni@bootlin.com>,
stable@vger.kernel.org
Subject: Re: [PATCH 06/10] spi: cadence-quadspi: Bound chip select against f_pdata array size
Date: Thu, 19 Nov 2026 15:55:04 +0100 [thread overview]
Message-ID: <DMZ9VNGP6GSZ.15VHI64APKAQR@bootlin.com> (raw)
In-Reply-To: <20261119143347.GS98456@joneslee-macbookpro.roam.internal>
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.
Thanks,
--
Théo Lebrun, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
next prev parent reply other threads:[~2026-11-19 14:55 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-19 9:17 [PATCH 00/10] spi: Fix data corruption, uninitialised data leaks and bounds checks Lee Jones
2026-11-19 9:17 ` [PATCH 01/10] spi: fsl-cpm: Map the zero page's address, not its struct page Lee Jones
2026-11-19 9:17 ` [PATCH 02/10] spi: bcm2835: Store native chip-select GPIO descriptor per device Lee Jones
2026-11-19 9:17 ` [PATCH 03/10] spi: ch341: Limit transfers to the hardware packet size Lee Jones
2026-11-19 9:17 ` [PATCH 04/10] spi: sprd-adi: Do not copy uninitialised data to rx_buf on read failure Lee Jones
2026-11-19 9:17 ` [PATCH 05/10] spi: topcliff-pch: Advance tx_buf between DMA chunks Lee Jones
2026-11-19 9:17 ` [PATCH 06/10] spi: cadence-quadspi: Bound chip select against f_pdata array size Lee Jones
2026-11-19 10:15 ` Théo Lebrun
2026-11-19 14:33 ` Lee Jones
2026-11-19 14:55 ` Théo Lebrun [this message]
2026-11-19 15:32 ` Lee Jones
2026-11-19 9:17 ` [PATCH 07/10] spi: cadence-xspi: Zero the tail word in m_iowriteq() Lee Jones
2026-11-19 9:17 ` [PATCH 08/10] spi: fsl-qspi: Propagate clock errors from fsl_qspi_select_mem() Lee Jones
2026-11-19 9:17 ` [PATCH 09/10] spi: cadence-xspi: Advance tx pointer between Marvell b0 chunks Lee Jones
2026-11-19 9:17 ` [PATCH 10/10] spi: cadence-xspi: Skip tail read for qword-aligned Marvell b0 receives Lee Jones
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=DMZ9VNGP6GSZ.15VHI64APKAQR@bootlin.com \
--to=theo.lebrun@bootlin.com \
--cc=broonie@kernel.org \
--cc=d-gole@ti.com \
--cc=grmoore@opensource.altera.com \
--cc=lee@kernel.org \
--cc=lftan@altera.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-spi@vger.kernel.org \
--cc=miquel.raynal@bootlin.com \
--cc=p.yadav@ti.com \
--cc=stable@vger.kernel.org \
--cc=thomas.petazzoni@bootlin.com \
--cc=vadivel.muruganx.ramuthevar@intel.com \
--cc=vigneshr@ti.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.