2023-03-20 05:23:17

by Dan Carpenter

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

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