All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] btrfs-progs: printf format fixes for 32bit x86
@ 2021-10-27 12:48 Qu Wenruo
  2021-11-02 17:08 ` David Sterba
  0 siblings, 1 reply; 2+ messages in thread
From: Qu Wenruo @ 2021-10-27 12:48 UTC (permalink / raw)
  To: linux-btrfs

When compiling btrfs-progs on 32bit x86 using GCC 11.1.0, there are
several warnings:

  In file included from ./common/utils.h:30,
                   from check/main.c:36:
  check/main.c: In function 'run_next_block':
  ./common/messages.h:42:31: warning: format '%lu' expects argument of type 'long unsigned int', but argument 4 has type 'u32' {aka 'unsigned int'} [-Wformat=]
     42 |                 __btrfs_error((fmt), ##__VA_ARGS__);                    \
        |                               ^~~~~
  check/main.c:6496:33: note: in expansion of macro 'error'
   6496 |                                 error(
        |                                 ^~~~~

  In file included from ./common/utils.h:30,
                   from kernel-shared/volumes.c:32:
  kernel-shared/volumes.c: In function 'btrfs_check_chunk_valid':
  ./common/messages.h:42:31: warning: format '%lu' expects argument of type 'long unsigned int', but argument 4 has type 'u32' {aka 'unsigned int'} [-Wformat=]
     42 |                 __btrfs_error((fmt), ##__VA_ARGS__);                    \
        |                               ^~~~~
  kernel-shared/volumes.c:2052:17: note: in expansion of macro 'error'
   2052 |                 error("invalid chunk item size, have %u expect [%zu, %lu)",
        |                 ^~~~~

  image/main.c: In function 'search_for_chunk_blocks':
  ./common/messages.h:42:31: warning: format '%lu' expects argument of type 'long unsigned int', but argument 3 has type 'size_t' {aka 'unsigned int'} [-Wformat=]
     42 |                 __btrfs_error((fmt), ##__VA_ARGS__);                    \
        |                               ^~~~~
  image/main.c:2122:33: note: in expansion of macro 'error'
   2122 |                                 error(
        |                                 ^~~~~

There are two types of problems:

- __BTRFS_LEAF_DATA_SIZE()
  This macro has no type definition, making it behaves differently on
  different arches.

  Fix this by following kernel to use inline function to make its return
  value fixed to u32.

- size_t related output
  For x86_64 %lu is OK but not for x86.

  Fix this by using %zu.

Signed-off-by: Qu Wenruo <wqu@suse.com>
---
 check/main.c            | 2 +-
 image/main.c            | 2 +-
 kernel-shared/ctree.h   | 6 +++++-
 kernel-shared/volumes.c | 2 +-
 4 files changed, 8 insertions(+), 4 deletions(-)

diff --git a/check/main.c b/check/main.c
index 38b2cfdf5b0b..235a9bab2f52 100644
--- a/check/main.c
+++ b/check/main.c
@@ -6494,7 +6494,7 @@ static int run_next_block(struct btrfs_root *root,
 			if (btrfs_item_size_nr(buf, i) < inline_offset) {
 				ret = -EUCLEAN;
 				error(
-		"invalid file extent item size, have %u expect (%lu, %lu]",
+		"invalid file extent item size, have %u expect (%lu, %u]",
 					btrfs_item_size_nr(buf, i),
 					inline_offset,
 					BTRFS_LEAF_DATA_SIZE(gfs_info));
diff --git a/image/main.c b/image/main.c
index b40e0e5550f8..dbce17e74dbd 100644
--- a/image/main.c
+++ b/image/main.c
@@ -2120,7 +2120,7 @@ static int search_for_chunk_blocks(struct mdrestore_struct *mdres)
 					       current_cluster);
 			if (ret < 0) {
 				error(
-			"failed to search tree blocks in item bytenr %llu size %lu",
+			"failed to search tree blocks in item bytenr %llu size %zu",
 					item_bytenr, size);
 				goto out;
 			}
diff --git a/kernel-shared/ctree.h b/kernel-shared/ctree.h
index 563ea50b3587..8d866e60c1b8 100644
--- a/kernel-shared/ctree.h
+++ b/kernel-shared/ctree.h
@@ -354,7 +354,11 @@ struct btrfs_header {
 	u8 level;
 } __attribute__ ((__packed__));
 
-#define __BTRFS_LEAF_DATA_SIZE(bs) ((bs) - sizeof(struct btrfs_header))
+static inline u32 __BTRFS_LEAF_DATA_SIZE(u32 nodesize)
+{
+	return nodesize - sizeof(struct btrfs_header);
+}
+
 #define BTRFS_LEAF_DATA_SIZE(fs_info) \
 				(__BTRFS_LEAF_DATA_SIZE(fs_info->nodesize))
 
diff --git a/kernel-shared/volumes.c b/kernel-shared/volumes.c
index 6c1e6f1018a3..7d6fe8fd34a7 100644
--- a/kernel-shared/volumes.c
+++ b/kernel-shared/volumes.c
@@ -2094,7 +2094,7 @@ int btrfs_check_chunk_valid(struct btrfs_fs_info *fs_info,
 	 */
 	if (slot >= 0 &&
 	    btrfs_item_size_nr(leaf, slot) < sizeof(struct btrfs_chunk)) {
-		error("invalid chunk item size, have %u expect [%zu, %lu)",
+		error("invalid chunk item size, have %u expect [%zu, %u)",
 			btrfs_item_size_nr(leaf, slot),
 			sizeof(struct btrfs_chunk),
 			BTRFS_LEAF_DATA_SIZE(fs_info));
-- 
2.33.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] btrfs-progs: printf format fixes for 32bit x86
  2021-10-27 12:48 [PATCH] btrfs-progs: printf format fixes for 32bit x86 Qu Wenruo
@ 2021-11-02 17:08 ` David Sterba
  0 siblings, 0 replies; 2+ messages in thread
