BPF List
 help / color / mirror / Atom feed
From: Tao Chen <chen.dylane@gmail.com>
To: ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org,
	eddyz87@gmail.com, 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: Fri, 14 Feb 2025 22:30:26 +0800	[thread overview]
Message-ID: <282976f0-772a-44cc-9d3d-b07f42a4b2cc@gmail.com> (raw)
In-Reply-To: <20250214141717.26847-1-chen.dylane@gmail.com>

在 2025/2/14 22:17, Tao Chen 写道:
> Just wrap the direct err with libbpf_err, keep consistency
> with other APIs.
> 
> Signed-off-by: Tao Chen <chen.dylane@gmail.com>
> ---
>   tools/lib/bpf/libbpf.c | 22 +++++++++++-----------
>   1 file changed, 11 insertions(+), 11 deletions(-)
> 
> diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
> index 194809da5172..6f2f3072f5a2 100644
> --- a/tools/lib/bpf/libbpf.c
> +++ b/tools/lib/bpf/libbpf.c
> @@ -9145,12 +9145,12 @@ int bpf_object__gen_loader(struct bpf_object *obj, struct gen_loader_opts *opts)
>   	struct bpf_gen *gen;
>   
>   	if (!opts)
> -		return -EFAULT;
> +		return libbpf_err(-EFAULT);
>   	if (!OPTS_VALID(opts, gen_loader_opts))
> -		return -EINVAL;
> +		return libbpf_err(-EINVAL);
>   	gen = calloc(sizeof(*gen), 1);
>   	if (!gen)
> -		return -ENOMEM;
> +		return libbpf_err(-ENOMEM);
>   	gen->opts = opts;
>   	gen->swapped_endian = !is_native_endianness(obj);
>   	obj->gen_loader = gen;
> @@ -9262,13 +9262,13 @@ int bpf_program__set_insns(struct bpf_program *prog,
>   	struct bpf_insn *insns;
>   
>   	if (prog->obj->loaded)
> -		return -EBUSY;
> +		return libbpf_err(-EBUSY);
>   
>   	insns = libbpf_reallocarray(prog->insns, new_insn_cnt, sizeof(*insns));
>   	/* NULL is a valid return from reallocarray if the new count is zero */
>   	if (!insns && new_insn_cnt) {
>   		pr_warn("prog '%s': failed to realloc prog code\n", prog->name);
> -		return -ENOMEM;
> +		return libbpf_err(-ENOMEM);
>   	}
>   	memcpy(insns, new_insns, new_insn_cnt * sizeof(*insns));
>   
> @@ -9379,11 +9379,11 @@ const char *bpf_program__log_buf(const struct bpf_program *prog, size_t *log_siz
>   int bpf_program__set_log_buf(struct bpf_program *prog, char *log_buf, size_t log_size)
>   {
>   	if (log_size && !log_buf)
> -		return -EINVAL;
> +		return libbpf_err(-EINVAL);
>   	if (prog->log_size > UINT_MAX)
> -		return -EINVAL;
> +		return libbpf_err(-EINVAL);
>   	if (prog->obj->loaded)
> -		return -EBUSY;
> +		return libbpf_err(-EBUSY);
>   
>   	prog->log_buf = log_buf;
>   	prog->log_size = log_size;
> @@ -13070,17 +13070,17 @@ int bpf_link__update_map(struct bpf_link *link, const struct bpf_map *map)
>   	int err;
>   
>   	if (!bpf_map__is_struct_ops(map))
> -		return -EINVAL;
> +		return libbpf_err(-EINVAL);
>   
>   	if (map->fd < 0) {
>   		pr_warn("map '%s': can't use BPF map without FD (was it created?)\n", map->name);
> -		return -EINVAL;
> +		return libbpf_err(-EINVAL);
>   	}
>   
>   	st_ops_link = container_of(link, struct bpf_link_struct_ops, link);
>   	/* Ensure the type of a link is correct */
>   	if (st_ops_link->map_fd < 0)
> -		return -EINVAL;
> +		return libbpf_err(-EINVAL);
>   
>   	err = bpf_map_update_elem(map->fd, &zero, map->st_ops->kern_vdata, 0);
>   	/* It can be EBUSY if the map has been used to create or

Forgive my carelessness. This patch was developed based on bpf-next. You 
can ignore it. I've resent it.

-- 
Best Regards
Dylane Chen

  reply	other threads:[~2025-02-14 14:30 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 [this message]
2025-02-19  2:08 ` Eduard Zingerman
2025-02-19  6:23   ` Tao Chen
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=282976f0-772a-44cc-9d3d-b07f42a4b2cc@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