Received: by 2002:a05:6a10:6d10:0:0:0:0 with SMTP id gq16csp934028pxb; Fri, 22 Apr 2022 14:43:54 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy1PQvGhkRz+yWEpJ5uCY5iwf1Bg4lzdmiSpKof93sxnbk751xhHQjHVggtQzaMmoh+lYCF X-Received: by 2002:a63:101:0:b0:3aa:b7e9:6708 with SMTP id 1-20020a630101000000b003aab7e96708mr5596311pgb.111.1650663834784; Fri, 22 Apr 2022 14:43:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1650663834; cv=none; d=google.com; s=arc-20160816; b=V59yYC/QTv4yhZQCnOMK+mktyvlpdfIxd4+7b0plyVTeAFlbQssibmJw/07Y35O31Q Mw5cy/nsYtO7lPnJYqxXEEYAihPuRYtFcu9HFVf4YDk9qjl9QGGIn0QV3nPLcx9GpD2X rBG3FaMsrIw1246TYsnadEGfb9XSDn5SddjAPF8j5iHDXX7X68X4PGVONpUR7uhvHTLG h/IOC5oubbP1/wA2wxSq+e2FMPgAdRFT5misvBR80Qqok4O88cFqSaMFJyg7Owv4kKGH heja7dcMO3nrsj7Jwgsj16o287Xgw6dFQIYWFIqoPnZdZE92kvh4szWPcKd18Kf9P9C0 Mr6Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :feedback-id:references:in-reply-to:message-id:subject:reply-to:cc :from:to:dkim-signature:date; bh=0PStfJn/A30V4r63nD53fw6U9MRSxUFeg0SQxYCDl8o=; b=gw7CdxJOLKBEesjlqr1esKwLMKr05uDAG4L8yG+6jbOlX4OsaMcnId9ye7KqgciFkf PeWaTAxmEH+rQ3gDkxIT/tbIWw7s3k8WlxB8pOQOG782yrlFwArfP00xJp6wuTyMe05T 2fnw3GKQPmSV2JOAQKOU01HqfLZv0TLdrCBqwa4GdvGJ3l9dxxFOruigLn5qZVSfqsR7 oksHx2nB1nfUqEyfs2tzw1nrslFAB+HftIdOnsXSzfZg7Is2LIaqmxOlT3lJpdVZEyY5 1V9lHaZFbguidAB7sZNk6q+Pme9qsgOG4fZIEkKFu8Rgy1zKP62WVJ6+eFO2ZSQt7/rx vKKg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@pm.me header.s=protonmail2 header.b=ha5O7GsY; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=pm.me Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id r80-20020a632b53000000b0039d2ffc2de2si9536372pgr.789.2022.04.22.14.43.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Apr 2022 14:43:54 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@pm.me header.s=protonmail2 header.b=ha5O7GsY; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=pm.me Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id D1057322FF7; Fri, 22 Apr 2022 12:51:42 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1383520AbiDUAog (ORCPT + 99 others); Wed, 20 Apr 2022 20:44:36 -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 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 m= onitoring") 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(-) diff --git a/samples/bpf/cookie_uid_helper_example.c b/samples/bpf/cookie_u= id_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) =09=09=09error(1, errno, "fail to get entry value of Key: %u\n", =09=09=09=09curN); =09=09} else { -=09=09=09printf("cookie: %u, uid: 0x%x, Packet Count: %lu," -=09=09=09=09" Bytes Count: %lu\n", curN, curEntry.uid, -=09=09=09=09curEntry.packets, curEntry.bytes); +=09=09=09printf("cookie: %u, uid: 0x%x, Packet Count: %llu, Bytes Count: %= llu\n", +=09=09=09 curN, curEntry.uid, (__u64)curEntry.packets, +=09=09=09 (__u64)curEntry.bytes); =09=09} =09} } @@ -265,9 +265,9 @@ static void udp_client(void) =09=09if (res < 0) =09=09=09error(1, errno, "lookup sk stat failed, cookie: %lu\n", =09=09=09 cookie); -=09=09printf("cookie: %lu, uid: 0x%x, Packet Count: %lu," -=09=09=09" Bytes Count: %lu\n\n", cookie, dataEntry.uid, -=09=09=09dataEntry.packets, dataEntry.bytes); +=09=09printf("cookie: %llu, uid: 0x%x, Packet Count: %llu, Bytes Count: %l= lu\n\n", +=09=09 (__u64)cookie, dataEntry.uid, (__u64)dataEntry.packets, +=09=09 (__u64)dataEntry.bytes); =09} =09close(s_send); =09close(s_rcv); diff --git a/samples/bpf/lwt_len_hist_user.c b/samples/bpf/lwt_len_hist_use= r.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) =09while (bpf_map_get_next_key(map_fd, &key, &next_key) =3D=3D 0) { =09=09if (next_key >=3D MAX_INDEX) { -=09=09=09fprintf(stderr, "Key %lu out of bounds\n", next_key); +=09=09=09fprintf(stderr, "Key %llu out of bounds\n", +=09=09=09=09(__u64)next_key); =09=09=09continue; =09=09} @@ -66,8 +67,8 @@ int main(int argc, char **argv) =09for (i =3D 1; i <=3D max_key + 1; i++) { =09=09stars(starstr, data[i - 1], max_value, MAX_STARS); -=09=09printf("%8ld -> %-8ld : %-8ld |%-*s|\n", -=09=09 (1l << i) >> 1, (1l << i) - 1, data[i - 1], +=09=09printf("%8ld -> %-8ld : %-8lld |%-*s|\n", +=09=09 (1l << i) >> 1, (1l << i) - 1, (__u64)data[i - 1], =09=09 MAX_STARS, starstr); =09} -- 2.36.0