libbpf: constify few bpf_program getters
Subsystems (4)
Andrii Nakryiko
maintainerPATCH 1/1 libbpf: constify few bpf_program getters
bpf_program__get_type() and bpf_program__get_expected_attach_type() shouldn't modify given bpf_program, so mark input parameter as const struct bpf_program. This eliminates unnecessary compilation warnings or explicit casts in user programs.
--- tools/lib/bpf/libbpf.c | 4 ++-- tools/lib/bpf/libbpf.h | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-)
tools/lib/bpf/libbpf.c +2 -2
@@ -8457,7 +8457,7 @@ int bpf_program__nth_fd(const struct bpf_program *prog, int n)return fd; } -enum bpf_prog_type bpf_program__get_type (struct bpf_program *prog) +enum bpf_prog_type bpf_program__get_type (const struct bpf_program *prog) {return prog->type; }
@@ -8502,7 +8502,7 @@ BPF_PROG_TYPE_FNS(extension, BPF_PROG_TYPE_EXT);BPF_PROG_TYPE_FNS (sk_lookup,BPF_PROG_TYPE_SK_LOOKUP );enum bpf_attach_type -bpf_program__get_expected_attach_type (struct bpf_program *prog) +bpf_program__get_expected_attach_type (const struct bpf_program *prog) {return prog->expected_attach_type; }
tools/lib/bpf/libbpf.h +2 -2
@@ -361,12 +361,12 @@ LIBBPF_API int bpf_program__set_struct_ops(struct bpf_program *prog); LIBBPF_API int bpf_program__set_extension(struct bpf_program *prog); LIBBPF_API int bpf_program__set_sk_lookup(struct bpf_program *prog); -LIBBPF_API enum bpf_prog_type bpf_program__get_type(struct bpf_program *prog); +LIBBPF_API enum bpf_prog_type bpf_program__get_type(const struct bpf_program *prog); LIBBPF_API void bpf_program__set_type(struct bpf_program *prog,enum bpf_prog_type type); LIBBPF_API enum bpf_attach_type -bpf_program__get_expected_attach_type (struct bpf_program *prog); +bpf_program__get_expected_attach_type (const struct bpf_program *prog); LIBBPF_API voidbpf_program__set_expected_attach_type (struct bpf_program *prog,enum bpf_attach_type type);
Signature · 1 line
2.30.2
This patch was applied to bpf/bpf-next.git (refs/heads/master):
Hello:
This patch was applied to bpf/bpf-next.git (refs/heads/master):
Quoted 8 lines · On Wed, 24 Mar 2021 10:29:41 -0700 you wrote:
bpf_program__get_type()andbpf_program__get_expected_attach_type()shouldn't modify givenbpf_program, so mark input parameter as const structbpf_program. This eliminates unnecessary compilation warnings or explicit casts in user programs.Signed-off-by Andrii Nakryiko <[email protected]>[...]
Here is the summary with links:
- [bpf-next] libbpf: constify few bpf_program getters
https://git.kernel.org/bpf/bpf-next/c/a46410d5e497
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html