On Fri, 2024-07-12 at 18:14 +0800, Geliang Tang wrote: > From: Geliang Tang <tanggeliang@xxxxxxxxxx> > > The errno 95 (ENOTSUP or EOPNOTSUPP) can be recognized by > strerror_r(), > but 524 (ENOTSUPP) can't: > > prog 'basic_alloc3': BPF program load failed: Operation not > supported > prog 'basic_alloc3': failed to load: -95 > failed to load object 'verifier_arena' > FAIL:unexpected_load_failure unexpected error: -95 (errno 95) > > prog 'inner_map': BPF program load failed: unknown error (-524) > prog 'inner_map': failed to load: -524 > failed to load object 'bloom_filter_map' > failed to load BPF skeleton 'bloom_filter_map': -524 > FAIL:bloom_filter_map__open_and_load unexpected error: -524 > > This patch fixes this by handling ENOTSUPP in libbpf_strerror_r(). > With > this change, the new error string looks like: > > prog 'inner_map': BPF program load failed: Operation not supported > (-524) > > Signed-off-by: Geliang Tang <tanggeliang@xxxxxxxxxx> > --- > tools/lib/bpf/str_error.c | 11 +++++++---- > tools/lib/bpf/str_error.h | 4 ++++ > 2 files changed, 11 insertions(+), 4 deletions(-) > > diff --git a/tools/lib/bpf/str_error.c b/tools/lib/bpf/str_error.c > index 5e6a1e27ddf9..10597d5124cd 100644 > --- a/tools/lib/bpf/str_error.c > +++ b/tools/lib/bpf/str_error.c > @@ -23,10 +23,13 @@ char *libbpf_strerror_r(int err, char *dst, int > len) > if (ret == -1) > ret = errno; > if (ret) { > - if (ret == EINVAL) > - /* strerror_r() doesn't recognize this > specific error */ > - snprintf(dst, len, "unknown error (%d)", err > < 0 ? err : -err); > - else > + if (ret == EINVAL) { > + if (err == ENOTSUPP) Shouldn't use "err" directly here, should use "err < 0 ? -err : err" instead. I prefer to add an unsigned variable "no" in v2: unsigned int no = err < 0 ? -err : err; And use "switch-case" for future expansion: switch (no) { case ENOTSUPP: > + snprintf(dst, len, "Operation not > supported (%d)", -err); No need to use "Operation not supported (-524)" here, just "Operation not supported" is better. snprintf(dst, len, "Operation not supported"); > + else > + /* strerror_r() doesn't recognize > this specific error */ > + snprintf(dst, len, "unknown error > (%d)", err < 0 ? err : -err); Then here: snprintf(dst, len, "unknown error (-%u)", no); Changes Requested. Will send a v2 soon. Thanks, -Geliang > + } else > snprintf(dst, len, "ERROR: > strerror_r(%d)=%d", err, ret); > } > return dst; > diff --git a/tools/lib/bpf/str_error.h b/tools/lib/bpf/str_error.h > index 626d7ffb03d6..c41f6ba133cf 100644 > --- a/tools/lib/bpf/str_error.h > +++ b/tools/lib/bpf/str_error.h > @@ -4,6 +4,10 @@ > > #define STRERR_BUFSIZE 128 > > +#ifndef ENOTSUPP > +#define ENOTSUPP 524 > +#endif > + > char *libbpf_strerror_r(int err, char *dst, int len); > > #endif /* __LIBBPF_STR_ERROR_H */