]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
perf lock: Fix return code for functions in __cmd_contention
authorAthira Rajeev <atrajeev@linux.vnet.ibm.com>
Fri, 10 Jan 2025 09:37:30 +0000 (15:07 +0530)
committerNamhyung Kim <namhyung@kernel.org>
Fri, 17 Jan 2025 18:09:54 +0000 (10:09 -0800)
perf lock contention returns zero exit value even if the lock contention
BPF setup failed.

  # ./perf lock con -b true
  libbpf: kernel BTF is missing at '/sys/kernel/btf/vmlinux', was CONFIG_DEBUG_INFO_BTF enabled?
  libbpf: failed to find '.BTF' ELF section in /lib/modules/6.13.0-rc3+/build/vmlinux
  libbpf: failed to find valid kernel BTF
  libbpf: kernel BTF is missing at '/sys/kernel/btf/vmlinux', was CONFIG_DEBUG_INFO_BTF enabled?
  libbpf: failed to find '.BTF' ELF section in /lib/modules/6.13.0-rc3+/build/vmlinux
  libbpf: failed to find valid kernel BTF
  libbpf: Error loading vmlinux BTF: -ESRCH
  libbpf: failed to load object 'lock_contention_bpf'
  libbpf: failed to load BPF skeleton 'lock_contention_bpf': -ESRCH
  Failed to load lock-contention BPF skeleton
  lock contention BPF setup failed
  # echo $?
   0

Fix this by saving the return code for lock_contention_prepare
so that command exits with proper return code. Similarly set the
return code properly for two other functions in builtin-lock, namely
setup_output_field() and select_key().

Signed-off-by: Athira Rajeev <atrajeev@linux.vnet.ibm.com>
Reviewed-by: Namhyung Kim <namhyung@kernel.org>
Link: https://lore.kernel.org/r/20250110093730.93610-1-atrajeev@linux.vnet.ibm.com
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
tools/perf/builtin-lock.c

index 208c482daa56ef9356150c261802d362e561cb71..94a2bc15a2fa718732d5f2c937bf9054a4e3fa45 100644 (file)
@@ -2049,7 +2049,8 @@ static int __cmd_contention(int argc, const char **argv)
                                goto out_delete;
                }
 
-               if (lock_contention_prepare(&con) < 0) {
+               err = lock_contention_prepare(&con);
+               if (err < 0) {
                        pr_err("lock contention BPF setup failed\n");
                        goto out_delete;
                }
@@ -2070,10 +2071,14 @@ static int __cmd_contention(int argc, const char **argv)
                }
        }
 
-       if (setup_output_field(true, output_fields))
+       err = setup_output_field(true, output_fields);
+       if (err) {
+               pr_err("Failed to setup output field\n");
                goto out_delete;
+       }
 
-       if (select_key(true))
+       err = select_key(true);
+       if (err)
                goto out_delete;
 
        if (symbol_conf.field_sep) {