From 8e002e770b1299fa1ea61e40236b3a3b7c8d621b Mon Sep 17 00:00:00 2001 From: Jim Harris Date: Wed, 18 Jan 2023 20:14:00 +0000 Subject: [PATCH] ftl: fix FTL_LOG_COMMON to avoid annoying gcc-12 warnings gcc-12 is really tricky. It detected that in ftl_nv_cache_load_state() that when we do an FTL_NOTICELOG, the dev and nv_cache values are associated with each other by the SPDK_CONTAINEROF() operation. So then in FTL_LOG_COMMON, it checks if dev is NULL. If it is, it doesn't print the dev->conf.name, but still prints the varargs which include nv_cache members. But if dev is NULL then these nv_cache members wouldn't be valid either, and that's what gcc-12 is complaining about, in a very unclear way. So now we just have FTL_LOG_COMMON contain a single line, with a tertiary operator to print either dev->conf.name or "N/A" depending on whether dev is NULL or not. I suspect this fixes it because we've replaced the if statement with a tertiary operator that is independent from the VA_ARGS. Fixes issue #2829 (partially). Signed-off-by: Jim Harris Change-Id: Ia56e2c7fb7966e7a5ceff35b36b0346b556ce7e7 Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/16342 Reviewed-by: Reviewed-by: Konrad Sztyber Reviewed-by: Tomasz Zawadzki Tested-by: SPDK CI Jenkins --- lib/ftl/utils/ftl_log.h | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/lib/ftl/utils/ftl_log.h b/lib/ftl/utils/ftl_log.h index 403eb0f2e..e664d099b 100644 --- a/lib/ftl/utils/ftl_log.h +++ b/lib/ftl/utils/ftl_log.h @@ -10,12 +10,8 @@ #include "spdk/log.h" #define FTL_LOG_COMMON(type, dev, format, ...) \ - if ((dev) == NULL) \ - { \ - spdk_log(SPDK_LOG_##type, __FILE__, __LINE__, __func__, "[FTL] "format, ## __VA_ARGS__); \ - } else { \ - spdk_log(SPDK_LOG_##type, __FILE__, __LINE__, __func__, "[FTL][%s] "format, (dev)->conf.name, ## __VA_ARGS__); \ - } \ + spdk_log(SPDK_LOG_##type, __FILE__, __LINE__, __func__, "[FTL][%s] "format, \ + (dev) != NULL ? (dev)->conf.name : "N/A", ## __VA_ARGS__) #define FTL_ERRLOG(dev, format, ...) \ FTL_LOG_COMMON(ERROR, dev, format, ## __VA_ARGS__)