* [PATCH 1/3] kexec: Use %llu/%llx and casts to format uint64_t
2021-03-17 12:14 [PATCH 0/3] Miscellaneous 32-bit fixes Geert Uytterhoeven
@ 2021-03-17 12:14 ` Geert Uytterhoeven
2021-03-17 12:14 ` [PATCH 2/3] printk: Use ULL suffix for 64-bit constants Geert Uytterhoeven
` (2 subsequent siblings)
3 siblings, 0 replies; 7+ messages in thread
From: Geert Uytterhoeven @ 2021-03-17 12:14 UTC (permalink / raw)
To: Simon Horman; +Cc: Varad Gautam, John Ogness, kexec, Geert Uytterhoeven
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
^ permalink raw reply related [flat|nested] 7+ messages in thread* [PATCH 2/3] printk: Use ULL suffix for 64-bit constants
2021-03-17 12:14 [PATCH 0/3] Miscellaneous 32-bit fixes Geert Uytterhoeven
2021-03-17 12:14 ` [PATCH 1/3] kexec: Use %llu/%llx and casts to format uint64_t Geert Uytterhoeven
@ 2021-03-17 12:14 ` 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-04-02 9:58 ` [PATCH 0/3] Miscellaneous 32-bit fixes Simon Horman
3 siblings, 1 reply; 7+ messages in thread
From: Geert Uytterhoeven @ 2021-03-17 12:14 UTC (permalink / raw)
To: Simon Horman; +Cc: Varad Gautam, John Ogness, kexec, Geert Uytterhoeven
When compiling for 32-bit:
util_lib/elf_info.c: In function ‘get_desc_state’:
util_lib/elf_info.c:923:31: warning: left shift count >= width of type [-Wshift-count-overflow]
923 | #define DESC_FLAGS_MASK (3UL << DESC_FLAGS_SHIFT)
| ^~
util_lib/elf_info.c:925:25: note: in expansion of macro ‘DESC_FLAGS_MASK’
925 | #define DESC_ID_MASK (~DESC_FLAGS_MASK)
| ^~~~~~~~~~~~~~~
util_lib/elf_info.c:926:30: note: in expansion of macro ‘DESC_ID_MASK’
926 | #define DESC_ID(sv) ((sv) & DESC_ID_MASK)
| ^~~~~~~~~~~~
util_lib/elf_info.c:947:12: note: in expansion of macro ‘DESC_ID’
947 | if (id != DESC_ID(state_val))
| ^~~~~~~
util_lib/elf_info.c: In function ‘id_inc’:
util_lib/elf_info.c:923:31: warning: left shift count >= width of type [-Wshift-count-overflow]
923 | #define DESC_FLAGS_MASK (3UL << DESC_FLAGS_SHIFT)
| ^~
util_lib/elf_info.c:925:25: note: in expansion of macro ‘DESC_FLAGS_MASK’
925 | #define DESC_ID_MASK (~DESC_FLAGS_MASK)
| ^~~~~~~~~~~~~~~
util_lib/elf_info.c:981:15: note: in expansion of macro ‘DESC_ID_MASK’
981 | return (id & DESC_ID_MASK);
| ^~~~~~~~~~~~
Indeed, "unsigned long" constants are 32-bit on 32-bit platforms, and
64-bit on 64-bit platforms.
Fix this by using a "ULL" suffix instead.
Fixes: 4149df9005f2cdd2 ("printk: add support for lockless ringbuffer")
Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
---
util_lib/elf_info.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/util_lib/elf_info.c b/util_lib/elf_info.c
index 2f23a448da08ebdd..7c0a2c345379a7ca 100644
--- a/util_lib/elf_info.c
+++ b/util_lib/elf_info.c
@@ -920,8 +920,8 @@ enum desc_state {
#define DESC_SV_BITS (sizeof(uint64_t) * 8)
#define DESC_FLAGS_SHIFT (DESC_SV_BITS - 2)
-#define DESC_FLAGS_MASK (3UL << DESC_FLAGS_SHIFT)
-#define DESC_STATE(sv) (3UL & (sv >> DESC_FLAGS_SHIFT))
+#define DESC_FLAGS_MASK (3ULL << DESC_FLAGS_SHIFT)
+#define DESC_STATE(sv) (3ULL & (sv >> DESC_FLAGS_SHIFT))
#define DESC_ID_MASK (~DESC_FLAGS_MASK)
#define DESC_ID(sv) ((sv) & DESC_ID_MASK)
--
2.25.1
_______________________________________________
kexec mailing list
kexec@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kexec
^ permalink raw reply related [flat|nested] 7+ messages in thread* Re: [PATCH 2/3] printk: Use ULL suffix for 64-bit constants
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
0 siblings, 0 replies; 7+ messages in thread
From: John Ogness @ 2021-03-17 13:14 UTC (permalink / raw)
To: Geert Uytterhoeven; +Cc: Simon Horman, Varad Gautam, kexec
On 2021-03-17, Geert Uytterhoeven <geert+renesas@glider.be> wrote:
> When compiling for 32-bit:
>
> util_lib/elf_info.c: In function ‘get_desc_state’:
> util_lib/elf_info.c:923:31: warning: left shift count >= width of type [-Wshift-count-overflow]
> 923 | #define DESC_FLAGS_MASK (3UL << DESC_FLAGS_SHIFT)
> | ^~
> util_lib/elf_info.c:925:25: note: in expansion of macro ‘DESC_FLAGS_MASK’
> 925 | #define DESC_ID_MASK (~DESC_FLAGS_MASK)
> | ^~~~~~~~~~~~~~~
> util_lib/elf_info.c:926:30: note: in expansion of macro ‘DESC_ID_MASK’
> 926 | #define DESC_ID(sv) ((sv) & DESC_ID_MASK)
> | ^~~~~~~~~~~~
> util_lib/elf_info.c:947:12: note: in expansion of macro ‘DESC_ID’
> 947 | if (id != DESC_ID(state_val))
> | ^~~~~~~
> util_lib/elf_info.c: In function ‘id_inc’:
> util_lib/elf_info.c:923:31: warning: left shift count >= width of type [-Wshift-count-overflow]
> 923 | #define DESC_FLAGS_MASK (3UL << DESC_FLAGS_SHIFT)
> | ^~
> util_lib/elf_info.c:925:25: note: in expansion of macro ‘DESC_FLAGS_MASK’
> 925 | #define DESC_ID_MASK (~DESC_FLAGS_MASK)
> | ^~~~~~~~~~~~~~~
> util_lib/elf_info.c:981:15: note: in expansion of macro ‘DESC_ID_MASK’
> 981 | return (id & DESC_ID_MASK);
> | ^~~~~~~~~~~~
>
> Indeed, "unsigned long" constants are 32-bit on 32-bit platforms, and
> 64-bit on 64-bit platforms.
>
> Fix this by using a "ULL" suffix instead.
>
> Fixes: 4149df9005f2cdd2 ("printk: add support for lockless ringbuffer")
> Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
Reviewed-by: John Ogness <john.ogness@linutronix.de>
> ---
> util_lib/elf_info.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/util_lib/elf_info.c b/util_lib/elf_info.c
> index 2f23a448da08ebdd..7c0a2c345379a7ca 100644
> --- a/util_lib/elf_info.c
> +++ b/util_lib/elf_info.c
> @@ -920,8 +920,8 @@ enum desc_state {
>
> #define DESC_SV_BITS (sizeof(uint64_t) * 8)
> #define DESC_FLAGS_SHIFT (DESC_SV_BITS - 2)
> -#define DESC_FLAGS_MASK (3UL << DESC_FLAGS_SHIFT)
> -#define DESC_STATE(sv) (3UL & (sv >> DESC_FLAGS_SHIFT))
> +#define DESC_FLAGS_MASK (3ULL << DESC_FLAGS_SHIFT)
> +#define DESC_STATE(sv) (3ULL & (sv >> DESC_FLAGS_SHIFT))
> #define DESC_ID_MASK (~DESC_FLAGS_MASK)
> #define DESC_ID(sv) ((sv) & DESC_ID_MASK)
_______________________________________________
kexec mailing list
kexec@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kexec
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH 3/3] printk: Use %zu to format size_t
2021-03-17 12:14 [PATCH 0/3] Miscellaneous 32-bit fixes Geert Uytterhoeven
2021-03-17 12:14 ` [PATCH 1/3] kexec: Use %llu/%llx and casts to format uint64_t Geert Uytterhoeven
2021-03-17 12:14 ` [PATCH 2/3] printk: Use ULL suffix for 64-bit constants Geert Uytterhoeven
@ 2021-03-17 12:14 ` Geert Uytterhoeven
2021-03-17 13:19 ` John Ogness
2021-04-02 9:58 ` [PATCH 0/3] Miscellaneous 32-bit fixes Simon Horman
3 siblings, 1 reply; 7+ messages in thread
From: Geert Uytterhoeven @ 2021-03-17 12:14 UTC (permalink / raw)
To: Simon Horman; +Cc: Varad Gautam, John Ogness, kexec, Geert Uytterhoeven
When compiling for 32-bit:
util_lib/elf_info.c: In function ‘dump_dmesg_lockless’:
util_lib/elf_info.c:1095:39: warning: format ‘%lu’ expects argument of type ‘long unsigned int’, but argument 3 has type ‘size_t’ {aka ‘unsigned int’} [-Wformat=]
1095 | fprintf(stderr, "Failed to malloc %lu bytes for prb: %s\n",
| ~~^
| |
| long unsigned int
| %u
1096 | printk_ringbuffer_sz, strerror(errno));
| ~~~~~~~~~~~~~~~~~~~~
| |
| size_t {aka unsigned int}
util_lib/elf_info.c:1101:49: warning: format ‘%lu’ expects argument of type ‘long unsigned int’, but argument 3 has type ‘size_t’ {aka ‘unsigned int’} [-Wformat=]
1101 | fprintf(stderr, "Failed to read prb of size %lu bytes: %s\n",
| ~~^
| |
| long unsigned int
| %u
1102 | printk_ringbuffer_sz, strerror(errno));
| ~~~~~~~~~~~~~~~~~~~~
| |
| size_t {aka unsigned int}
Indeed, "size_t" is "unsigned int" on 32-bit platforms, and "unsigned
long" on 64-bit platforms.
Fix this by formatting using "%zu".
Fixes: 4149df9005f2cdd2 ("printk: add support for lockless ringbuffer")
Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
---
util_lib/elf_info.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/util_lib/elf_info.c b/util_lib/elf_info.c
index 7c0a2c345379a7ca..676926ca8c5f3766 100644
--- a/util_lib/elf_info.c
+++ b/util_lib/elf_info.c
@@ -1092,13 +1092,13 @@ static void dump_dmesg_lockless(int fd, void (*handler)(char*, unsigned int))
kaddr = read_file_pointer(fd, vaddr_to_offset(prb_vaddr));
m.prb = calloc(1, printk_ringbuffer_sz);
if (!m.prb) {
- fprintf(stderr, "Failed to malloc %lu bytes for prb: %s\n",
+ fprintf(stderr, "Failed to malloc %zu bytes for prb: %s\n",
printk_ringbuffer_sz, strerror(errno));
exit(64);
}
ret = pread(fd, m.prb, printk_ringbuffer_sz, vaddr_to_offset(kaddr));
if (ret != printk_ringbuffer_sz) {
- fprintf(stderr, "Failed to read prb of size %lu bytes: %s\n",
+ fprintf(stderr, "Failed to read prb of size %zu bytes: %s\n",
printk_ringbuffer_sz, strerror(errno));
exit(65);
}
--
2.25.1
_______________________________________________
kexec mailing list
kexec@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kexec
^ permalink raw reply related [flat|nested] 7+ messages in thread* Re: [PATCH 3/3] printk: Use %zu to format size_t
2021-03-17 12:14 ` [PATCH 3/3] printk: Use %zu to format size_t Geert Uytterhoeven
@ 2021-03-17 13:19 ` John Ogness
0 siblings, 0 replies; 7+ messages in thread
From: John Ogness @ 2021-03-17 13:19 UTC (permalink / raw)
To: Geert Uytterhoeven; +Cc: Simon Horman, Varad Gautam, kexec
On 2021-03-17, Geert Uytterhoeven <geert+renesas@glider.be> wrote:
> When compiling for 32-bit:
>
> util_lib/elf_info.c: In function ‘dump_dmesg_lockless’:
> util_lib/elf_info.c:1095:39: warning: format ‘%lu’ expects argument of type ‘long unsigned int’, but argument 3 has type ‘size_t’ {aka ‘unsigned int’} [-Wformat=]
> 1095 | fprintf(stderr, "Failed to malloc %lu bytes for prb: %s\n",
> | ~~^
> | |
> | long unsigned int
> | %u
> 1096 | printk_ringbuffer_sz, strerror(errno));
> | ~~~~~~~~~~~~~~~~~~~~
> | |
> | size_t {aka unsigned int}
> util_lib/elf_info.c:1101:49: warning: format ‘%lu’ expects
> argument of type ‘long unsigned int’, but argument 3 has type ‘size_t’
> {aka ‘unsigned int’} [-Wformat=]
> 1101 | fprintf(stderr, "Failed to read prb of size %lu bytes: %s\n",
> | ~~^
> | |
> | long unsigned int
> | %u
> 1102 | printk_ringbuffer_sz, strerror(errno));
> | ~~~~~~~~~~~~~~~~~~~~
> | |
> | size_t {aka unsigned int}
>
> Indeed, "size_t" is "unsigned int" on 32-bit platforms, and "unsigned
> long" on 64-bit platforms.
>
> Fix this by formatting using "%zu".
>
> Fixes: 4149df9005f2cdd2 ("printk: add support for lockless ringbuffer")
> Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
Reviewed-by: John Ogness <john.ogness@linutronix.de>
> ---
> util_lib/elf_info.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/util_lib/elf_info.c b/util_lib/elf_info.c
> index 7c0a2c345379a7ca..676926ca8c5f3766 100644
> --- a/util_lib/elf_info.c
> +++ b/util_lib/elf_info.c
> @@ -1092,13 +1092,13 @@ static void dump_dmesg_lockless(int fd, void (*handler)(char*, unsigned int))
> kaddr = read_file_pointer(fd, vaddr_to_offset(prb_vaddr));
> m.prb = calloc(1, printk_ringbuffer_sz);
> if (!m.prb) {
> - fprintf(stderr, "Failed to malloc %lu bytes for prb: %s\n",
> + fprintf(stderr, "Failed to malloc %zu bytes for prb: %s\n",
> printk_ringbuffer_sz, strerror(errno));
> exit(64);
> }
> ret = pread(fd, m.prb, printk_ringbuffer_sz, vaddr_to_offset(kaddr));
> if (ret != printk_ringbuffer_sz) {
> - fprintf(stderr, "Failed to read prb of size %lu bytes: %s\n",
> + fprintf(stderr, "Failed to read prb of size %zu bytes: %s\n",
> printk_ringbuffer_sz, strerror(errno));
> exit(65);
> }
_______________________________________________
kexec mailing list
kexec@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kexec
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 0/3] Miscellaneous 32-bit fixes
2021-03-17 12:14 [PATCH 0/3] Miscellaneous 32-bit fixes Geert Uytterhoeven
` (2 preceding siblings ...)
2021-03-17 12:14 ` [PATCH 3/3] printk: Use %zu to format size_t Geert Uytterhoeven
@ 2021-04-02 9:58 ` Simon Horman
3 siblings, 0 replies; 7+ messages in thread
From: Simon Horman @ 2021-04-02 9:58 UTC (permalink / raw)
To: Geert Uytterhoeven; +Cc: Varad Gautam, John Ogness, kexec
On Wed, Mar 17, 2021 at 01:14:47PM +0100, Geert Uytterhoeven wrote:
> Hi Simon,
>
> This patch series fixes several compile warnings when building for a
> 32-bit platform. All but the last one are real bugs, from a functional
> point of view.
>
> Thanks for your comments!
Thanks Geert,
applied.
_______________________________________________
kexec mailing list
kexec@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kexec
^ permalink raw reply [flat|nested] 7+ messages in thread