]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
libbpf: move libbpf_errstr() into libbpf_utils.c
authorAndrii Nakryiko <andrii@kernel.org>
Wed, 1 Oct 2025 17:13:24 +0000 (10:13 -0700)
committerAlexei Starovoitov <ast@kernel.org>
Wed, 1 Oct 2025 22:27:25 +0000 (15:27 -0700)
Get rid of str_err.{c,h} by moving implementation of libbpf_errstr()
into libbpf_utils.c and declarations into libbpf_internal.h.

Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Link: https://lore.kernel.org/r/20251001171326.3883055-4-andrii@kernel.org
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Acked-by: Eduard Zingerman <eddyz87@gmail.com>
15 files changed:
tools/lib/bpf/Build
tools/lib/bpf/btf.c
tools/lib/bpf/btf_dump.c
tools/lib/bpf/elf.c
tools/lib/bpf/features.c
tools/lib/bpf/gen_loader.c
tools/lib/bpf/libbpf.c
tools/lib/bpf/libbpf_internal.h
tools/lib/bpf/libbpf_utils.c
tools/lib/bpf/linker.c
tools/lib/bpf/relo_core.c
tools/lib/bpf/ringbuf.c
tools/lib/bpf/str_error.c [deleted file]
tools/lib/bpf/str_error.h [deleted file]
tools/lib/bpf/usdt.c

index c30927135fd6f0e98a54cf8681e52d450519e28f..c80204bb72a2af572a4f566d13e9942aa9694725 100644 (file)
@@ -1,4 +1,4 @@
-libbpf-y := libbpf.o bpf.o nlattr.o btf.o libbpf_utils.o str_error.o \
+libbpf-y := libbpf.o bpf.o nlattr.o btf.o libbpf_utils.o \
            netlink.o bpf_prog_linfo.o libbpf_probes.o hashmap.o \
            btf_dump.o ringbuf.o strset.o linker.o gen_loader.o relo_core.o \
            usdt.o zip.o elf.o features.o btf_iter.o btf_relocate.o
index 37682908cb0f3bd4703eb2ee811aa3da3673c33b..18907f0fcf9f0180f364339f001e05183a292b1e 100644 (file)
@@ -23,7 +23,6 @@
 #include "libbpf_internal.h"
 #include "hashmap.h"
 #include "strset.h"
-#include "str_error.h"
 
 #define BTF_MAX_NR_TYPES 0x7fffffffU
 #define BTF_MAX_STR_OFFSET 0x7fffffffU
index f09f25eccf3cd73184ae90cb8cc518dcc27414af..6388392f49a0b5651ac92098eb02b7d080d542a2 100644 (file)
@@ -21,7 +21,6 @@
 #include "hashmap.h"
 #include "libbpf.h"
 #include "libbpf_internal.h"
-#include "str_error.h"
 
 static const char PREFIXES[] = "\t\t\t\t\t\t\t\t\t\t\t\t\t";
 static const size_t PREFIX_CNT = sizeof(PREFIXES) - 1;
index 823f83ad819c8e3eebc45778463b5c7ea65c4cc8..295dbda245807178fb23aeac312bef3c19724868 100644 (file)
@@ -9,7 +9,6 @@
 #include <linux/kernel.h>
 
 #include "libbpf_internal.h"
