lib/zt_common.h: zpcimon: Add __force and use it to annotate le32toh() conversions

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 <hoeppner@linux.ibm.com>
Signed-off-by: Niklas Schnelle <schnelle@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
This commit is contained in:
Niklas Schnelle
2026-07-23 16:55:54 +02:00
committed by Jan Höppner
parent 0f0e8cf33b
commit 91123e5d45
2 changed files with 20 additions and 9 deletions

View File

@@ -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.

View File

@@ -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)