All of lore.kernel.org
 help / color / mirror / Atom feed
From: Yonghong Song <yhs@fb.com>
To: <bpf@vger.kernel.org>
Cc: Alexei Starovoitov <ast@kernel.org>,
	Andrii Nakryiko <andrii@kernel.org>,
	Daniel Borkmann <daniel@iogearbox.net>, <kernel-team@fb.com>
Subject: [PATCH bpf-next v5 04/17] libbpf: Refactor btf__add_enum() for future code sharing
Date: Mon, 6 Jun 2022 23:26:15 -0700	[thread overview]
Message-ID: <20220607062615.3718063-1-yhs@fb.com> (raw)
In-Reply-To: <20220607062554.3716237-1-yhs@fb.com>

Refactor btf__add_enum() function to create a separate
function btf_add_enum_common() so later the common function
can be used to add enum64 btf type. There is no functionality
change for this patch.

Acked-by: Andrii Nakryiko <andrii@kernel.org>
Signed-off-by: Yonghong Song <yhs@fb.com>
---
 tools/lib/bpf/btf.c | 36 +++++++++++++++++++++---------------
 1 file changed, 21 insertions(+), 15 deletions(-)

diff --git a/tools/lib/bpf/btf.c b/tools/lib/bpf/btf.c
index 2e9c23bcdc67..1972d0c65e0c 100644
--- a/tools/lib/bpf/btf.c
+++ b/tools/lib/bpf/btf.c
@@ -2129,20 +2129,8 @@ int btf__add_field(struct btf *btf, const char *name, int type_id,
 	return 0;
 }
 
-/*
- * Append new BTF_KIND_ENUM type with:
- *   - *name* - name of the enum, can be NULL or empty for anonymous enums;
- *   - *byte_sz* - size of the enum, in bytes.
- *
- * Enum initially has no enum values in it (and corresponds to enum forward
- * declaration). Enumerator values can be added by btf__add_enum_value()
- * immediately after btf__add_enum() succeeds.
- *
- * Returns:
- *   - >0, type ID of newly added BTF type;
- *   - <0, on error.
- */
-int btf__add_enum(struct btf *btf, const char *name, __u32 byte_sz)
+static int btf_add_enum_common(struct btf *btf, const char *name, __u32 byte_sz,
+			       bool is_signed, __u8 kind)
 {
 	struct btf_type *t;
 	int sz, name_off = 0;
@@ -2167,12 +2155,30 @@ int btf__add_enum(struct btf *btf, const char *name, __u32 byte_sz)
 
 	/* start out with vlen=0; it will be adjusted when adding enum values */
 	t->name_off = name_off;
-	t->info = btf_type_info(BTF_KIND_ENUM, 0, 0);
+	t->info = btf_type_info(kind, 0, is_signed);
 	t->size = byte_sz;
 
 	return btf_commit_type(btf, sz);
 }
 
+/*
+ * Append new BTF_KIND_ENUM type with:
+ *   - *name* - name of the enum, can be NULL or empty for anonymous enums;
+ *   - *byte_sz* - size of the enum, in bytes.
+ *
+ * Enum initially has no enum values in it (and corresponds to enum forward
+ * declaration). Enumerator values can be added by btf__add_enum_value()
+ * immediately after btf__add_enum() succeeds.
+ *
+ * Returns:
+ *   - >0, type ID of newly added BTF type;
+ *   - <0, on error.
+ */
+int btf__add_enum(struct btf *btf, const char *name, __u32 byte_sz)
+{
+	return btf_add_enum_common(btf, name, byte_sz, false, BTF_KIND_ENUM);
+}
+
 /*
  * Append new enum value for the current ENUM type with:
  *   - *name* - name of the enumerator value, can't be NULL or empty;
-- 
2.30.2


  parent reply	other threads:[~2022-06-07  6:26 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-07  6:25 [PATCH bpf-next v5 00/17] bpf: Add 64bit enum value support Yonghong Song
2022-06-07  6:26 ` [PATCH bpf-next v5 01/17] bpf: Add btf enum64 support Yonghong Song
2022-06-07  6:26 ` [PATCH bpf-next v5 02/17] libbpf: Permit 64bit relocation value Yonghong Song
2022-06-07  6:26 ` [PATCH bpf-next v5 03/17] libbpf: Fix an error in 64bit relocation value computation Yonghong Song
2022-06-07  6:26 ` Yonghong Song [this message]
2022-06-07  6:26 ` [PATCH bpf-next v5 05/17] libbpf: Add enum64 parsing and new enum64 public API Yonghong Song
2022-06-07  6:26 ` [PATCH bpf-next v5 06/17] libbpf: Add enum64 deduplication support Yonghong Song
2022-06-07  6:26 ` [PATCH bpf-next v5 07/17] libbpf: Add enum64 support for btf_dump Yonghong Song
2022-06-07  6:26 ` [PATCH bpf-next v5 08/17] libbpf: Add enum64 sanitization Yonghong Song
2022-06-07  6:26 ` [PATCH bpf-next v5 09/17] libbpf: Add enum64 support for bpf linking Yonghong Song
2022-06-07  6:26 ` [PATCH bpf-next v5 10/17] libbpf: Add enum64 relocation support Yonghong Song
2022-06-07  6:26 ` [PATCH bpf-next v5 11/17] bpftool: Add btf enum64 support Yonghong Song
2022-06-07  6:26 ` [PATCH bpf-next v5 12/17] selftests/bpf: Fix selftests failure Yonghong Song
2022-06-07  6:27 ` [PATCH bpf-next v5 13/17] selftests/bpf: Test new enum kflag and enum64 API functions Yonghong Song
2022-06-07  6:27 ` [PATCH bpf-next v5 14/17] selftests/bpf: Add BTF_KIND_ENUM64 unit tests Yonghong Song
2022-06-07  6:27 ` [PATCH bpf-next v5 15/17] selftests/bpf: Test BTF_KIND_ENUM64 for deduplication Yonghong Song
2022-06-07  6:27 ` [PATCH bpf-next v5 16/17] selftests/bpf: Add a test for enum64 value relocations Yonghong Song
2022-06-07  6:27 ` [PATCH bpf-next v5 17/17] docs/bpf: Update documentation for BTF_KIND_ENUM64 support Yonghong Song
2022-06-07 17:40 ` [PATCH bpf-next v5 00/17] bpf: Add 64bit enum value support patchwork-bot+netdevbpf

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=20220607062615.3718063-1-yhs@fb.com \
    --to=yhs@fb.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=kernel-team@fb.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.