402-bpf-fix-warning-from-basename.patch 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. From 69e3b2fadcd32683db2942f31fe41f0fbb2185f8 Mon Sep 17 00:00:00 2001
  2. From: Stephen Hemminger <[email protected]>
  3. Date: Sat, 27 Jan 2024 13:58:14 -0800
  4. Subject: [PATCH] bpf: fix warning from basename()
  5. MIME-Version: 1.0
  6. Content-Type: text/plain; charset=UTF-8
  7. Content-Transfer-Encoding: 8bit
  8. The function basename() expects a mutable character string,
  9. which now causes a warning:
  10. bpf_legacy.c: In function ‘bpf_load_common’:
  11. bpf_legacy.c:975:38: warning: passing argument 1 of ‘__xpg_basename’ discards ‘const’ qualifier from pointer target type [-Wdiscarded-qualifiers]
  12. 975 | basename(cfg->object), cfg->mode == EBPF_PINNED ?
  13. | ~~~^~~~~~~~
  14. In file included from bpf_legacy.c:21:
  15. /usr/include/libgen.h:34:36: note: expected ‘char *’ but argument is of type ‘const char *’
  16. 34 | extern char *__xpg_basename (char *__path) __THROW;
  17. Fixes: f20ff2f19552 ("bpf: keep parsed program mode in struct bpf_cfg_in")
  18. Signed-off-by: Stephen Hemminger <[email protected]>
  19. ---
  20. lib/bpf_legacy.c | 4 ++--
  21. 1 file changed, 2 insertions(+), 2 deletions(-)
  22. --- a/lib/bpf_legacy.c
  23. +++ b/lib/bpf_legacy.c
  24. @@ -971,8 +971,8 @@ int bpf_load_common(struct bpf_cfg_in *c
  25. ops->cbpf_cb(nl, cfg->opcodes, cfg->n_opcodes);
  26. if (cfg->mode == EBPF_OBJECT || cfg->mode == EBPF_PINNED) {
  27. snprintf(annotation, sizeof(annotation), "%s:[%s]",
  28. - basename(cfg->object), cfg->mode == EBPF_PINNED ?
  29. - "*fsobj" : cfg->section);
  30. + basename(strdupa(cfg->object)),
  31. + cfg->mode == EBPF_PINNED ? "*fsobj" : cfg->section);
  32. ops->ebpf_cb(nl, cfg->prog_fd, annotation);
  33. }