From: Jeff Layton <jlayton@kernel•org>
To: Geert Uytterhoeven <geert+renesas@glider•be>,
Christian Brauner <brauner@kernel•org>
Cc: linux-next@vger•kernel.org, linux-kernel@vger•kernel.org
Subject: Re: [PATCH -next] samples/vfs/mountinfo: Use __u64 instead of uint64_t
Date: Mon, 06 Jan 2025 12:40:03 -0500 [thread overview]
Message-ID: <04fafa6fd58252bf74b9606278ff5d68cb62c102.camel@kernel.org> (raw)
In-Reply-To: <20250106134802.1019911-1-geert+renesas@glider.be>
On Mon, 2025-01-06 at 14:48 +0100, Geert Uytterhoeven wrote:
> On 32-bit (e.g. arm32, m68k):
>
> samples/vfs/mountinfo.c: In function ‘dump_mountinfo’:
> samples/vfs/mountinfo.c:145:29: warning: format ‘%lx’ expects argument of type ‘long unsigned int’, but argument 2 has type ‘uint64_t’ {aka ‘long long unsigned int’} [-Wformat=]
> 145 | printf("0x%lx 0x%lx 0x%llx ", mnt_ns_id, mnt_id, buf->mnt_parent_id);
> | ~~^ ~~~~~~~~~
> | | |
> | long unsigned int uint64_t {aka long long unsigned int}
> | %llx
> samples/vfs/mountinfo.c:145:35: warning: format ‘%lx’ expects argument of type ‘long unsigned int’, but argument 3 has type ‘uint64_t’ {aka ‘long long unsigned int’} [-Wformat=]
> 145 | printf("0x%lx 0x%lx 0x%llx ", mnt_ns_id, mnt_id, buf->mnt_parent_id);
> | ~~^ ~~~~~~
> | | |
> | long unsigned int uint64_t {aka long long unsigned int}
> | %llx
>
> Just using "%llx" instead of "%lx" is not sufficient, as uint64_t is
> "long unsigned int" on some 64-bit platforms like arm64. Hence also
> replace "uint64_t" by "__u64", which matches what most other samples
> are already using.
>
> Fixes: d95e49bf8bcdc7c1 ("samples: add a mountinfo program to demonstrate statmount()/listmount()")
> Signed-off-by: Geert Uytterhoeven <geert+renesas@glider•be>
> ---
> Feel free to fold into the original commit.
>
> Alternatively, you can use PRIx64, which is used by tools/, but not by
> any of the current samples.
> ---
> samples/vfs/mountinfo.c | 35 +++++++++++++++++------------------
> 1 file changed, 17 insertions(+), 18 deletions(-)
>
> diff --git a/samples/vfs/mountinfo.c b/samples/vfs/mountinfo.c
> index 2b17d244d321ee75..f47c035cc339544e 100644
> --- a/samples/vfs/mountinfo.c
> +++ b/samples/vfs/mountinfo.c
> @@ -32,9 +32,9 @@ static bool ext_format;
> * There are no bindings in glibc for listmount() and statmount() (yet),
> * make our own here.
> */
> -static int statmount(uint64_t mnt_id, uint64_t mnt_ns_id, uint64_t mask,
> - struct statmount *buf, size_t bufsize,
> - unsigned int flags)
> +static int statmount(__u64 mnt_id, __u64 mnt_ns_id, __u64 mask,
> + struct statmount *buf, size_t bufsize,
> + unsigned int flags)
> {
> struct mnt_id_req req = {
> .size = MNT_ID_REQ_SIZE_VER0,
> @@ -50,9 +50,8 @@ static int statmount(uint64_t mnt_id, uint64_t mnt_ns_id, uint64_t mask,
> return syscall(__NR_statmount, &req, buf, bufsize, flags);
> }
>
> -static ssize_t listmount(uint64_t mnt_id, uint64_t mnt_ns_id,
> - uint64_t last_mnt_id, uint64_t list[], size_t num,
> - unsigned int flags)
> +static ssize_t listmount(__u64 mnt_id, __u64 mnt_ns_id, __u64 last_mnt_id,
> + __u64 list[], size_t num, unsigned int flags)
> {
> struct mnt_id_req req = {
> .size = MNT_ID_REQ_SIZE_VER0,
> @@ -68,7 +67,7 @@ static ssize_t listmount(uint64_t mnt_id, uint64_t mnt_ns_id,
> return syscall(__NR_listmount, &req, list, num, flags);
> }
>
> -static void show_mnt_attrs(uint64_t flags)
> +static void show_mnt_attrs(__u64 flags)
> {
> printf("%s", flags & MOUNT_ATTR_RDONLY ? "ro" : "rw");
>
> @@ -112,7 +111,7 @@ static void show_propagation(struct statmount *sm)
> printf(" unbindable");
> }
>
> -static void show_sb_flags(uint64_t flags)
> +static void show_sb_flags(__u64 flags)
> {
> printf("%s", flags & MS_RDONLY ? "ro" : "rw");
> if (flags & MS_SYNCHRONOUS)
> @@ -125,15 +124,15 @@ static void show_sb_flags(uint64_t flags)
> printf(",lazytime");
> }
>
> -static int dump_mountinfo(uint64_t mnt_id, uint64_t mnt_ns_id)
> +static int dump_mountinfo(__u64 mnt_id, __u64 mnt_ns_id)
> {
> int ret;
> struct statmount *buf = alloca(STATMOUNT_BUFSIZE);
> - const uint64_t mask = STATMOUNT_SB_BASIC | STATMOUNT_MNT_BASIC |
> - STATMOUNT_PROPAGATE_FROM | STATMOUNT_FS_TYPE |
> - STATMOUNT_MNT_ROOT | STATMOUNT_MNT_POINT |
> - STATMOUNT_MNT_OPTS | STATMOUNT_FS_SUBTYPE |
> - STATMOUNT_SB_SOURCE;
> + const __u64 mask = STATMOUNT_SB_BASIC | STATMOUNT_MNT_BASIC |
> + STATMOUNT_PROPAGATE_FROM | STATMOUNT_FS_TYPE |
> + STATMOUNT_MNT_ROOT | STATMOUNT_MNT_POINT |
> + STATMOUNT_MNT_OPTS | STATMOUNT_FS_SUBTYPE |
> + STATMOUNT_SB_SOURCE;
>
> ret = statmount(mnt_id, mnt_ns_id, mask, buf, STATMOUNT_BUFSIZE, 0);
> if (ret < 0) {
> @@ -142,7 +141,7 @@ static int dump_mountinfo(uint64_t mnt_id, uint64_t mnt_ns_id)
> }
>
> if (ext_format)
> - printf("0x%lx 0x%lx 0x%llx ", mnt_ns_id, mnt_id, buf->mnt_parent_id);
> + printf("0x%llx 0x%llx 0x%llx ", mnt_ns_id, mnt_id, buf->mnt_parent_id);
>
> printf("%u %u %u:%u %s %s ", buf->mnt_id_old, buf->mnt_parent_id_old,
> buf->sb_dev_major, buf->sb_dev_minor,
> @@ -166,10 +165,10 @@ static int dump_mountinfo(uint64_t mnt_id, uint64_t mnt_ns_id)
> return 0;
> }
>
> -static int dump_mounts(uint64_t mnt_ns_id)
> +static int dump_mounts(__u64 mnt_ns_id)
> {
> - uint64_t mntid[MAXMOUNTS];
> - uint64_t last_mnt_id = 0;
> + __u64 mntid[MAXMOUNTS];
> + __u64 last_mnt_id = 0;
> ssize_t count;
> int i;
>
Many thanks. I missed that bit of the fix.
Reviewed-by: Jeff Layton <jlayton@kernel•org>
next prev parent reply other threads:[~2025-01-06 17:40 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-01-06 13:48 [PATCH -next] samples/vfs/mountinfo: Use __u64 instead of uint64_t Geert Uytterhoeven
2025-01-06 17:40 ` Jeff Layton [this message]
2025-01-10 11:08 ` Christian Brauner
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=04fafa6fd58252bf74b9606278ff5d68cb62c102.camel@kernel.org \
--to=jlayton@kernel$(echo .)org \
--cc=brauner@kernel$(echo .)org \
--cc=geert+renesas@glider$(echo .)be \
--cc=linux-kernel@vger$(echo .)kernel.org \
--cc=linux-next@vger$(echo .)kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
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