From patchwork Thu Apr 21 00:39:32 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Lobakin X-Patchwork-Id: 12820964 X-Patchwork-Delegate: bpf@iogearbox.net Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 799B6C433EF for ; Thu, 21 Apr 2022 00:41:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346941AbiDUAob (ORCPT ); Wed, 20 Apr 2022 20:44:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38524 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1383530AbiDUAmZ (ORCPT ); Wed, 20 Apr 2022 20:42:25 -0400 Received: from mail-4322.protonmail.ch (mail-4322.protonmail.ch [185.70.43.22]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 37DB82A262; Wed, 20 Apr 2022 17:39:37 -0700 (PDT) Date: Thu, 21 Apr 2022 00:39:32 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pm.me; s=protonmail2; t=1650501575; bh=0PStfJn/A30V4r63nD53fw6U9MRSxUFeg0SQxYCDl8o=; h=Date:To:From:Cc:Reply-To:Subject:Message-ID:In-Reply-To: References:Feedback-ID:From:To:Cc:Date:Subject:Reply-To: Feedback-ID:Message-ID; b=ha5O7GsYjAxVIWUiwEWS6Wh5ksolr7RWStN0fdNIJ4VKKHWIRQCtr+M06ZWxebTuW vhPVsPi2kytoKb9p90Ziwj2ZT+KPMZ1jXcVqqHchqse4S/0jcOUPyM7PM5N+qZ4WkU 4k4dlSRssuF+OIoMhDXH4fKm/4l4HLB1pl+nLsAmFildlGsK4XKckGPjUQOve0rsk7 cwaEtCPHImlTgg6dDkMdKMls+EjdbjJZ/VD/AxWg1Wfauq2sy4zdW4DaNttbPEM5FV davbM8BIOnKyQl6s3wJgCNuNXlP1GHlHIehk2M4F60+Y0ixcbzaqgkz+G32ZZKp6AW Vg8LiqmlPGU7Q== To: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko From: Alexander Lobakin Cc: Alexander Lobakin , Maciej Fijalkowski , Song Liu , Kumar Kartikeya Dwivedi , bpf@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Reply-To: Alexander Lobakin Subject: [PATCH v2 bpf 07/11] samples/bpf: fix uin64_t format literals Message-ID: <20220421003152.339542-8-alobakin@pm.me> In-Reply-To: <20220421003152.339542-1-alobakin@pm.me> References: <20220421003152.339542-1-alobakin@pm.me> Feedback-ID: 22809121:user:proton MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net 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 --- samples/bpf/cookie_uid_helper_example.c | 12 ++++++------ samples/bpf/lwt_len_hist_user.c | 7 ++++--- 2 files changed, 10 insertions(+), 9 deletions(-) -- 2.36.0 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); }