All of lore.kernel.org
 help / color / mirror / Atom feed
From: Chi-Wen Weng <cwweng.linux@gmail.com>
To: sashiko-reviews@lists.linux.dev
Cc: robh@kernel.org, conor+dt@kernel.org, devicetree@vger.kernel.org,
	Mark Brown <broonie@kernel.org>
Subject: Re: [PATCH v2 3/3] spi: ma35d1-qspi: Add GPIO chip select support
Date: Fri, 2 Oct 2026 08:51:53 +0800	[thread overview]
Message-ID: <5fe2ad09-428f-4559-99b0-07042412b980@gmail.com> (raw)
In-Reply-To: <20261001134613.16C861F000FF@smtp.kernel.org>



sashiko-bot@kernel.org 於 2026/10/1 下午 09:46 寫道:
> Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
> - [Medium] spi: incorrect validation of total chip selects limits GPIO expansion
> --
> 
> commit bf74299215867df971e01913ae533377b76db610
> Author: Chi-Wen Weng <cwweng@nuvoton.com>
> 
>      spi: ma35d1-qspi: Add GPIO chip select support
>      
>      The generic SPI controller binding allows GPIO-based chip selects, but
>      the MA35D1 QSPI driver does not currently enable the SPI core's GPIO
>      descriptor handling. This patch enables GPIO chip-select support and
>      specifies that the controller provides two native chip selects.
> 
>> diff --git a/drivers/spi/spi-ma35d1-qspi.c b/drivers/spi/spi-ma35d1-qspi.c
>> index 30e3239f777d6..0644bb2990b8c 100644
>> --- a/drivers/spi/spi-ma35d1-qspi.c
>> +++ b/drivers/spi/spi-ma35d1-qspi.c
> [ ... ]
>> @@ -638,18 +664,21 @@ static int nuvoton_qspi_probe(struct platform_device *pdev)
>>   		goto err_assert;
>>   	}
>>   
>> -	if (!num_cs || num_cs > NUVOTON_QSPI_MAX_NUM_CS) {
>> +	if (!num_cs || num_cs > NUVOTON_QSPI_MAX_NATIVE_CS) {
> 
> [Severity: Medium]
> Does this validation check incorrectly apply the native chip select limit to the
> total number of chip selects?
> 
> If the Devicetree specifies a num-cs greater than 2 to declare additional
> GPIO-backed chip selects, it appears this check will cause nuvoton_qspi_probe()
> to fail unconditionally, preventing the use of the new GPIO expansion feature.
> 
>>   		ret = dev_err_probe(dev, -EINVAL, "invalid num-cs %u\n",
>>   				     num_cs);
>>   		goto err_assert;
>>   	}
>>   
>>   	ctlr->num_chipselect = num_cs;
>> +	ctlr->max_native_cs = NUVOTON_QSPI_MAX_NATIVE_CS;
>> +	ctlr->use_gpio_descriptors = true;
> 

Hi,

Thanks for the review.

I don't think this check prevents additional GPIO chip selects.

For the MA35D1 binding, `num-cs` is limited to the two native hardware
chip selects:

     num-cs:
       minimum: 1
       maximum: 2
       default: 2

Additional chip selects are described by entries in `cs-gpios`, rather
than by increasing `num-cs` beyond two.

Since the driver sets:

     ctlr->max_native_cs = NUVOTON_QSPI_MAX_NATIVE_CS;
     ctlr->use_gpio_descriptors = true;

the SPI core handles the GPIO chip-select expansion when the controller
is registered. The number of usable chip-select slots is expanded
according to the number of `cs-gpios` entries.

For example, with two native chip selects and two additional GPIO chip
selects, `num-cs` remains 2 while `cs-gpios` contains four entries. The
SPI core then expands `ctlr->num_chipselect` to 4.

`max_native_cs` only limits native chip-select indices. GPIO-backed chip
selects beyond that native limit are still valid.

Therefore a DT with `num-cs > 2` is not valid for this controller
binding, while valid configurations using additional GPIO chip selects
continue to work through the SPI core.

Thanks,
Chi-Wen



  reply	other threads:[~2026-10-02  0:51 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-01 13:18 [PATCH v2 0/3] spi: Add Nuvoton MA35D1 SPI controller support Chi-Wen Weng
2026-10-01 13:18 ` [PATCH v2 1/3] spi: dt-bindings: nuvoton,ma35d1-qspi: Add MA35D1 SPI controller Chi-Wen Weng
2026-10-03 14:25   ` Krzysztof Kozlowski
2026-10-05  3:08     ` Chi-Wen Weng
2026-10-01 13:18 ` [PATCH v2 2/3] spi: ma35d1: Add Nuvoton MA35D1 SPI controller support Chi-Wen Weng
2026-10-01 13:37   ` sashiko-bot
2026-10-02  0:45     ` Chi-Wen Weng
2026-10-01 13:18 ` [PATCH v2 3/3] spi: ma35d1-qspi: Add GPIO chip select support Chi-Wen Weng
2026-10-01 13:46   ` sashiko-bot
2026-10-02  0:51     ` Chi-Wen Weng [this message]
2026-10-04 17:19 ` [PATCH v2 0/3] spi: Add Nuvoton MA35D1 SPI controller support Mark Brown

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=5fe2ad09-428f-4559-99b0-07042412b980@gmail.com \
    --to=cwweng.linux@gmail.com \
    --cc=broonie@kernel.org \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=robh@kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /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.