Skip to contentSkip to conversation

drivers/i2c/busses/i2c-xiic.c:932 xiic_recv_atomic() warn: variable dereferenced before check 'i2c->rx_msg' (see line 930)

PATCH New Dan Carpenter 1 participant 1 message Nov 30, 2024

lore
Share & tools
lore
#0 lore raw

PATCH 11908/12916 drivers/i2c/busses/i2c-xiic.c:932 xiic_recv_atomic() warn: variable dereferenced before check 'i2c->rx_msg' (see line 930)

tree:   https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git master
head:   6f3d2b5299b0a8bcb8a9405a8d3fceb24f79c4f0
commit: 8bba86687c0b6a22f05ed4a7398c519d3796bc74 [11908/12916] i2c: xiic: Add atomic transfer support
config: i386-randconfig-141-20241121 (https://download.01.org/0day-ci/archive/20241128/[email protected]/config)
compiler: clang version 19.1.3 (https://github.com/llvm/llvm-project ab51eccf88f5321e7c60591c5546b254b6afab99)

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 <[email protected]>
| Reported-by: Dan Carpenter <[email protected]>
| Closes: https://lore.kernel.org/r/[email protected]/

smatch warnings:
drivers/i2c/busses/i2c-xiic.c:932 xiic_recv_atomic() warn: variable dereferenced before check 'i2c->rx_msg' (see line 930)

vim +932 drivers/i2c/busses/i2c-xiic.c

8bba86687c0b6a Manikanta Guntupalli 2024-10-11  928  static void xiic_recv_atomic(struct xiic_i2c *i2c)
8bba86687c0b6a Manikanta Guntupalli 2024-10-11  929  {
8bba86687c0b6a Manikanta Guntupalli 2024-10-11 @930  	while (xiic_rx_space(i2c)) {
                                                                             ^^^

The xiic_rx_space() macro dereferences i2c->rx_msg.

8bba86687c0b6a Manikanta Guntupalli 2024-10-11 931 if (xiic_getreg32(i2c, XIIC_IISR_OFFSET) & XIIC_INTR_RX_FULL_MASK) {

8bba86687c0b6a Manikanta Guntupalli 2024-10-11 @932  			if (!i2c->rx_msg) {
                                                                            ^^^^^^^^^^^^

Inconsistent NULL check.

8bba86687c0b6a Manikanta Guntupalli 2024-10-11  933  				xiic_clear_rx_fifo(i2c);
8bba86687c0b6a Manikanta Guntupalli 2024-10-11  934  				break;
8bba86687c0b6a Manikanta Guntupalli 2024-10-11  935  			}
8bba86687c0b6a Manikanta Guntupalli 2024-10-11  936  			xiic_read_rx(i2c);
8bba86687c0b6a Manikanta Guntupalli 2024-10-11  937  
8bba86687c0b6a Manikanta Guntupalli 2024-10-11  938  			/* Clear Rx full and Tx error interrupts. */
8bba86687c0b6a Manikanta Guntupalli 2024-10-11  939  			xiic_irq_clr_en(i2c, XIIC_INTR_RX_FULL_MASK |
8bba86687c0b6a Manikanta Guntupalli 2024-10-11  940  					XIIC_INTR_TX_ERROR_MASK);
8bba86687c0b6a Manikanta Guntupalli 2024-10-11  941  		}
8bba86687c0b6a Manikanta Guntupalli 2024-10-11  942  		if (xiic_error_check(i2c))
8bba86687c0b6a Manikanta Guntupalli 2024-10-11  943  			return;
8bba86687c0b6a Manikanta Guntupalli 2024-10-11  944  	}
8bba86687c0b6a Manikanta Guntupalli 2024-10-11  945  
8bba86687c0b6a Manikanta Guntupalli 2024-10-11  946  	i2c->rx_msg = NULL;
8bba86687c0b6a Manikanta Guntupalli 2024-10-11  947  	xiic_irq_clr_en(i2c, XIIC_INTR_TX_ERROR_MASK);
8bba86687c0b6a Manikanta Guntupalli 2024-10-11  948  
8bba86687c0b6a Manikanta Guntupalli 2024-10-11  949  	/* send next message if this wasn't the last. */
8bba86687c0b6a Manikanta Guntupalli 2024-10-11  950  	if (i2c->nmsgs > 1) {
8bba86687c0b6a Manikanta Guntupalli 2024-10-11  951  		i2c->nmsgs--;
8bba86687c0b6a Manikanta Guntupalli 2024-10-11  952  		i2c->tx_msg++;
8bba86687c0b6a Manikanta Guntupalli 2024-10-11  953  		__xiic_start_xfer(i2c);
8bba86687c0b6a Manikanta Guntupalli 2024-10-11  954  	}
8bba86687c0b6a Manikanta Guntupalli 2024-10-11  955  }
Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki