diff mbox series

[bpf-next,1/2] tools/bpf: add const qualifier to btf__get_map_kv_tids() map_name parameter

Message ID 20190205194822.1804874-1-yhs@fb.com
State Accepted
Delegated to: BPF Maintainers
Headers show
Series tools/bpf: two changes in libbpf | expand

Commit Message

Yonghong Song Feb. 5, 2019, 7:48 p.m. UTC
Commit 96408c43447a ("tools/bpf: implement libbpf btf__get_map_kv_tids() API function")
added the API function btf__get_map_kv_tids():
  btf__get_map_kv_tids(const struct btf *btf, char *map_name, ...)

The parameter map_name has type "char *". This is okay inside libbpf library since
the map_name is from bpf_map->name which also has type "char *".

This will be problematic if the caller for map_name already has attribute "const",
e.g., from C++ string.c_str(). It will result in either a warning or an error.

  /home/yhs/work/bcc/src/cc/btf.cc:166:51:
    error: invalid conversion from ‘const char*’ to ‘char*’ [-fpermissive]
      return btf__get_map_kv_tids(btf_, map_name.c_str()

This patch added "const" attributes to map_name parameter.

Fixes: 96408c43447a ("tools/bpf: implement libbpf btf__get_map_kv_tids() API function")
Signed-off-by: Yonghong Song <yhs@fb.com>
---
 tools/lib/bpf/btf.c | 2 +-
 tools/lib/bpf/btf.h | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

Comments

Alexei Starovoitov Feb. 6, 2019, 2:27 a.m. UTC | #1
On Tue, Feb 05, 2019 at 11:48:22AM -0800, Yonghong Song wrote:
> Commit 96408c43447a ("tools/bpf: implement libbpf btf__get_map_kv_tids() API function")
> added the API function btf__get_map_kv_tids():
>   btf__get_map_kv_tids(const struct btf *btf, char *map_name, ...)
> 
> The parameter map_name has type "char *". This is okay inside libbpf library since
> the map_name is from bpf_map->name which also has type "char *".
> 
> This will be problematic if the caller for map_name already has attribute "const",
> e.g., from C++ string.c_str(). It will result in either a warning or an error.
> 
>   /home/yhs/work/bcc/src/cc/btf.cc:166:51:
>     error: invalid conversion from ‘const char*’ to ‘char*’ [-fpermissive]
>       return btf__get_map_kv_tids(btf_, map_name.c_str()
> 
> This patch added "const" attributes to map_name parameter.
> 
> Fixes: 96408c43447a ("tools/bpf: implement libbpf btf__get_map_kv_tids() API function")
> Signed-off-by: Yonghong Song <yhs@fb.com>

Acked-by: Alexei Starovoitov <ast@kernel.org>
Alexei Starovoitov Feb. 6, 2019, 2:41 a.m. UTC | #2
On Tue, Feb 5, 2019 at 6:27 PM Alexei Starovoitov
<alexei.starovoitov@gmail.com> wrote:
>
> On Tue, Feb 05, 2019 at 11:48:22AM -0800, Yonghong Song wrote:
> > Commit 96408c43447a ("tools/bpf: implement libbpf btf__get_map_kv_tids() API function")
> > added the API function btf__get_map_kv_tids():
> >   btf__get_map_kv_tids(const struct btf *btf, char *map_name, ...)
> >
> > The parameter map_name has type "char *". This is okay inside libbpf library since
> > the map_name is from bpf_map->name which also has type "char *".
> >
> > This will be problematic if the caller for map_name already has attribute "const",
> > e.g., from C++ string.c_str(). It will result in either a warning or an error.
> >
> >   /home/yhs/work/bcc/src/cc/btf.cc:166:51:
> >     error: invalid conversion from ‘const char*’ to ‘char*’ [-fpermissive]
> >       return btf__get_map_kv_tids(btf_, map_name.c_str()
> >
> > This patch added "const" attributes to map_name parameter.
> >
> > Fixes: 96408c43447a ("tools/bpf: implement libbpf btf__get_map_kv_tids() API function")
> > Signed-off-by: Yonghong Song <yhs@fb.com>
>
> Acked-by: Alexei Starovoitov <ast@kernel.org>

Actually just applied this patch alone,
since it's independent from 2nd.
diff mbox series

Patch

diff --git a/tools/lib/bpf/btf.c b/tools/lib/bpf/btf.c
index 4949f8840bda..3b3a2959d03a 100644
--- a/tools/lib/bpf/btf.c
+++ b/tools/lib/bpf/btf.c
@@ -511,7 +511,7 @@  int btf__get_from_id(__u32 id, struct btf **btf)
 	return err;
 }
 
-int btf__get_map_kv_tids(const struct btf *btf, char *map_name,
+int btf__get_map_kv_tids(const struct btf *btf, const char *map_name,
 			 __u32 expected_key_size, __u32 expected_value_size,
 			 __u32 *key_type_id, __u32 *value_type_id)
 {
diff --git a/tools/lib/bpf/btf.h b/tools/lib/bpf/btf.h
index 25a9d2db035d..b393da90cc85 100644
--- a/tools/lib/bpf/btf.h
+++ b/tools/lib/bpf/btf.h
@@ -69,7 +69,7 @@  LIBBPF_API void btf__get_strings(const struct btf *btf, const char **strings,
 				 __u32 *str_len);
 LIBBPF_API const char *btf__name_by_offset(const struct btf *btf, __u32 offset);
 LIBBPF_API int btf__get_from_id(__u32 id, struct btf **btf);
-LIBBPF_API int btf__get_map_kv_tids(const struct btf *btf, char *map_name,
+LIBBPF_API int btf__get_map_kv_tids(const struct btf *btf, const char *map_name,
 				    __u32 expected_key_size,
 				    __u32 expected_value_size,
 				    __u32 *key_type_id, __u32 *value_type_id);