From: Alexander Lobakin <alobakin@pm.me>
To: Alexei Starovoitov <ast@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>,
Andrii Nakryiko <andrii@kernel.org>
Cc: Alexander Lobakin <alobakin@pm.me>,
Maciej Fijalkowski <maciej.fijalkowski@intel.com>,
Song Liu <songliubraving@fb.com>,
Kumar Kartikeya Dwivedi <memxor@gmail.com>,
bpf@vger.kernel.org, netdev@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: [PATCH v2 bpf 07/11] samples/bpf: fix uin64_t format literals
Date: Thu, 21 Apr 2022 00:39:32 +0000 [thread overview]
Message-ID: <20220421003152.339542-8-alobakin@pm.me> (raw)
In-Reply-To: <20220421003152.339542-1-alobakin@pm.me>
There's a couple places where uin64_t is being passed as an %lu
format argument. That type is defined as unsigned long on 64-bit
systems and as unsigned long long on 32-bit, so neither %lu nor
%llu are not universal.
One of the options is %PRIu64, but since it's always 8-byte long,
just cast it to the _proper_ __u64 and print as %llu.
Fixes: 51570a5ab2b7 ("A Sample of using socket cookie and uid for traffic monitoring")
Fixes: 00f660eaf378 ("Sample program using SO_COOKIE")
Signed-off-by: Alexander Lobakin <alobakin@pm.me>
---
samples/bpf/cookie_uid_helper_example.c | 12 ++++++------
samples/bpf/lwt_len_hist_user.c | 7 ++++---
2 files changed, 10 insertions(+), 9 deletions(-)
diff --git a/samples/bpf/cookie_uid_helper_example.c b/samples/bpf/cookie_uid_helper_example.c
index f0df3dda4b1f..269fac58fd5c 100644
--- a/samples/bpf/cookie_uid_helper_example.c
+++ b/samples/bpf/cookie_uid_helper_example.c
@@ -207,9 +207,9 @@ static void print_table(void)
error(1, errno, "fail to get entry value of Key: %u\n",
curN);
} else {
- printf("cookie: %u, uid: 0x%x, Packet Count: %lu,"
- " Bytes Count: %lu\n", curN, curEntry.uid,
- curEntry.packets, curEntry.bytes);
+ printf("cookie: %u, uid: 0x%x, Packet Count: %llu, Bytes Count: %llu\n",
+ curN, curEntry.uid, (__u64)curEntry.packets,
+ (__u64)curEntry.bytes);
}
}
}
@@ -265,9 +265,9 @@ static void udp_client(void)
if (res < 0)
error(1, errno, "lookup sk stat failed, cookie: %lu\n",
cookie);
- printf("cookie: %lu, uid: 0x%x, Packet Count: %lu,"
- " Bytes Count: %lu\n\n", cookie, dataEntry.uid,
- dataEntry.packets, dataEntry.bytes);
+ printf("cookie: %llu, uid: 0x%x, Packet Count: %llu, Bytes Count: %llu\n\n",
+ (__u64)cookie, dataEntry.uid, (__u64)dataEntry.packets,
+ (__u64)dataEntry.bytes);
}
close(s_send);
close(s_rcv);
diff --git a/samples/bpf/lwt_len_hist_user.c b/samples/bpf/lwt_len_hist_user.c
index 430a4b7e353e..c682faa75a2b 100644
--- a/samples/bpf/lwt_len_hist_user.c
+++ b/samples/bpf/lwt_len_hist_user.c
@@ -44,7 +44,8 @@ int main(int argc, char **argv)
while (bpf_map_get_next_key(map_fd, &key, &next_key) == 0) {
if (next_key >= MAX_INDEX) {
- fprintf(stderr, "Key %lu out of bounds\n", next_key);
+ fprintf(stderr, "Key %llu out of bounds\n",
+ (__u64)next_key);
continue;
}
@@ -66,8 +67,8 @@ int main(int argc, char **argv)
for (i = 1; i <= max_key + 1; i++) {
stars(starstr, data[i - 1], max_value, MAX_STARS);
- printf("%8ld -> %-8ld : %-8ld |%-*s|\n",
- (1l << i) >> 1, (1l << i) - 1, data[i - 1],
+ printf("%8ld -> %-8ld : %-8lld |%-*s|\n",
+ (1l << i) >> 1, (1l << i) - 1, (__u64)data[i - 1],
MAX_STARS, starstr);
}
--
2.36.0
next prev parent reply other threads:[~2022-04-21 0:41 UTC|newest]
Thread overview: 32+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-04-21 0:38 [PATCH v2 bpf 00/11] bpf: random unpopular userspace fixes (32 bit et al) Alexander Lobakin
2022-04-21 0:38 ` [PATCH v2 bpf 01/11] bpftool: use a local copy of perf_event to fix accessing ::bpf_cookie Alexander Lobakin
2022-04-21 0:38 ` [PATCH v2 bpf 02/11] bpftool: define a local bpf_perf_link to fix accessing its fields Alexander Lobakin
2023-04-14 9:54 ` Michal Suchánek
2023-04-14 15:18 ` Alexander Lobakin
2023-04-14 16:28 ` Michal Suchánek
2023-04-20 23:07 ` Andrii Nakryiko
2023-04-21 7:39 ` Michal Suchánek
2023-05-03 23:43 ` Quentin Monnet
2023-05-03 23:52 ` Andrii Nakryiko
2023-05-04 8:18 ` Michal Suchánek
2023-05-04 16:48 ` Yonghong Song
2022-04-21 0:39 ` [PATCH v2 bpf 03/11] bpftool: use a local bpf_perf_event_value " Alexander Lobakin
2023-06-06 21:02 ` Nick Desaulniers
2023-06-07 10:42 ` Quentin Monnet
2023-06-07 16:18 ` Alexander Lobakin
2022-04-21 0:39 ` [PATCH v2 bpf 04/11] bpftool: fix fcntl.h include Alexander Lobakin
2022-04-21 0:39 ` [PATCH v2 bpf 05/11] samples/bpf: add 'asm/mach-generic' include path for every MIPS Alexander Lobakin
2022-04-21 0:39 ` [PATCH v2 bpf 06/11] samples/bpf: use host bpftool to generate vmlinux.h, not target Alexander Lobakin
2022-04-21 0:39 ` Alexander Lobakin [this message]
2022-04-21 7:46 ` [PATCH v2 bpf 07/11] samples/bpf: fix uin64_t format literals David Laight
2022-04-21 22:55 ` Alexander Lobakin
2022-04-21 0:39 ` [PATCH v2 bpf 08/11] samples/bpf: fix false-positive right-shift underflow warnings Alexander Lobakin
2022-04-21 0:39 ` [PATCH v2 bpf 09/11] samples/bpf: fix include order for non-Glibc environments Alexander Lobakin
2022-04-21 0:39 ` [PATCH v2 bpf 10/11] samples/bpf: fix -Wsequence-point Alexander Lobakin
2022-04-21 0:39 ` [PATCH v2 bpf 11/11] samples/bpf: xdpsock: fix -Wmaybe-uninitialized Alexander Lobakin
2022-04-21 0:40 ` [PATCH v2 bpf 00/11] bpf: random unpopular userspace fixes (32 bit et al) Alexei Starovoitov
2022-04-21 10:52 ` Toke Høiland-Jørgensen
2022-04-21 22:39 ` Alexander Lobakin
2022-04-21 23:17 ` Toke Høiland-Jørgensen
2022-05-03 21:17 ` Alexander Lobakin
2022-05-04 11:34 ` Toke Høiland-Jørgensen
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=20220421003152.339542-8-alobakin@pm.me \
--to=alobakin@pm.me \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=linux-kernel@vger.kernel.org \
--cc=maciej.fijalkowski@intel.com \
--cc=memxor@gmail.com \
--cc=netdev@vger.kernel.org \
--cc=songliubraving@fb.com \
/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 NNTP newsgroup(s).