Skip to contentSkip to conversation

drivers/ata/ahci_zhaoxin_sgpio.c:36 ahci_wait_em_reset() warn: variable dereferenced before check 'sgpio_zhaoxin' (see line 33)

PATCH New Dan Carpenter 1 participant 1 message Dec 18, 2024

lore
Share & tools
lore
#0 lore raw

PATCH 1640/1640 drivers/ata/ahci_zhaoxin_sgpio.c:36 ahci_wait_em_reset() warn: variable dereferenced before check 'sgpio_zhaoxin' (see line 33)

tree:   https://gitee.com/openeuler/kernel.git OLK-6.6
head:   46064348cc445799cf9e8fd030323a0426fbb5e4
commit: fb43492008c11fe89e510dd63383a2d37ea3cf8e [1640/1640] ata: ahci: Add support for AHCI SGPIO Enclosure Management
config: x86_64-randconfig-161-20241217 (https://download.01.org/0day-ci/archive/20241218/[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/ata/ahci_zhaoxin_sgpio.c:36 ahci_wait_em_reset() warn: variable dereferenced before check 'sgpio_zhaoxin' (see line 33) drivers/ata/ahci_zhaoxin_sgpio.c:335 ahci_transmit_sgpio_indicator_gp() warn: inconsistent returns '&sgpio_zhaoxin->wr_lock'.

vim +/sgpio_zhaoxin +36 drivers/ata/ahci_zhaoxin_sgpio.c

fb43492008c11f leoliu-oc 2024-06-18  31  int ahci_wait_em_reset(struct sgpio_zhaoxin *sgpio_zhaoxin, u32 retry)
fb43492008c11f leoliu-oc 2024-06-18  32  {
fb43492008c11f leoliu-oc 2024-06-18 @33  	void __iomem *mmio = sgpio_zhaoxin->mmio;
                                                                     ^^^^^^^^^^^^^^^

Dereferenced

fb43492008c11f leoliu-oc 2024-06-18 34 u32 em_ctl;
fb43492008c11f leoliu-oc 2024-06-18 35

fb43492008c11f leoliu-oc 2024-06-18 @36  	if (!sgpio_zhaoxin || retry == 0) {
                                                     ^^^^^^^^^^^^^

Checked too late

fb43492008c11f leoliu-oc 2024-06-18  37  		pr_err("In ahci wait em reset, invalid param\n");
fb43492008c11f leoliu-oc 2024-06-18  38  		return -EINVAL;
fb43492008c11f leoliu-oc 2024-06-18  39  	}
fb43492008c11f leoliu-oc 2024-06-18  40  
fb43492008c11f leoliu-oc 2024-06-18  41  	while (retry--) { /*EM_CTL needs reset at least 64ms*/
fb43492008c11f leoliu-oc 2024-06-18  42  		em_ctl = readl(mmio + HOST_EM_CTL);
fb43492008c11f leoliu-oc 2024-06-18  43  		if (em_ctl & EM_CTL_RST)
fb43492008c11f leoliu-oc 2024-06-18  44  			usleep_range(10000, 20000); /*EM_CTL still in reset, usleep 10ms*/
fb43492008c11f leoliu-oc 2024-06-18  45  		else
fb43492008c11f leoliu-oc 2024-06-18  46  			break;
fb43492008c11f leoliu-oc 2024-06-18  47  
fb43492008c11f leoliu-oc 2024-06-18  48  		if (!retry)
fb43492008c11f leoliu-oc 2024-06-18  49  			pr_err("Wait for EM_CTL reset, time out\n");
fb43492008c11f leoliu-oc 2024-06-18  50  	}
fb43492008c11f leoliu-oc 2024-06-18  51  
fb43492008c11f leoliu-oc 2024-06-18  52  	return 0;
fb43492008c11f leoliu-oc 2024-06-18  53  }
Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki