All of lore.kernel.org
 help / color / mirror / Atom feed
From: Geert Uytterhoeven <geert+renesas@glider.be>
To: Simon Horman <horms@verge.net.au>
Cc: Varad Gautam <vrd@amazon.de>,
	John Ogness <john.ogness@linutronix.de>,
	kexec@lists.infradead.org,
	Geert Uytterhoeven <geert+renesas@glider.be>
Subject: [PATCH 1/3] kexec: Use %llu/%llx and casts to format uint64_t
Date: Wed, 17 Mar 2021 13:14:48 +0100	[thread overview]
Message-ID: <20210317121450.2556349-2-geert+renesas@glider.be> (raw)
In-Reply-To: <20210317121450.2556349-1-geert+renesas@glider.be>

When compiling for 32-bit:

    kexec/kexec.c: In function ‘cmdline_add_liveupdate’:
    kexec/kexec.c:1192:30: warning: format ‘%lu’ expects argument of type ‘long unsigned int’, but argument 3 has type ‘uint64_t’ {aka ‘long long unsigned int’} [-Wformat=]
     1192 |  sprintf(buf, " liveupdate=%luM@0x%lx", lu_sizeM, lu_start);
	  |                            ~~^          ~~~~~~~~
	  |                              |          |
	  |                              |          uint64_t {aka long long unsigned int}
	  |                              long unsigned int
	  |                            %llu
    kexec/kexec.c:1192:37: warning: format ‘%lx’ expects argument of type ‘long unsigned int’, but argument 4 has type ‘uint64_t’ {aka ‘long long unsigned int’} [-Wformat=]
     1192 |  sprintf(buf, " liveupdate=%luM@0x%lx", lu_sizeM, lu_start);
	  |                                   ~~^             ~~~~~~~~
	  |                                     |             |
	  |                                     |             uint64_t {aka long long unsigned int}
	  |                                     long unsigned int
	  |                                   %llx

Indeed, "uint64_t" is "unsigned long long" on 32-bit formats, and
"unsigned long" on 64-bit formats.

Fix this by casting to "unsigned long long", and formatting using "%llu"
or "%llx".

Fixes: b13984c6f9ec7fdd ("kexec: Introduce --load-live-update for xen")
Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
---
 kexec/kexec.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/kexec/kexec.c b/kexec/kexec.c
index fd7c8d2b7a7977f9..c5a8dec1f09f35ca 100644
--- a/kexec/kexec.c
+++ b/kexec/kexec.c
@@ -1189,7 +1189,8 @@ void cmdline_add_liveupdate(char **base)
 
 	xen_get_kexec_range(KEXEC_RANGE_MA_LIVEUPDATE, &lu_start, &lu_end);
 	lu_sizeM = (lu_end - lu_start) / (1024 * 1024) + 1;
-	sprintf(buf, " liveupdate=%luM@0x%lx", lu_sizeM, lu_start);
+	sprintf(buf, " liveupdate=%lluM@0x%llx", (unsigned long long)lu_sizeM,
+		(unsigned long long)lu_start);
 	len = strlen(*base) + strlen(buf) + 1;
 	str = xmalloc(len);
 	sprintf(str, "%s%s", *base, buf);
-- 
2.25.1


_______________________________________________
kexec mailing list
kexec@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kexec

  reply	other threads:[~2021-03-17 12:15 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-17 12:14 [PATCH 0/3] Miscellaneous 32-bit fixes Geert Uytterhoeven
2021-03-17 12:14 ` Geert Uytterhoeven [this message]
2021-03-17 12:14 ` [PATCH 2/3] printk: Use ULL suffix for 64-bit constants Geert Uytterhoeven
2021-03-17 13:14   ` John Ogness
2021-03-17 12:14 ` [PATCH 3/3] printk: Use %zu to format size_t Geert Uytterhoeven
2021-03-17 13:19   ` John Ogness
2021-04-02  9:58 ` [PATCH 0/3] Miscellaneous 32-bit fixes Simon Horman

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=20210317121450.2556349-2-geert+renesas@glider.be \
    --to=geert+renesas@glider.be \
    --cc=horms@verge.net.au \
    --cc=john.ogness@linutronix.de \
    --cc=kexec@lists.infradead.org \
    --cc=vrd@amazon.de \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.