-#include "str_error.h"
 
 /* A SHT_GNU_versym section holds 16-bit words. This bit is set if
  * the symbol is hidden and can only be seen when referenced using an
index 760657f5224c2a624710bb650e04e20d74a6a78b..b842b83e24804e4b18005c7ef60cd3f1ec5365a4 100644 (file)
@@ -6,7 +6,6 @@
 #include "libbpf.h"
 #include "libbpf_common.h"
 #include "libbpf_internal.h"
-#include "str_error.h"
 
 static inline __u64 ptr_to_u64(const void *ptr)
 {
index 6945dd99a84693f2ef4f5c3ffd0e9e440feb63e9..cd5c2543f54d85c8816229924a206ccfefdbd83d 100644 (file)
@@ -4,6 +4,7 @@
 #include <stdlib.h>
 #include <string.h>
 #include <errno.h>
+#include <asm/byteorder.h>
 #include <linux/filter.h>
 #include <sys/param.h>
 #include "btf.h"
@@ -13,8 +14,6 @@
 #include "hashmap.h"
 #include "bpf_gen_internal.h"
 #include "skel_internal.h"
-#include <asm/byteorder.h>
-#include "str_error.h"
 
 #define MAX_USED_MAPS  64
 #define MAX_USED_PROGS 32
index c21bc61f5ff4ce928d743874a59575bfc7f41bfb..6d19e0db492c194b67e35a62607003c1b976a7fe 100644 (file)
@@ -51,7 +51,6 @@
 #include "libbpf.h"
 #include "bpf.h"
 #include "btf.h"
-#include "str_error.h"
 #include "libbpf_internal.h"
 #include "hashmap.h"
 #include "bpf_gen_internal.h"
index c93797dcaf5bcf8c1e1956815032458feecc88a7..a8f204139371defaf6d456ef90602d3f5179fce2 100644 (file)
@@ -172,6 +172,16 @@ do {                               \
 #define pr_info(fmt, ...)      __pr(LIBBPF_INFO, fmt, ##__VA_ARGS__)
 #define pr_debug(fmt, ...)     __pr(LIBBPF_DEBUG, fmt, ##__VA_ARGS__)
 
+/**
+ * @brief **libbpf_errstr()** returns string corresponding to numeric errno
+ * @param err negative numeric errno
+ * @return pointer to string representation of the errno, that is invalidated
+ * upon the next call.
+ */
+const char *libbpf_errstr(int err);
+
+#define errstr(err) libbpf_errstr(err)
+
 #ifndef __has_builtin
 #define __has_builtin(x) 0
 #endif
index 6b180172ec6bb89168cae6e7d9340851026c12a9..ee3013e9b77cfa91fe427431fcfb7184da429e86 100644 (file)
 #undef _GNU_SOURCE
 #include <stdio.h>
 #include <string.h>
+#include <errno.h>
 
 #include "libbpf.h"
 #include "libbpf_internal.h"
 
+#ifndef ENOTSUPP
+#define ENOTSUPP       524
+#endif
+
 /* make sure libbpf doesn't use kernel-only integer typedefs */
 #pragma GCC poison u8 u16 u32 u64 s8 s16 s32 s64
 
@@ -73,3 +78,70 @@ int libbpf_strerror(int err, char *buf, size_t size)
                return libbpf_err(-ERANGE);
        return libbpf_err(-ENOENT);
 }
+
+const char *libbpf_errstr(int err)
+{
+       static __thread char buf[12];
+
+       if (err > 0)
+               err = -err;
+
+       switch (err) {
+       case -E2BIG:            return "-E2BIG";
+       case -EACCES:           return "-EACCES";
+       case -EADDRINUSE:       return "-EADDRINUSE";
+       case -EADDRNOTAVAIL:    return "-EADDRNOTAVAIL";
+       case -EAGAIN:           return "-EAGAIN";
+       case -EALREADY:         return "-EALREADY";
+       case -EBADF:            return "-EBADF";
+       case -EBADFD:           return "-EBADFD";
+       case -EBUSY:            return "-EBUSY";
+       case -ECANCELED:        return "-ECANCELED";
+       case -ECHILD:           return "-ECHILD";
+       case -EDEADLK:          return "-EDEADLK";
+       case -EDOM:             return "-EDOM";
+       case -EEXIST:           return "-EEXIST";
+       case -EFAULT:           return "-EFAULT";
+       case -EFBIG:            return "-EFBIG";
+       case -EILSEQ:           return "-EILSEQ";
+       case -EINPROGRESS:      return "-EINPROGRESS";
+       case -EINTR:            return "-EINTR";
+       case -EINVAL:           return "-EINVAL";
+       case -EIO:              return "-EIO";
+       case -EISDIR:           return "-EISDIR";
+       case -ELOOP:            return "-ELOOP";
+       case -EMFILE:           return "-EMFILE";
+       case -EMLINK:           return "-EMLINK";
+       case -EMSGSIZE:         return "-EMSGSIZE";
+       case -ENAMETOOLONG:     return "-ENAMETOOLONG";
+       case -ENFILE:           return "-ENFILE";
+       case -ENODATA:          return "-ENODATA";
+       case -ENODEV:           return "-ENODEV";
+       case -ENOENT:           return "-ENOENT";
+       case -ENOEXEC:          return "-ENOEXEC";
+       case -ENOLINK:          return "-ENOLINK";
+       case -ENOMEM:           return "-ENOMEM";
+       case -ENOSPC:           return "-ENOSPC";
+       case -ENOTBLK:          return "-ENOTBLK";
+       case -ENOTDIR:          return "-ENOTDIR";
+       case -ENOTSUPP:         return "-ENOTSUPP";
+       case -ENOTTY:           return "-ENOTTY";
+       case -ENXIO:            return "-ENXIO";
+       case -EOPNOTSUPP:       return "-EOPNOTSUPP";
+       case -EOVERFLOW:        return "-EOVERFLOW";
+       case -EPERM:            return "-EPERM";
+       case -EPIPE:            return "-EPIPE";
+       case -EPROTO:           return "-EPROTO";
+       case -EPROTONOSUPPORT:  return "-EPROTONOSUPPORT";
+       case -ERANGE:           return "-ERANGE";
+       case -EROFS:            return "-EROFS";
+       case -ESPIPE:           return "-ESPIPE";
+       case -ESRCH:            return "-ESRCH";
+       case -ETXTBSY:          return "-ETXTBSY";
+       case -EUCLEAN:          return "-EUCLEAN";
+       case -EXDEV:            return "-EXDEV";
+       default:
+               snprintf(buf, sizeof(buf), "%d", err);
+               return buf;
+       }
+}
index a469e5d4fee70ebfb162b53b509ebcf594d28ada..56ae77047bc3676e567213deae8e9ef2ca09ea12 100644 (file)
@@ -25,7 +25,6 @@
 #include "btf.h"
 #include "libbpf_internal.h"
 #include "strset.h"
-#include "str_error.h"
 
 #define BTF_EXTERN_SEC ".extern"
 
index 2b83c98a11372d5905fd5aab41eeadba86fe4d81..6eea5edba58a5897323567533e27012929e5d31e 100644 (file)
@@ -64,7 +64,6 @@ enum libbpf_print_level {
 #include "libbpf.h"
 #include "bpf.h"
 #include "btf.h"
-#include "str_error.h"
 #include "libbpf_internal.h"
 #endif
 
index 9702b70da444c5a8e94d223ebe434d81d44f6801..00ec4837a06de22fe161427ccb78909c376e1dd9 100644 (file)
@@ -21,7 +21,6 @@
 #include "libbpf.h"
 #include "libbpf_internal.h"
 #include "bpf.h"
-#include "str_error.h"
 
 struct ring {
        ring_buffer_sample_fn sample_cb;
diff --git a/tools/lib/bpf/str_error.c b/tools/lib/bpf/str_error.c
deleted file mode 100644 (file)
index 92dbd80..0000000
+++ /dev/null
@@ -1,80 +0,0 @@
-// SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause)
-#undef _GNU_SOURCE
-#include <string.h>
-#include <stdio.h>
-#include <errno.h>
-#include "str_error.h"
-
-#ifndef ENOTSUPP
-#define ENOTSUPP       524
-#endif
-
-/* make sure libbpf doesn't use kernel-only integer typedefs */
-#pragma GCC poison u8 u16 u32 u64 s8 s16 s32 s64
-
-const char *libbpf_errstr(int err)
-{
-       static __thread char buf[12];
-
-       if (err > 0)
-               err = -err;
-
-       switch (err) {
-       case -E2BIG:            return "-E2BIG";
-       case -EACCES:           return "-EACCES";
-       case -EADDRINUSE:       return "-EADDRINUSE";
-       case -EADDRNOTAVAIL:    return "-EADDRNOTAVAIL";
-       case -EAGAIN:           return "-EAGAIN";
-       case -EALREADY:         return "-EALREADY";
-       case -EBADF:            return "-EBADF";
-       case -EBADFD:           return "-EBADFD";
-       case -EBUSY:            return "-EBUSY";
-       case -ECANCELED:        return "-ECANCELED";
-       case -ECHILD:           return "-ECHILD";
-       case -EDEADLK:          return "-EDEADLK";
-       case -EDOM:             return "-EDOM";
-       case -EEXIST:           return "-EEXIST";
-       case -EFAULT:           return "-EFAULT";
-       case -EFBIG:            return "-EFBIG";
-       case -EILSEQ:           return "-EILSEQ";
-       case -EINPROGRESS:      return "-EINPROGRESS";
-       case -EINTR:            return "-EINTR";
-       case -EINVAL:           return "-EINVAL";
-       case -EIO:              return "-EIO";
-       case -EISDIR:           return "-EISDIR";
-       case -ELOOP:            return "-ELOOP";
-       case -EMFILE:           return "-EMFILE";
-       case -EMLINK:           return "-EMLINK";
-       case -EMSGSIZE:         return "-EMSGSIZE";
-       case -ENAMETOOLONG:     return "-ENAMETOOLONG";
-       case -ENFILE:           return "-ENFILE";
-       case -ENODATA:          return "-ENODATA";
-       case -ENODEV:           return "-ENODEV";
-       case -ENOENT:           return "-ENOENT";
-       case -ENOEXEC:          return "-ENOEXEC";
-       case -ENOLINK:          return "-ENOLINK";
-       case -ENOMEM:           return "-ENOMEM";
-       case -ENOSPC:           return "-ENOSPC";
-       case -ENOTBLK:          return "-ENOTBLK";
-       case -ENOTDIR:          return "-ENOTDIR";
-       case -ENOTSUPP:         return "-ENOTSUPP";
-       case -ENOTTY:           return "-ENOTTY";
-       case -ENXIO:            return "-ENXIO";
-       case -EOPNOTSUPP:       return "-EOPNOTSUPP";
-       case -EOVERFLOW:        return "-EOVERFLOW";
-       case -EPERM:            return "-EPERM";
-       case -EPIPE:            return "-EPIPE";
-       case -EPROTO:           return "-EPROTO";
-       case -EPROTONOSUPPORT:  return "-EPROTONOSUPPORT";
-       case -ERANGE:           return "-ERANGE";
-       case -EROFS:            return "-EROFS";
-       case -ESPIPE:           return "-ESPIPE";
-       case -ESRCH:            return "-ESRCH";
-       case -ETXTBSY:          return "-ETXTBSY";
-       case -EUCLEAN:          return "-EUCLEAN";
-       case -EXDEV:            return "-EXDEV";
-       default:
-               snprintf(buf, sizeof(buf), "%d", err);
-               return buf;
-       }
-}
diff --git a/tools/lib/bpf/str_error.h b/tools/lib/bpf/str_error.h
deleted file mode 100644 (file)
index d4c82ee..0000000
+++ /dev/null
@@ -1,15 +0,0 @@
-/* SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause) */
-#ifndef __LIBBPF_STR_ERROR_H
-#define __LIBBPF_STR_ERROR_H
-
-/**
- * @brief **libbpf_errstr()** returns string corresponding to numeric errno
- * @param err negative numeric errno
- * @return pointer to string representation of the errno, that is invalidated
- * upon the next call.
- */
-const char *libbpf_errstr(int err);
-
-#define errstr(err) libbpf_errstr(err)
-
-#endif /* __LIBBPF_STR_ERROR_H */
index fc2785eecc1776d9c3ccd9f9257084193a44b7d2..c174b40866738a5580d383fe732833dcf0d28c13 100644 (file)
@@ -20,7 +20,6 @@
 #include "libbpf_common.h"
 #include "libbpf_internal.h"
 #include "hashmap.h"
-#include "str_error.h"
 
 /* libbpf's USDT support consists of BPF-side state/code and user-space
  * state/code working together in concert. BPF-side parts are defined in