From: David Sterba @ 2021-11-02 17:08 UTC (permalink / raw)
  To: Qu Wenruo; +Cc: linux-btrfs

On Wed, Oct 27, 2021 at 08:48:46PM +0800, Qu Wenruo wrote:
> When compiling btrfs-progs on 32bit x86 using GCC 11.1.0, there are
> several warnings:
> 
>   In file included from ./common/utils.h:30,
>                    from check/main.c:36:
>   check/main.c: In function 'run_next_block':
>   ./common/messages.h:42:31: warning: format '%lu' expects argument of type 'long unsigned int', but argument 4 has type 'u32' {aka 'unsigned int'} [-Wformat=]
>      42 |                 __btrfs_error((fmt), ##__VA_ARGS__);                    \
>         |                               ^~~~~
>   check/main.c:6496:33: note: in expansion of macro 'error'
>    6496 |                                 error(
>         |                                 ^~~~~
> 
>   In file included from ./common/utils.h:30,
>                    from kernel-shared/volumes.c:32:
>   kernel-shared/volumes.c: In function 'btrfs_check_chunk_valid':
>   ./common/messages.h:42:31: warning: format '%lu' expects argument of type 'long unsigned int', but argument 4 has type 'u32' {aka 'unsigned int'} [-Wformat=]
>      42 |                 __btrfs_error((fmt), ##__VA_ARGS__);                    \
>         |                               ^~~~~
>   kernel-shared/volumes.c:2052:17: note: in expansion of macro 'error'
>    2052 |                 error("invalid chunk item size, have %u expect [%zu, %lu)",
>         |                 ^~~~~
> 
>   image/main.c: In function 'search_for_chunk_blocks':
>   ./common/messages.h:42:31: warning: format '%lu' expects argument of type 'long unsigned int', but argument 3 has type 'size_t' {aka 'unsigned int'} [-Wformat=]
>      42 |                 __btrfs_error((fmt), ##__VA_ARGS__);                    \
>         |                               ^~~~~
>   image/main.c:2122:33: note: in expansion of macro 'error'
>    2122 |                                 error(
>         |                                 ^~~~~
> 
> There are two types of problems:
> 
> - __BTRFS_LEAF_DATA_SIZE()
>   This macro has no type definition, making it behaves differently on
>   different arches.
> 
>   Fix this by following kernel to use inline function to make its return
>   value fixed to u32.
> 
> - size_t related output
>   For x86_64 %lu is OK but not for x86.
> 
>   Fix this by using %zu.
> 
> Signed-off-by: Qu Wenruo <wqu@suse.com>

Added to devel, thanks.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-11-02 17:09 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-27 12:48 [PATCH] btrfs-progs: printf format fixes for 32bit x86 Qu Wenruo
2021-11-02 17:08 ` David Sterba

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.