Re: [PATCH] spi: hisi-kunpeng: prevent infinite while() loop in hisi_spi_flush_fifo

From: Dan Carpenter

Date: Thu Mar 19 2026 - 11:51:58 EST


Hi Pei,

kernel test robot noticed the following build warnings:

https://git-scm.com/docs/git-format-patch#_base_tree_information]

url: https://github.com/intel-lab-lkp/linux/commits/Pei-Xiao/spi-hisi-kunpeng-prevent-infinite-while-loop-in-hisi_spi_flush_fifo/20260318-211321
base: https://git.kernel.org/pub/scm/linux/kernel/git/broonie/spi.git for-next
patch link: https://lore.kernel.org/r/d50f1f46b2ee2bba05de9e2d4199353b545194e3.1773820898.git.xiaopei01%40kylinos.cn
patch subject: [PATCH] spi: hisi-kunpeng: prevent infinite while() loop in hisi_spi_flush_fifo
config: s390-randconfig-r072-20260319 (https://download.01.org/0day-ci/archive/20260319/202603192159.S0PIjhlg-lkp@xxxxxxxxx/config)
compiler: clang version 23.0.0git (https://github.com/llvm/llvm-project 4abb927bacf37f18f6359a41639a6d1b3bffffb5)
smatch: v0.5.0-9004-gb810ac53

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@xxxxxxxxx>
| Reported-by: Dan Carpenter <dan.carpenter@xxxxxxxxxx>
| Closes: https://lore.kernel.org/r/202603192159.S0PIjhlg-lkp@xxxxxxxxx/

smatch warnings:
drivers/spi/spi-hisi-kunpeng.c:206 hisi_spi_flush_fifo() warn: should this be 'inner_limit == -1'

vim +206 drivers/spi/spi-hisi-kunpeng.c

c770d8631e1810 Jay Fang 2021-03-27 193
c770d8631e1810 Jay Fang 2021-03-27 194 static void hisi_spi_flush_fifo(struct hisi_spi *hs)
c770d8631e1810 Jay Fang 2021-03-27 195 {
c770d8631e1810 Jay Fang 2021-03-27 196 unsigned long limit = loops_per_jiffy << 1;
c770d8631e1810 Jay Fang 2021-03-27 197
c770d8631e1810 Jay Fang 2021-03-27 198 do {
e8821f559fed86 Pei Xiao 2026-03-18 199 unsigned long inner_limit = loops_per_jiffy;
e8821f559fed86 Pei Xiao 2026-03-18 200
e8821f559fed86 Pei Xiao 2026-03-18 201 while (hisi_spi_rx_not_empty(hs) && inner_limit--) {
c770d8631e1810 Jay Fang 2021-03-27 202 readl(hs->regs + HISI_SPI_DOUT);
e8821f559fed86 Pei Xiao 2026-03-18 203 cpu_relax();
e8821f559fed86 Pei Xiao 2026-03-18 204 }
e8821f559fed86 Pei Xiao 2026-03-18 205
e8821f559fed86 Pei Xiao 2026-03-18 @206 if (!inner_limit) {

This test is wrong. Maybe change inner_limit-- to
--inner_limit.

e8821f559fed86 Pei Xiao 2026-03-18 207 dev_warn_ratelimited(hs->dev, "RX FIFO flush timeout\n");
e8821f559fed86 Pei Xiao 2026-03-18 208 break;
e8821f559fed86 Pei Xiao 2026-03-18 209 }
e8821f559fed86 Pei Xiao 2026-03-18 210
c770d8631e1810 Jay Fang 2021-03-27 211 } while (hisi_spi_busy(hs) && limit--);
e8821f559fed86 Pei Xiao 2026-03-18 212
e8821f559fed86 Pei Xiao 2026-03-18 213 if (!limit)
e8821f559fed86 Pei Xiao 2026-03-18 214 dev_warn_ratelimited(hs->dev, "SPI busy timeout\n");
c770d8631e1810 Jay Fang 2021-03-27 215 }

--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki