NVDIMM Device and Persistent Memory development
 help / color / mirror / Atom feed
From: Justin Ernst <justin.ernst@hpe.com>
To: nvdimm@lists.linux.dev
Cc: Justin Ernst <justin.ernst@hpe.com>
Subject: [ndctl PATCH] util/json: Use json_object_get_uint64() with uint64 support
Date: Thu, 29 Feb 2024 17:11:51 -0600	[thread overview]
Message-ID: <20240229231151.358694-1-justin.ernst@hpe.com> (raw)

If HAVE_JSON_U64=1, utils/json.c:display_hex() can call json_object_get_int64()
on a struct json_object created with json_object_new_uint64(). In the context of
'ndctl list --regions --human', this results in a static value of 0x7fffffffffffffff
being displayed for iset_id, as seen in #217.

Correct hex values are observed with the use of json_object_get_uint64(). To support
builds against older json-c, use a new static inline function util_json_get_u64() to
fallback to json_object_get_int64() if HAVE_JSON_U64=0.

Link: #217
Fixes: 691cd249 ("json: Add support for json_object_new_uint64()")
Signed-off-by: Justin Ernst <justin.ernst@hpe.com>
---
 util/json.c | 2 +-
 util/json.h | 8 ++++++++
 2 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/util/json.c b/util/json.c
index 1d5c6bc..ba9daa3 100644
--- a/util/json.c
+++ b/util/json.c
@@ -75,7 +75,7 @@ static int display_size(struct json_object *jobj, struct printbuf *pbuf,
 static int display_hex(struct json_object *jobj, struct printbuf *pbuf,
 		int level, int flags)
 {
-	unsigned long long val = json_object_get_int64(jobj);
+	unsigned long long val = util_json_get_u64(jobj);
 	static char buf[32];
 
 	snprintf(buf, sizeof(buf), "\"%#llx\"", val);
diff --git a/util/json.h b/util/json.h
index ea370df..a8d0283 100644
--- a/util/json.h
+++ b/util/json.h
@@ -34,10 +34,18 @@ static inline struct json_object *util_json_new_u64(unsigned long long val)
 {
 	return json_object_new_uint64(val);
 }
+static inline unsigned long long util_json_get_u64(struct json_object *jobj)
+{
+	return json_object_get_uint64(jobj);
+}
 #else /* fallback to signed */
 static inline struct json_object *util_json_new_u64(unsigned long long val)
 {
 	return json_object_new_int64(val);
 }
+static inline unsigned long long util_json_get_u64(struct json_object *jobj)
+{
+	return json_object_get_int64(jobj);
+}
 #endif /* HAVE_JSON_U64 */
 #endif /* __UTIL_JSON_H__ */
-- 
2.26.2


                 reply	other threads:[~2024-02-29 23:22 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240229231151.358694-1-justin.ernst@hpe.com \
    --to=justin.ernst@hpe.com \
    --cc=nvdimm@lists.linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).