drivers/spi/spi-atcspi200.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
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
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 >
在 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
© 2016 - 2026 Red Hat, Inc.