diff mbox series

[bpf-next,v2,03/11] btf: Add BTF_ID_LIST_SINGLE macro

Message ID 20200909171155.256601-4-lmb@cloudflare.com
State Changes Requested
Delegated to: BPF Maintainers
Headers show
Series Make check_func_arg type checks table driven | expand

Commit Message

Lorenz Bauer Sept. 9, 2020, 5:11 p.m. UTC
Add a convenience macro that allows defining a BTF ID list with
a single item. This lets us cut down on repetitive macros.

Signed-off-by: Lorenz Bauer <lmb@cloudflare.com>
Suggested-by: Andrii Nakryiko <andriin@fb.com>
---
 include/linux/btf_ids.h | 7 +++++++
 1 file changed, 7 insertions(+)

Comments

Martin KaFai Lau Sept. 9, 2020, 6:09 p.m. UTC | #1
On Wed, Sep 09, 2020 at 06:11:47PM +0100, Lorenz Bauer wrote:
> Add a convenience macro that allows defining a BTF ID list with
> a single item. This lets us cut down on repetitive macros.
> 
> Signed-off-by: Lorenz Bauer <lmb@cloudflare.com>
> Suggested-by: Andrii Nakryiko <andriin@fb.com>
> ---
>  include/linux/btf_ids.h | 7 +++++++
>  1 file changed, 7 insertions(+)
> 
> diff --git a/include/linux/btf_ids.h b/include/linux/btf_ids.h
> index 210b086188a3..d6a959572175 100644
> --- a/include/linux/btf_ids.h
> +++ b/include/linux/btf_ids.h
> @@ -76,6 +76,13 @@ extern u32 name[];
>  #define BTF_ID_LIST_GLOBAL(name)			\
>  __BTF_ID_LIST(name, globl)
>  
> +/* The BTF_ID_LIST_SINGLE macro defines a BTF_ID_LIST with
> + * a single entry.
> + */
> +#define BTF_ID_LIST_SINGLE(name, prefix, typename)	\
> +	BTF_ID_LIST(name) \
> +	BTF_ID(prefix, typename)
> +
The same is needed for the "#else" part when CONFIG_DEBUG_INFO_BTF is
not enabled.
Andrii Nakryiko Sept. 10, 2020, 6:49 p.m. UTC | #2
On Wed, Sep 9, 2020 at 10:13 AM Lorenz Bauer <lmb@cloudflare.com> wrote:
>
> Add a convenience macro that allows defining a BTF ID list with
> a single item. This lets us cut down on repetitive macros.
>
> Signed-off-by: Lorenz Bauer <lmb@cloudflare.com>
> Suggested-by: Andrii Nakryiko <andriin@fb.com>
> ---
>  include/linux/btf_ids.h | 7 +++++++
>  1 file changed, 7 insertions(+)
>
> diff --git a/include/linux/btf_ids.h b/include/linux/btf_ids.h
> index 210b086188a3..d6a959572175 100644
> --- a/include/linux/btf_ids.h
> +++ b/include/linux/btf_ids.h
> @@ -76,6 +76,13 @@ extern u32 name[];
>  #define BTF_ID_LIST_GLOBAL(name)                       \
>  __BTF_ID_LIST(name, globl)
>
> +/* The BTF_ID_LIST_SINGLE macro defines a BTF_ID_LIST with
> + * a single entry.
> + */
> +#define BTF_ID_LIST_SINGLE(name, prefix, typename)     \
> +       BTF_ID_LIST(name) \
> +       BTF_ID(prefix, typename)
> +

This is a very minor improvement over open coded

BTF_ID_LIST(name)
BTF_ID(prefix, typename)

It made way more sense for SET, due to duplication of set name in START/END.

But I don't mind it either.

>  /*
>   * The BTF_ID_UNUSED macro defines 4 zero bytes.
>   * It's used when we want to define 'unused' entry
> --
> 2.25.1
>
diff mbox series

Patch

diff --git a/include/linux/btf_ids.h b/include/linux/btf_ids.h
index 210b086188a3..d6a959572175 100644
--- a/include/linux/btf_ids.h
+++ b/include/linux/btf_ids.h
@@ -76,6 +76,13 @@  extern u32 name[];
 #define BTF_ID_LIST_GLOBAL(name)			\
 __BTF_ID_LIST(name, globl)
 
+/* The BTF_ID_LIST_SINGLE macro defines a BTF_ID_LIST with
+ * a single entry.
+ */
+#define BTF_ID_LIST_SINGLE(name, prefix, typename)	\
+	BTF_ID_LIST(name) \
+	BTF_ID(prefix, typename)
+
 /*
  * The BTF_ID_UNUSED macro defines 4 zero bytes.
  * It's used when we want to define 'unused' entry