From 54e9fc6bdae15f573611a29a5399aa90809e74d2 Mon Sep 17 00:00:00 2001 From: Tokunori Ikegami Date: Sun, 8 Mar 2026 15:58:12 +0900 Subject: [PATCH 1/2] nvme-print-json: fix get feature 128-bit host id print Since implemented as always 64-bit host id print. Signed-off-by: Tokunori Ikegami --- nvme-print-json.c | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/nvme-print-json.c b/nvme-print-json.c index fad8244e44..d59f7e7449 100644 --- a/nvme-print-json.c +++ b/nvme-print-json.c @@ -4020,19 +4020,22 @@ static void json_feature_show_fields_sw_progress(struct json_object *r, unsigned obj_add_uint(r, "Pre-boot Software Load Count (PBSLC)", result & 0xff); } -static void json_feature_show_fields_host_id(struct json_object *r, unsigned char *buf) +static void json_feature_show_fields_host_id(struct json_object *r, + unsigned int result, unsigned char *hostid) { - uint64_t ull = 0; - int i; + bool exhid; - if (buf) { - for (i = sizeof(ull) / sizeof(*buf); i; i--) { - ull |= buf[i - 1]; - if (i - 1) - ull <<= BYTE_TO_BIT(sizeof(buf[i])); - } - obj_add_uint64(r, "Host Identifier (HOSTID)", ull); - } + if (!hostid) + return; + + nvme_feature_decode_host_id(result, &exhid); + + if (exhid) + obj_add_str(r, "Host Identifier (HOSTID)", + uint128_t_to_l10n_string(le128_to_cpu(hostid))); + else + obj_add_uint64(r, "Host Identifier (HOSTID)", + le64_to_cpu(*(__le64 *)hostid)); } static void json_feature_show_fields_resv_mask(struct json_object *r, unsigned int result) @@ -4296,7 +4299,7 @@ static void json_feature_show_fields(enum nvme_features_id fid, unsigned int res json_feature_show_fields_sw_progress(r, result); break; case NVME_FEAT_FID_HOST_ID: - json_feature_show_fields_host_id(r, buf); + json_feature_show_fields_host_id(r, result, buf); break; case NVME_FEAT_FID_RESV_MASK: json_feature_show_fields_resv_mask(r, result); From 145aeeec0889e4efbb3ed0f5da5746eb4c4071f8 Mon Sep 17 00:00:00 2001 From: Tokunori Ikegami Date: Sun, 8 Mar 2026 16:00:43 +0900 Subject: [PATCH 2/2] nvme-print-stdout: fix to use le64_to_cpu for host id feature print Since hardcoded to change only big endian byte order for 64-bit hostid. Signed-off-by: Tokunori Ikegami --- nvme-print-stdout.c | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/nvme-print-stdout.c b/nvme-print-stdout.c index e5621386c5..aa7964aab3 100644 --- a/nvme-print-stdout.c +++ b/nvme-print-stdout.c @@ -5135,7 +5135,6 @@ static void stdout_host_metadata(enum nvme_features_id fid, static void stdout_feat_host_id(unsigned int result, unsigned char *hostid) { - uint64_t ull; bool exhid; if (!hostid) @@ -5143,17 +5142,12 @@ static void stdout_feat_host_id(unsigned int result, unsigned char *hostid) nvme_feature_decode_host_id(result, &exhid); - if (exhid) { + if (exhid) printf("\tHost Identifier (HOSTID): %s\n", uint128_t_to_l10n_string(le128_to_cpu(hostid))); - return; - } - - ull = hostid[7]; ull <<= 8; ull |= hostid[6]; ull <<= 8; - ull |= hostid[5]; ull <<= 8; ull |= hostid[4]; ull <<= 8; - ull |= hostid[3]; ull <<= 8; ull |= hostid[2]; ull <<= 8; - ull |= hostid[1]; ull <<= 8; ull |= hostid[0]; - printf("\tHost Identifier (HOSTID): %" PRIu64 "\n", ull); + else + printf("\tHost Identifier (HOSTID): %" PRIu64 "\n", + le64_to_cpu(*(__le64 *)hostid)); } static void stdout_feature_show(enum nvme_features_id fid, int sel, unsigned int result)