From 91123e5d45ed9fd227d6e9c590ec82484dbb7bc7 Mon Sep 17 00:00:00 2001 From: Niklas Schnelle Date: Thu, 23 Jul 2026 16:55:54 +0200 Subject: [PATCH] lib/zt_common.h: zpcimon: Add __force and use it to annotate le32toh() conversions MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When using sparse on zpcimon several warnings like the one below are generated: warning: incorrect type in argument 1 (different base types) expected unsigned int [usertype] __bsx got restricted __le32 [usertype] warning_temp_time This is because several members in struct nvme_smart_log are marked as __le32. These members are correctly converted to host endianness before use via le32toh() respectively le16toh(). Since these functions take their parameters as plain uint32_t or uint16_t however the implicit conversion triggers the above warning. Fix this by adding the __force attribute and using it to mark type conversions in the leXXtoh() calls. Reviewed-by: Jan Höppner Signed-off-by: Niklas Schnelle Signed-off-by: Jan Höppner --- include/lib/zt_common.h | 5 +++++ zpcimon/nvmemon.c | 24 +++++++++++++++--------- 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/include/lib/zt_common.h b/include/lib/zt_common.h index c5363fe2..78f2a9b8 100644 --- a/include/lib/zt_common.h +++ b/include/lib/zt_common.h @@ -72,6 +72,11 @@ #define __section(x) __attribute__((__section__(#x))) #define __noinline __attribute__((__noinline__)) #define __big_endian +#ifdef __CHECKER__ +# define __force __attribute__((force)) +#else +# define __force +#endif /* The Linux kernel (in stddef.h) and glibc (sys/cdefs.h) define * __always_inline. Therefore undefine it first to allow the headers * to be included first. diff --git a/zpcimon/nvmemon.c b/zpcimon/nvmemon.c index bd5ef1a7..1e4c1aa8 100644 --- a/zpcimon/nvmemon.c +++ b/zpcimon/nvmemon.c @@ -20,6 +20,7 @@ #include "lib/pci_list.h" #include "lib/pci_sclp.h" #include "lib/util_fmt.h" +#include "lib/zt_common.h" #include "nvmemon.h" #include "zpcimon.h" @@ -108,19 +109,24 @@ static void nvme_json_print_smart_log(struct zpcimon_ctx *ctx, struct nvme_smart util_fmt_pair(FMT_DEFAULT, "media_errors", "%s", u128_num_buf); nvme_u128_to_json_val(nvme_le128_to_cpu(log->num_err_log_entries), u128_num_buf); util_fmt_pair(FMT_DEFAULT, "num_err_log_entries", "%s", u128_num_buf); - util_fmt_pair(FMT_DEFAULT, "warning_temp_time", "%d", le32toh(log->warning_temp_time)); - util_fmt_pair(FMT_DEFAULT, "critical_comp_time", "%d", le32toh(log->critical_comp_time)); - util_fmt_pair(FMT_DEFAULT, "temperature_sensor_1", "%d", le16toh(log->temp_sensor[0])); - util_fmt_pair(FMT_DEFAULT, "temperature_sensor_2", "%d", le16toh(log->temp_sensor[1])); - util_fmt_pair(FMT_DEFAULT, "temperature_sensor_3", "%d", le16toh(log->temp_sensor[2])); + util_fmt_pair(FMT_DEFAULT, "warning_temp_time", "%d", + le32toh((__force uint32_t)log->warning_temp_time)); + util_fmt_pair(FMT_DEFAULT, "critical_comp_time", "%d", + le32toh((__force uint32_t)log->critical_comp_time)); + util_fmt_pair(FMT_DEFAULT, "temperature_sensor_1", "%d", + le16toh((__force uint16_t)log->temp_sensor[0])); + util_fmt_pair(FMT_DEFAULT, "temperature_sensor_2", "%d", + le16toh((__force uint16_t)log->temp_sensor[1])); + util_fmt_pair(FMT_DEFAULT, "temperature_sensor_3", "%d", + le16toh((__force uint16_t)log->temp_sensor[2])); util_fmt_pair(FMT_DEFAULT, "thm_temp1_trans_count", "%d", - le32toh(log->thm_temp1_trans_count)); + le32toh((__force uint32_t)log->thm_temp1_trans_count)); util_fmt_pair(FMT_DEFAULT, "thm_temp2_trans_count", "%d", - le32toh(log->thm_temp2_trans_count)); + le32toh((__force uint32_t)log->thm_temp2_trans_count)); util_fmt_pair(FMT_DEFAULT, "thm_temp1_total_time", "%d", - le32toh(log->thm_temp1_total_time)); + le32toh((__force uint32_t)log->thm_temp1_total_time)); util_fmt_pair(FMT_DEFAULT, "thm_temp2_total_time", "%d", - le32toh(log->thm_temp2_total_time)); + le32toh((__force uint32_t)log->thm_temp2_total_time)); util_fmt_obj_end(); /* smart-log */ if (ctx->opts.smart_blob)