drivers/perf/arm_cspmu/arm_cspmu.c:1075 arm_cspmu_find_cpu_container() warn: variable dereferenced before check 'cpu_dev' (see line 1073)
From: Dan Carpenter
Date: Wed Feb 22 2023 - 08:54:05 EST
tree: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master
head: 925cf0457d7e62ce08878ffb789189ac08ca8677
commit: e37dfd65731dc4f001fa7dfa7f705e6840017d5a perf: arm_cspmu: Add support for ARM CoreSight PMU driver
config: arm64-randconfig-m031-20230219 (https://download.01.org/0day-ci/archive/20230219/202302191227.kc0V8fM7-lkp@xxxxxxxxx/config)
compiler: aarch64-linux-gcc (GCC) 12.1.0
If you fix the issue, kindly add following tag where applicable
| Reported-by: kernel test robot <lkp@xxxxxxxxx>
| Reported-by: Dan Carpenter <error27@xxxxxxxxx>
| Link: https://lore.kernel.org/r/202302191227.kc0V8fM7-lkp@xxxxxxxxx/
smatch warnings:
drivers/perf/arm_cspmu/arm_cspmu.c:1075 arm_cspmu_find_cpu_container() warn: variable dereferenced before check 'cpu_dev' (see line 1073)
vim +/cpu_dev +1075 drivers/perf/arm_cspmu/arm_cspmu.c
e37dfd65731dc4 Besar Wicaksono 2022-11-11 1069 static inline int arm_cspmu_find_cpu_container(int cpu, u32 container_uid)
e37dfd65731dc4 Besar Wicaksono 2022-11-11 1070 {
e37dfd65731dc4 Besar Wicaksono 2022-11-11 1071 u32 acpi_uid;
e37dfd65731dc4 Besar Wicaksono 2022-11-11 1072 struct device *cpu_dev = get_cpu_device(cpu);
e37dfd65731dc4 Besar Wicaksono 2022-11-11 @1073 struct acpi_device *acpi_dev = ACPI_COMPANION(cpu_dev);
^^^^^^^
Dereference
e37dfd65731dc4 Besar Wicaksono 2022-11-11 1074
e37dfd65731dc4 Besar Wicaksono 2022-11-11 @1075 if (!cpu_dev)
^^^^^^^
Checked too late.
e37dfd65731dc4 Besar Wicaksono 2022-11-11 1076 return -ENODEV;
e37dfd65731dc4 Besar Wicaksono 2022-11-11 1077
e37dfd65731dc4 Besar Wicaksono 2022-11-11 1078 while (acpi_dev) {
e37dfd65731dc4 Besar Wicaksono 2022-11-11 1079 if (!strcmp(acpi_device_hid(acpi_dev),
e37dfd65731dc4 Besar Wicaksono 2022-11-11 1080 ACPI_PROCESSOR_CONTAINER_HID) &&
e37dfd65731dc4 Besar Wicaksono 2022-11-11 1081 !kstrtouint(acpi_device_uid(acpi_dev), 0, &acpi_uid) &&
e37dfd65731dc4 Besar Wicaksono 2022-11-11 1082 acpi_uid == container_uid)
e37dfd65731dc4 Besar Wicaksono 2022-11-11 1083 return 0;
e37dfd65731dc4 Besar Wicaksono 2022-11-11 1084
e37dfd65731dc4 Besar Wicaksono 2022-11-11 1085 acpi_dev = acpi_dev_parent(acpi_dev);
e37dfd65731dc4 Besar Wicaksono 2022-11-11 1086 }
e37dfd65731dc4 Besar Wicaksono 2022-11-11 1087
e37dfd65731dc4 Besar Wicaksono 2022-11-11 1088 return -ENODEV;
e37dfd65731dc4 Besar Wicaksono 2022-11-11 1089 }
--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests