* [PATCH] spi: atcspi200: validate data buswidth to fix FIELD_PREP build error
@ 2026-02-18 8:21 xiaopeitux
2026-02-23 6:36 ` CL Wang
0 siblings, 1 reply; 3+ messages in thread
From: xiaopeitux @ 2026-02-18 8:21 UTC (permalink / raw)
To: cl634, broonie, linux-spi, linux-kernel; +Cc: Pei Xiao, kernel test robot
From: Pei Xiao <xiaopei01@kylinos.cn>
TRANS_DUAL_QUAD only two bit, limit to range 0~3.
which gcc complains about:
error: FIELD_PREP: value too large for the field
drivers/spi/spi-atcspi200.c:198:9: note: in expansion of macro
'TRANS_DUAL_QUAD'
tc |= TRANS_DUAL_QUAD(ffs(op->data.buswidth) - 1);
Reported-by: kernel test robot <lkp@intel.com>
Closes: https://lore.kernel.org/oe-kbuild-all/202602140738.P7ZozxzI-lkp@intel.com/
Signed-off-by: Pei Xiao <xiaopei01@kylinos.cn>
---
drivers/spi/spi-atcspi200.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/drivers/spi/spi-atcspi200.c b/drivers/spi/spi-atcspi200.c
index 60a37ff5c6f5..87a2dedcee55 100644
--- a/drivers/spi/spi-atcspi200.c
+++ b/drivers/spi/spi-atcspi200.c
@@ -195,7 +195,10 @@ static void atcspi_set_trans_ctl(struct atcspi_dev *spi,
if (op->addr.buswidth > 1)
tc |= TRANS_ADDR_FMT;
if (op->data.nbytes) {
- tc |= TRANS_DUAL_QUAD(ffs(op->data.buswidth) - 1);
+ unsigned int width_code = ffs(op->data.buswidth) - 1;
+ if(unlikely(width_code > 3))
+ return;
+ tc |= TRANS_DUAL_QUAD(width_code);
if (op->data.dir == SPI_MEM_DATA_IN) {
if (op->dummy.nbytes)
tc |= TRANS_MODE_DMY_READ |
--
2.25.1
^ permalink raw reply related [flat|nested] 3+ messages in thread* Re: [PATCH] spi: atcspi200: validate data buswidth to fix FIELD_PREP build error
2026-02-18 8:21 [PATCH] spi: atcspi200: validate data buswidth to fix FIELD_PREP build error xiaopeitux
@ 2026-02-23 6:36 ` CL Wang
2026-02-23 7:45 ` Pei Xiao
0 siblings, 1 reply; 3+ messages in thread
From: CL Wang @ 2026-02-23 6:36 UTC (permalink / raw)
To: xiaopeitux
Cc: broonie, linux-spi, linux-kernel, Pei Xiao, kernel test robot,
cl634
Hi Pei,
Thanks for the patch to address the GCC compiler warning.
While I understand that the SPI framework theoretically guarantees
op->data.buswidth won't produce an out-of-bounds value here, I have
some concerns regarding the proposed error handling.
Using a direct return; inside atcspi_set_trans_ctl() creates a silent failure.
Since the function returns void, the callers (atcspi_prepare_trans and
atcspi_exec_mem_op) remain completely unaware of the error. They will blindly
proceed with the transfer, leaving the hardware in an unconfigured or unknown
state. Additionally, using a forced bitwise truncation could also lead to
uncontrollable hardware behavior.
A safer approach would be to either modify the function signatures to propagate
the error (e.g., returning -EINVAL), or at least fall back to a safe default
(like forcing width_code = 0 for standard 1-bit mode) along with
a WARN_ON_ONCE().
Since this requires a bit more structural adjustment in the driver, would you
mind if I take this over and submit a proper fix? I will make sure to add a
Suggested-by tag to acknowledge your effort in bringing this up.
Thanks again for catching this!
Best regards,
CL
>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] spi: atcspi200: validate data buswidth to fix FIELD_PREP build error
2026-02-23 6:36 ` CL Wang
@ 2026-02-23 7:45 ` Pei Xiao
0 siblings, 0 replies; 3+ messages in thread
From: Pei Xiao @ 2026-02-23 7:45 UTC (permalink / raw)
To: CL Wang, xiaopeitux; +Cc: broonie, linux-spi, linux-kernel, kernel test robot
在 2026/2/23 14:36, CL Wang 写道:
> Hi Pei,
>
> Thanks for the patch to address the GCC compiler warning.
>
> While I understand that the SPI framework theoretically guarantees
> op->data.buswidth won't produce an out-of-bounds value here, I have
> some concerns regarding the proposed error handling.
>
> Using a direct return; inside atcspi_set_trans_ctl() creates a silent failure.
> Since the function returns void, the callers (atcspi_prepare_trans and
> atcspi_exec_mem_op) remain completely unaware of the error. They will blindly
> proceed with the transfer, leaving the hardware in an unconfigured or unknown
> state. Additionally, using a forced bitwise truncation could also lead to
> uncontrollable hardware behavior.
>
> A safer approach would be to either modify the function signatures to propagate
> the error (e.g., returning -EINVAL), or at least fall back to a safe default
> (like forcing width_code = 0 for standard 1-bit mode) along with
> a WARN_ON_ONCE().
>
> Since this requires a bit more structural adjustment in the driver, would you
> mind if I take this over and submit a proper fix? I will make sure to add a
> Suggested-by tag to acknowledge your effort in bringing this up.
please go ahead with the modifications, thank you!
Pei .
Thanks!
> Thanks again for catching this!
>
> Best regards,
> CL
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-02-23 7:51 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-02-18 8:21 [PATCH] spi: atcspi200: validate data buswidth to fix FIELD_PREP build error xiaopeitux
2026-02-23 6:36 ` CL Wang
2026-02-23 7:45 ` Pei Xiao
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox