lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [day] [month] [year] [list]
Message-ID: <e3648550-7207-44db-a7a8-41640ea958ad@kili.mountain>
Date:   Mon, 20 Mar 2023 08:23:01 +0300
From:   Dan Carpenter <error27@...il.com>
To:     oe-kbuild@...ts.linux.dev, Eric Lin <eric.lin@...ive.com>
Cc:     lkp@...el.com, oe-kbuild-all@...ts.linux.dev,
        linux-kernel@...r.kernel.org, Will Deacon <will@...nel.org>
Subject: drivers/perf/riscv_pmu_sbi.c:802 pmu_sbi_device_probe() warn:
 missing unwind goto?

tree:   https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master
head:   e8d018dd0257f744ca50a729e3d042cf2ec9da65
commit: e9a023f2b73ac35ff5cfbefe8524c64d8173d65f drivers/perf: riscv_pmu: Add riscv pmu pm notifier
config: riscv-randconfig-m031-20230319 (https://download.01.org/0day-ci/archive/20230320/202303200941.4TSDQb89-lkp@intel.com/config)
compiler: riscv32-linux-gcc (GCC) 12.1.0

If you fix the issue, kindly add following tag where applicable
| Reported-by: kernel test robot <lkp@...el.com>
| Reported-by: Dan Carpenter <error27@...il.com>
| Link: https://lore.kernel.org/r/202303200941.4TSDQb89-lkp@intel.com/

New smatch warnings:
drivers/perf/riscv_pmu_sbi.c:802 pmu_sbi_device_probe() warn: missing unwind goto?

vim +802 drivers/perf/riscv_pmu_sbi.c

e9991434596f53 Atish Patra 2022-02-18  764  static int pmu_sbi_device_probe(struct platform_device *pdev)
e9991434596f53 Atish Patra 2022-02-18  765  {
e9991434596f53 Atish Patra 2022-02-18  766  	struct riscv_pmu *pmu = NULL;
e9991434596f53 Atish Patra 2022-02-18  767  	int num_counters;
4905ec2fb7e642 Atish Patra 2022-02-18  768  	int ret = -ENODEV;
e9991434596f53 Atish Patra 2022-02-18  769  
e9991434596f53 Atish Patra 2022-02-18  770  	pr_info("SBI PMU extension is available\n");
e9991434596f53 Atish Patra 2022-02-18  771  	pmu = riscv_pmu_alloc();
e9991434596f53 Atish Patra 2022-02-18  772  	if (!pmu)
e9991434596f53 Atish Patra 2022-02-18  773  		return -ENOMEM;
e9991434596f53 Atish Patra 2022-02-18  774  
e9991434596f53 Atish Patra 2022-02-18  775  	num_counters = pmu_sbi_find_num_ctrs();
e9991434596f53 Atish Patra 2022-02-18  776  	if (num_counters < 0) {
e9991434596f53 Atish Patra 2022-02-18  777  		pr_err("SBI PMU extension doesn't provide any counters\n");
4905ec2fb7e642 Atish Patra 2022-02-18  778  		goto out_free;
e9991434596f53 Atish Patra 2022-02-18  779  	}
e9991434596f53 Atish Patra 2022-02-18  780  
e9991434596f53 Atish Patra 2022-02-18  781  	/* cache all the information about counters now */
e9991434596f53 Atish Patra 2022-02-18  782  	if (pmu_sbi_get_ctrinfo(num_counters))
4905ec2fb7e642 Atish Patra 2022-02-18  783  		goto out_free;

Better to preserve the error code from pmu_sbi_get_ctrinfo() instead of
just returning -ENODEV;

e9991434596f53 Atish Patra 2022-02-18  784  
4905ec2fb7e642 Atish Patra 2022-02-18  785  	ret = pmu_sbi_setup_irqs(pmu, pdev);
4905ec2fb7e642 Atish Patra 2022-02-18  786  	if (ret < 0) {
4905ec2fb7e642 Atish Patra 2022-02-18  787  		pr_info("Perf sampling/filtering is not supported as sscof extension is not available\n");
4905ec2fb7e642 Atish Patra 2022-02-18  788  		pmu->pmu.capabilities |= PERF_PMU_CAP_NO_INTERRUPT;
4905ec2fb7e642 Atish Patra 2022-02-18  789  		pmu->pmu.capabilities |= PERF_PMU_CAP_NO_EXCLUDE;
4905ec2fb7e642 Atish Patra 2022-02-18  790  	}
e9991434596f53 Atish Patra 2022-02-18  791  	pmu->num_counters = num_counters;
e9991434596f53 Atish Patra 2022-02-18  792  	pmu->ctr_start = pmu_sbi_ctr_start;
e9991434596f53 Atish Patra 2022-02-18  793  	pmu->ctr_stop = pmu_sbi_ctr_stop;
e9991434596f53 Atish Patra 2022-02-18  794  	pmu->event_map = pmu_sbi_event_map;
e9991434596f53 Atish Patra 2022-02-18  795  	pmu->ctr_get_idx = pmu_sbi_ctr_get_idx;
e9991434596f53 Atish Patra 2022-02-18  796  	pmu->ctr_get_width = pmu_sbi_ctr_get_width;
e9991434596f53 Atish Patra 2022-02-18  797  	pmu->ctr_clear_idx = pmu_sbi_ctr_clear_idx;
e9991434596f53 Atish Patra 2022-02-18  798  	pmu->ctr_read = pmu_sbi_ctr_read;
e9991434596f53 Atish Patra 2022-02-18  799  
e9991434596f53 Atish Patra 2022-02-18  800  	ret = cpuhp_state_add_instance(CPUHP_AP_PERF_RISCV_STARTING, &pmu->node);
e9991434596f53 Atish Patra 2022-02-18  801  	if (ret)
e9991434596f53 Atish Patra 2022-02-18 @802  		return ret;

This needs to clean up before returning.

The out_unregister name is misleading because it doesn't undo the
perf_pmu_register() as you would expect based on the name.  Also
pmu_sbi_get_ctrinfo() and pmu_sbi_setup_irqs() should really have been
cleaned up.

There is a system that people often use to write error handling in a
straight forward way:
https://staticthinking.wordpress.com/2022/04/28/free-the-last-thing-style/

e9991434596f53 Atish Patra 2022-02-18  803  
e9a023f2b73ac3 Eric Lin    2022-07-05  804  	ret = riscv_pm_pmu_register(pmu);
e9a023f2b73ac3 Eric Lin    2022-07-05  805  	if (ret)
e9a023f2b73ac3 Eric Lin    2022-07-05  806  		goto out_unregister;
e9a023f2b73ac3 Eric Lin    2022-07-05  807  
e9991434596f53 Atish Patra 2022-02-18  808  	ret = perf_pmu_register(&pmu->pmu, "cpu", PERF_TYPE_RAW);
e9a023f2b73ac3 Eric Lin    2022-07-05  809  	if (ret)
e9a023f2b73ac3 Eric Lin    2022-07-05  810  		goto out_unregister;
e9991434596f53 Atish Patra 2022-02-18  811  
e9991434596f53 Atish Patra 2022-02-18  812  	return 0;
4905ec2fb7e642 Atish Patra 2022-02-18  813  
e9a023f2b73ac3 Eric Lin    2022-07-05  814  out_unregister:
e9a023f2b73ac3 Eric Lin    2022-07-05  815  	riscv_pmu_destroy(pmu);
e9a023f2b73ac3 Eric Lin    2022-07-05  816  
4905ec2fb7e642 Atish Patra 2022-02-18  817  out_free:
4905ec2fb7e642 Atish Patra 2022-02-18  818  	kfree(pmu);
4905ec2fb7e642 Atish Patra 2022-02-18  819  	return ret;
e9991434596f53 Atish Patra 2022-02-18  820  }

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

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