drivers/scsi/fnic/fnic_scsi.c:98:38: warning: array subscript -1 is outside array bounds of 'struct scsi_cmnd[23529010298098917]'

From: kernel test robot
Date: Wed Oct 18 2023 - 07:21:43 EST


tree: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master
head: 06dc10eae55b5ceabfef287a7e5f16ceea204aa0
commit: 514f0c400bde6b62405467daaf2a0a86bcf7794b scsi: fnic: Fix sg_reset success path
date: 3 weeks ago
config: x86_64-allyesconfig (https://download.01.org/0day-ci/archive/20231018/202310181947.fzMfU0gi-lkp@xxxxxxxxx/config)
compiler: gcc-12 (Debian 12.2.0-14) 12.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20231018/202310181947.fzMfU0gi-lkp@xxxxxxxxx/reproduce)

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>
| Closes: https://lore.kernel.org/oe-kbuild-all/202310181947.fzMfU0gi-lkp@xxxxxxxxx/

All warnings (new ones prefixed by >>):

In function 'fnic_io_lock_hash',
inlined from 'fnic_fcpio_itmf_cmpl_handler' at drivers/scsi/fnic/fnic_scsi.c:1086:13:
>> drivers/scsi/fnic/fnic_scsi.c:98:38: warning: array subscript -1 is outside array bounds of 'struct scsi_cmnd[23529010298098917]' [-Warray-bounds]
98 | u32 hash = scsi_cmd_to_rq(sc)->tag & (FNIC_IO_LOCKS - 1);
| ~~~~~~~~~~~~~~~~~~^~~~~
>> drivers/scsi/fnic/fnic_scsi.c:98:38: warning: array subscript -1 is outside array bounds of 'struct scsi_cmnd[23529010298098917]' [-Warray-bounds]
>> drivers/scsi/fnic/fnic_scsi.c:98:38: warning: array subscript -1 is outside array bounds of 'struct scsi_cmnd[23529010298098917]' [-Warray-bounds]
>> drivers/scsi/fnic/fnic_scsi.c:98:38: warning: array subscript -1 is outside array bounds of 'struct scsi_cmnd[23529010298098917]' [-Warray-bounds]


vim +98 drivers/scsi/fnic/fnic_scsi.c

5df6d737dd4b0f Abhijeet Joglekar 2009-04-17 94
5df6d737dd4b0f Abhijeet Joglekar 2009-04-17 95 static inline spinlock_t *fnic_io_lock_hash(struct fnic *fnic,
5df6d737dd4b0f Abhijeet Joglekar 2009-04-17 96 struct scsi_cmnd *sc)
5df6d737dd4b0f Abhijeet Joglekar 2009-04-17 97 {
e1c9f0cfac4f2e Bart Van Assche 2021-08-09 @98 u32 hash = scsi_cmd_to_rq(sc)->tag & (FNIC_IO_LOCKS - 1);
5df6d737dd4b0f Abhijeet Joglekar 2009-04-17 99
5df6d737dd4b0f Abhijeet Joglekar 2009-04-17 100 return &fnic->io_req_lock[hash];
5df6d737dd4b0f Abhijeet Joglekar 2009-04-17 101 }
5df6d737dd4b0f Abhijeet Joglekar 2009-04-17 102

:::::: The code at line 98 was first introduced by commit
:::::: e1c9f0cfac4f2ed2bc6e89f2f4061dcf1538d4cd scsi: fnic: Use scsi_cmd_to_rq() instead of scsi_cmnd.request

:::::: TO: Bart Van Assche <bvanassche@xxxxxxx>
:::::: CC: Martin K. Petersen <martin.petersen@xxxxxxxxxx>

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