BPF List
 help / color / mirror / Atom feed
From: Tao Chen <chen.dylane@gmail.com>
To: Eduard Zingerman <eddyz87@gmail.com>,
	ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org,
	haoluo@google.com, jolsa@kernel.org, qmo@kernel.org
Cc: bpf@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] libbpf: Wrap libbpf API direct err with libbpf_err
Date: Wed, 19 Feb 2025 14:23:35 +0800	[thread overview]
Message-ID: <9df12336-ca00-4d45-a832-24203c334df7@gmail.com> (raw)
In-Reply-To: <88f0c25cc981f958e46d51560fbf6db7136a3fa0.camel@gmail.com>

在 2025/2/19 10:08, Eduard Zingerman 写道:
> On Fri, 2025-02-14 at 22:17 +0800, Tao Chen wrote:
>> Just wrap the direct err with libbpf_err, keep consistency
>> with other APIs.
>>
>> Signed-off-by: Tao Chen <chen.dylane@gmail.com>
>> ---
> 
> While at it, I've noticed two more places that need libbpf_err() calls.
> Could you please check the following locations:
> 
> bpf_map__set_value_size:
>    return -EOPNOTSUPP;       tools/lib/bpf/libbpf.c:10309
>    return err;               tools/lib/bpf/libbpf.c:10317

Will change it. Thanks

> 
> ?
> 
> Other than that, I agree with changes in this patch.
> 
> Acked-by: Eduard Zingerman <eddyz87@gmail.com>
> 
> [...]
> 

I use a simple script, other places may also should be added:

9727 line: return NUL; (API:libbpf_bpf_attach_type_str)
9735 line: return NULL; (API: libbpf_bpf_link_type_str)
9743 line: return NULL; (API: libbpf_bpf_map_type_str)
9751 line: return NULL; (API: libbpf_bpf_prog_type_str)
10151 line: return NULL; (API: bpf_map__name)
10458 line: return NULL; (API: bpf_object__prev_map)

-----------------------------------------------
#!/bin/python3
import re

LIBBPF_PATH="tools/lib/bpf/"

def process_functions(file_path, target_functions):
     """
     find return err fix
     Args:
         file_path: like libbpf.c btf.c etc.
         target_functions: libbpf APIS
     """
     with open(file_path, 'r') as file:
         lines = file.readlines()

     function_info = {func: {'start': None, 'end': None, 'code': []} for 
func in target_functions}

     in_target_function = False
     current_function = None

     for i, line in enumerate(lines):
         # check the start line
         for func in target_functions:
             if re.search(re.escape(func) + r'\s*\(', line):
                 if ' __' in line:
                     continue
                 if '=' in line:
                     continue
                 if 'if' in line:
                     continue
                 if ';' in line:
                     continue
                 if '*' in func:
                     continue
                 in_target_function = True
                 current_function = func
                 function_info[func]['start'] = i
                 function_info[func]['code'].append(line)
                 break

         # check return err in target function
         if in_target_function and current_function:
             function_info[current_function]['code'].append(line)
             if re.search(r'\breturn\b', line):
                 # check return
                 if not re.search(r'\breturn\s+0\b', line):  # return 0 
ignore
                     if not re.search(r'libbpf_err|libbpf_ptr', line):
                         print(f"code should fix at {i + 1} line: 
{line.strip()} (API: {current_function})")

             # check function end line
             if re.search(r'}', line):
                 function_info[current_function]['end'] = i
                 in_target_function = False
                 current_function = None  # Reset for the next function


def extract_libbpf_apis(map_file):
     """
     extract APIS from libbpf.map
     Args:
         map_file (str): libbpf.map。
     Returns:
         list: libbpf APIs。
     """
     functions = []
     inside_global_section = False

     with open(map_file, 'r') as f:
         for line in f:
             line = line.strip()
             if ';' in line and 'LIBBPF' not in line:
                 functions.append(line.replace(';',''))

     return functions

map_file = "tools/lib/bpf/libbpf.map"
input_files = ["libbpf.c",
                "btf.c",
                "bpf_prog_linfo.c",
                "btf_dump.c",
                "btf_iter.c",
                "btf_relocate.c",
                "elf.c",
                "features.c",
                "gen_loader.c",
                "hashmap.c",
                "libbpf_probes.c",
                "linker.c",
                "netlink.c",
                "nlattr.c",
                "relo_core.c",
                "usdt.c",
                "zip.c",
                "str_error.c",
                "strset.c"]

target_functions = extract_libbpf_apis(map_file)
print(f"Target functions extracted: {target_functions}")

for input_file in input_files:
     print(f"===========check file:{input_file}=============")
     process_functions(LIBBPF_PATH + input_file, target_functions)

-- 
Best Regards
Dylane Chen

  reply	other threads:[~2025-02-19  6:23 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-02-14 14:17 [PATCH] libbpf: Wrap libbpf API direct err with libbpf_err Tao Chen
2025-02-14 14:30 ` Tao Chen
2025-02-19  2:08 ` Eduard Zingerman
2025-02-19  6:23   ` Tao Chen [this message]
2025-02-19  6:34     ` Eduard Zingerman
2025-02-19 15:15       ` Tao Chen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=9df12336-ca00-4d45-a832-24203c334df7@gmail.com \
    --to=chen.dylane@gmail.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=eddyz87@gmail.com \
    --cc=haoluo@google.com \
    --cc=jolsa@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=qmo@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox