[PATCH] spi: atcspi200: validate data buswidth to fix FIELD_PREP build error

From: xiaopeitux

Date: Wed Feb 18 2026 - 03:25:17 EST


From: Pei Xiao <xiaopei01@xxxxxxxxxx>

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@xxxxxxxxx>
Closes: https://lore.kernel.org/oe-kbuild-all/202602140738.P7ZozxzI-lkp@xxxxxxxxx/
Signed-off-by: Pei Xiao <xiaopei01@xxxxxxxxxx>
---
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