]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
bpf: Extract bpf_get_linfo_file_line
authorKumar Kartikeya Dwivedi <memxor@gmail.com>
Wed, 8 Apr 2026 02:13:53 +0000 (04:13 +0200)
committerAlexei Starovoitov <ast@kernel.org>
Thu, 9 Apr 2026 01:09:56 +0000 (18:09 -0700)
Extract bpf_get_linfo_file_line as its own function so that the logic to
obtain the file, line, and line number for a given program can be shared
in subsequent patches.

Reviewed-by: Puranjay Mohan <puranjay@kernel.org>
Acked-by: Mykyta Yatsenko <yatsenko@meta.com>
Signed-off-by: Kumar Kartikeya Dwivedi <memxor@gmail.com>
Link: https://lore.kernel.org/r/20260408021359.3786905-3-memxor@gmail.com
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
include/linux/bpf.h
kernel/bpf/core.c

index 30d35d5fe40b5ae2e3f5bec2c46599f2206bb838..d8fb9d61f5cee624e8944c4ab83163a87d3f0446 100644 (file)
@@ -3945,6 +3945,8 @@ static inline bool bpf_is_subprog(const struct bpf_prog *prog)
        return prog->aux->func_idx != 0;
 }
 
+void bpf_get_linfo_file_line(struct btf *btf, const struct bpf_line_info *linfo,
+                            const char **filep, const char **linep, int *nump);
 int bpf_prog_get_file_line(struct bpf_prog *prog, unsigned long ip, const char **filep,
                           const char **linep, int *nump);
 struct bpf_prog *bpf_prog_find_from_stack(void);
index 89b89f55415c397c84849e46dbe89e4cbd1fcd75..ada76f99717743315683399ad13606021a2b0461 100644 (file)
@@ -3315,6 +3315,26 @@ EXPORT_TRACEPOINT_SYMBOL_GPL(xdp_bulk_tx);
 
 #ifdef CONFIG_BPF_SYSCALL
 
+void bpf_get_linfo_file_line(struct btf *btf, const struct bpf_line_info *linfo,
+                            const char **filep, const char **linep, int *nump)
+{
+       /* Get base component of the file path. */
+       if (filep) {
+               *filep = btf_name_by_offset(btf, linfo->file_name_off);
+               *filep = kbasename(*filep);
+       }
+
+       /* Obtain the source line, and strip whitespace in prefix. */
+       if (linep) {
+               *linep = btf_name_by_offset(btf, linfo->line_off);
+               while (isspace(**linep))
+                       *linep += 1;
+       }
+
+       if (nump)
+               *nump = BPF_LINE_INFO_LINE_NUM(linfo->line_col);
+}
+
 int bpf_prog_get_file_line(struct bpf_prog *prog, unsigned long ip, const char **filep,
                           const char **linep, int *nump)
 {
@@ -3349,14 +3369,7 @@ int bpf_prog_get_file_line(struct bpf_prog *prog, unsigned long ip, const char *
        if (idx == -1)
                return -ENOENT;
 
-       /* Get base component of the file path. */
-       *filep = btf_name_by_offset(btf, linfo[idx].file_name_off);
-       *filep = kbasename(*filep);
-       /* Obtain the source line, and strip whitespace in prefix. */
-       *linep = btf_name_by_offset(btf, linfo[idx].line_off);
-       while (isspace(**linep))
-               *linep += 1;
-       *nump = BPF_LINE_INFO_LINE_NUM(linfo[idx].line_col);
+       bpf_get_linfo_file_line(btf, &linfo[idx], filep, linep, nump);
        return 0;
 }