Skip to contentSkip to conversation

drivers/spi/spi.c:1510 spi_do_calibration() warn: variable dereferenced before check 'ctlr->cal_rule' (see line 1497)

PATCH New Dan Carpenter 1 participant 1 message Jan 6, 2025

lore
Share & tools
lore
#0 lore raw

PATCH 68/85 drivers/spi/spi.c:1510 spi_do_calibration() warn: variable dereferenced before check 'ctlr->cal_rule' (see line 1497)

tree:   https://github.com/frank-w/BPI-R2-4.14 6.13-rsslro
head:   71039e5e1e5f0b4e55c5f6279c659b58e05819c8
commit: 3f003bfdabf11d3f9fc47fecd2fe46b5447deea2 [68/85] drivers: spi: Add support for dynamic calibration
config: x86_64-randconfig-161-20241222 (https://download.01.org/0day-ci/archive/20241222/[email protected]/config)
compiler: gcc-12 (Debian 12.2.0-14) 12.2.0

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/spi/spi.c:1510 spi_do_calibration() warn: variable dereferenced before check 'ctlr->cal_rule' (see line 1497)

vim +1510 drivers/spi/spi.c

3f003bfdabf11d SkyLake.Huang  2022-06-23  1494  int spi_do_calibration(struct spi_controller *ctlr, struct spi_device *spi,
3f003bfdabf11d SkyLake.Huang  2022-06-23  1495  	int (*cal_read)(void *priv, u32 *addr, int addrlen, u8 *buf, int readlen), void *drv_priv)
3f003bfdabf11d SkyLake.Huang  2022-06-23  1496  {
3f003bfdabf11d SkyLake.Huang  2022-06-23 @1497  	int datalen = ctlr->cal_rule->datalen;
3f003bfdabf11d SkyLake.Huang  2022-06-23  1498  	int addrlen = ctlr->cal_rule->addrlen;
                                                                      ^^^^^^^^^^^^^^^^

Dereferences

3f003bfdabf11d SkyLake.Huang  2022-06-23  1499  	u8 *buf;
3f003bfdabf11d SkyLake.Huang  2022-06-23  1500  	int ret;
3f003bfdabf11d SkyLake.Huang  2022-06-23  1501  	int i;
3f003bfdabf11d SkyLake.Huang  2022-06-23  1502  	struct list_head *cal_head, *listptr;
3f003bfdabf11d SkyLake.Huang  2022-06-23  1503  	struct spi_cal_target *target;
3f003bfdabf11d SkyLake.Huang  2022-06-23  1504  
3f003bfdabf11d SkyLake.Huang  2022-06-23  1505  	/* Calculate calibration result */
3f003bfdabf11d SkyLake.Huang  2022-06-23  1506  	int hit_val, total_hit, origin;
3f003bfdabf11d SkyLake.Huang  2022-06-23  1507  	bool hit;
3f003bfdabf11d SkyLake.Huang  2022-06-23  1508  
3f003bfdabf11d SkyLake.Huang  2022-06-23  1509  	/* Make sure we can start calibration */
3f003bfdabf11d SkyLake.Huang  2022-06-23 @1510  	if(!ctlr->cal_target || !ctlr->cal_rule || !ctlr->append_caldata)
                                                                                ^^^^^^^^^^^^^^^

NULL check is too late.

3f003bfdabf11d SkyLake.Huang  2022-06-23  1511  		return 0;
3f003bfdabf11d SkyLake.Huang  2022-06-23  1512  
3f003bfdabf11d SkyLake.Huang  2022-06-23  1513  	buf = kzalloc(datalen * sizeof(u8), GFP_KERNEL);
3f003bfdabf11d SkyLake.Huang  2022-06-23  1514  	if(!buf)
3f003bfdabf11d SkyLake.Huang  2022-06-23  1515  		return -ENOMEM;
Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki