From d83183918a44f7175aa709962db83670fadf871b Mon Sep 17 00:00:00 2001 From: Caleb Sander Date: Sun, 5 Nov 2023 09:02:02 -0700 Subject: [PATCH] libnvme-wrap: exit on VOID_FN lookup failure libnvme-wrap provides fallbacks for missing libnvme functions. For functions that return a value, the FN() macro can be used to define a default return value if the function isn't found. This isn't possible for functions returning void, so VOID_FN() currently is a no-op if the function can't be found. For nvme_init_copy_range_f1(), the only current VOID_FN() user, this will result in silently sending a Copy command with a zeroed range, which is not what the user requested. Instead, exit the process immediately if the function can't be found. Signed-off-by: Caleb Sander --- libnvme-wrap.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/libnvme-wrap.c b/libnvme-wrap.c index a62d60c0..b5b48383 100644 --- a/libnvme-wrap.c +++ b/libnvme-wrap.c @@ -7,19 +7,24 @@ #include #include +#include #include +#include "nvme-print.h" #define PROTO(args...) args #define ARGS(args...) args -#define VOID_FN(name, proto, args) \ -void __attribute__((weak)) name(proto) \ -{ \ - void (*fn)(proto); \ - fn = dlsym(RTLD_NEXT, #name); \ - if (fn) \ - fn(args); \ +#define VOID_FN(name, proto, args) \ +void __attribute__((weak)) name(proto) \ +{ \ + void (*fn)(proto); \ + fn = dlsym(RTLD_NEXT, #name); \ + if (!fn) { \ + nvme_show_error("libnvme function " #name " not found");\ + exit(EXIT_FAILURE); \ + } \ + fn(args); \ } #define FN(name, rtype, proto, args, defret) \ -- 2.50.1