Received: by 2002:a5d:9c59:0:0:0:0:0 with SMTP id 25csp2212268iof; Tue, 7 Jun 2022 23:21:51 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyTbnAR9RgZ2dcRLC4ZEO1oYMrn1DMRUCBh1eYCL/kyR9VhQmg/70xWXAYQ4TM0pbg4e/nO X-Received: by 2002:a05:6a00:1886:b0:51b:eefe:e182 with SMTP id x6-20020a056a00188600b0051beefee182mr22757434pfh.75.1654669311611; Tue, 07 Jun 2022 23:21:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654669311; cv=none; d=google.com; s=arc-20160816; b=GYrc3Jlj10XaMlV94yE78dwlJVpssMK3XwfJC9tZx4wKfQYYwdhrhtavcHcehF+s7Q m0dfWhPjHr3exCqiCyGudH0UjXHfK5APItmtQSJ9T9ZEuwkSJj5UCDVUEF8BOE8W4PP7 7nxacPvTVH5H+9wKHyawXb8wB+gYII7NsKjxH14tu5sC24+fxBfSGcNiZB9XCotaHNFm 0ayToY5UJcS5rzwaoe7J/TH2tE16h5KqWbkTPE2slxNtrZ5OgQcEE7wlchVpteip80gC ju8xBsx4cMnL2TpMmKFlY+L4z0UGW5ege+uCPHc0efUwoOfyA5U5t7iavlEF2U2EL/W9 knJw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=3q6TfnyhK/JVdpGe1sn/i51UuwyEe8WKDR0Bhpepgkw=; b=bDJm5mr2P4vqf6YFHN2IkSsokfeGXJCMgzJfXtPuR1QjG59UHA9IvnSacmNAc+k5co kQK3iQRMjJxi131HR6ATuFxSVqDjKEhaUinvxjF5VCPlEqO8jHAc18iaIEjydpkNJbxU DDW2ioiG2yUbv2lhbPkPwpl00RrWQoY3O8h0X/32X7IUejLlYPU5fURzdmjHtThDhQVn WjopHRqy2iOgUoZmWxo95YfqdaBodJ2VIV4UJOcGh1bmrBAsdVfeBaVQd24qcfonwJ51 0nTKA78evwUPKIYMDGb82KXV9IvqC9nAE5WGu4vGyBevCpmQmHElOdLvTR5KZIoyqs7r f1qw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=tnMvdL81; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id s9-20020a639e09000000b003fdac2b75a0si8310556pgd.475.2022.06.07.23.21.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Jun 2022 23:21:51 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=tnMvdL81; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id BDEAB254454; Tue, 7 Jun 2022 22:42:32 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1443531AbiFHCCl (ORCPT + 99 others); Tue, 7 Jun 2022 22:02:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42530 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1842425AbiFHAJ2 (ORCPT ); Tue, 7 Jun 2022 20:09:28 -0400 Received: from mail-lf1-x134.google.com (mail-lf1-x134.google.com [IPv6:2a00:1450:4864:20::134]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6CF9614A930 for ; Tue, 7 Jun 2022 13:36:56 -0700 (PDT) Received: by mail-lf1-x134.google.com with SMTP id h23so30089545lfe.4 for ; Tue, 07 Jun 2022 13:36:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=3q6TfnyhK/JVdpGe1sn/i51UuwyEe8WKDR0Bhpepgkw=; b=tnMvdL81BwwXW6yVLeadSVxqoY40YLtneqyhtf7dzDEpjVWIgYH2iRPKp6eha1ETf/ Smnkr1PDED9FhO6HiPjOWfoRl+qtY5bDl2zV8/T21F7omzHIsh8REiwWKm7rynrFC7ha 9z+rlqOGw5hX23QjtYQZk2+zXzfNjdTLnK4vrIWAqzEASTEjsvOOPjhpZ6f40Z7QrcnB /r0WaquGT7aHMBd+33JvbWRYcNc6jPuoNu/Lox9ShGV826J9aHUp1scqdqE5EYLGSHfx gfWYSsAzMjOPFQwNOxPDSeXLbznp8dwHpy4bYBa63aLMO72Y8VFdbnm8Wo5j+lC8f2hp o8GA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=3q6TfnyhK/JVdpGe1sn/i51UuwyEe8WKDR0Bhpepgkw=; b=i8KLpsLlwwtXetRS4CcAg9dHQne+ZQvvmCpaXAaGsSETHVcchzA/7FYYKrIwxqBzfv PrbrdGApj9mg3udgQQf9fb20/9rVg8mdWcGeUzBAnro3fQeki1RCsyrWSU2nqFe0OxyV 0JMxGog9JfTmc70PAaaEoeCgoy0X0wyV7ULNBa8sEYJLiU/BmOSGOuM2ZKnpGxnF4DCR E3Idu7NC7JOrizsIjSs2gK6MZd+kOFbZZlfYftuKpsmvufzx5+KeBefwUATJH/T9Jh1i QykzOF7gPx/Vfvp/v5vdtHh+0JYe7iQHy2YIWREVyEbRrJTddGbrWDTvaNddTU4UhqDX y4YQ== X-Gm-Message-State: AOAM531hCGe+9JsbrunLUg6s80knKZ7QR3tM2lrdwi/QirnTNXd1Xpzo LDsJA7SAYKPNyJf4LxmDpOAj3RbdH+kGqoQE1tcvxw== X-Received: by 2002:a05:6512:3132:b0:478:f2f1:3a75 with SMTP id p18-20020a056512313200b00478f2f13a75mr21381284lfd.100.1654634213023; Tue, 07 Jun 2022 13:36:53 -0700 (PDT) MIME-Version: 1.0 References: <20220607180847.13482-1-jstitt007@gmail.com> In-Reply-To: From: Nick Desaulniers Date: Tue, 7 Jun 2022 13:36:41 -0700 Message-ID: Subject: Re: [PATCH v2] netfilter: conntrack: Fix clang -Wformat warning in print_tuple() To: Justin Stitt Cc: Pablo Neira Ayuso , Jozsef Kadlecsik , Florian Westphal , llvm@lists.linux.dev, Nathan Chancellor , "David S. Miller" , Eric Dumazet , Jakub Kicinski , pabeni@redhat.com, Tom Rix , netfilter-devel@vger.kernel.org, coreteam@netfilter.org, Network Development , LKML Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-9.5 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE, USER_IN_DEF_DKIM_WL 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 Also, please make sure to run scripts/get_maintainer.pl on your patch file and CC everyone it recommends, with the maintainers you want to pick up your patch in the To field. https://lore.kernel.org/llvm/20220607180847.13482-1-jstitt007@gmail.com/T/#u $ ./scripts/get_maintainer.pl 0001-netfilter-conntrack-Fix-clang-Wformat-warning-in-pri.patch Pablo Neira Ayuso (maintainer:NETFILTER) Jozsef Kadlecsik (maintainer:NETFILTER) Florian Westphal (maintainer:NETFILTER) "David S. Miller" (maintainer:NETWORKING [GENERAL]) Eric Dumazet (maintainer:NETWORKING [GENERAL]) Jakub Kicinski (maintainer:NETWORKING [GENERAL]) Paolo Abeni (maintainer:NETWORKING [GENERAL]) Nathan Chancellor (supporter:CLANG/LLVM BUILD SUPPORT) Nick Desaulniers (supporter:CLANG/LLVM BUILD SUPPORT) Tom Rix (reviewer:CLANG/LLVM BUILD SUPPORT) netfilter-devel@vger.kernel.org (open list:NETFILTER) coreteam@netfilter.org (open list:NETFILTER) netdev@vger.kernel.org (open list:NETWORKING [GENERAL]) linux-kernel@vger.kernel.org (open list) llvm@lists.linux.dev (open list:CLANG/LLVM BUILD SUPPORT On Tue, Jun 7, 2022 at 1:33 PM Nick Desaulniers wrote: > > On Tue, Jun 7, 2022 at 11:09 AM Justin Stitt wrote: > > > > | net/netfilter/nf_conntrack_standalone.c:63:7: warning: format specifies type > > | 'unsigned short' but the argument has type 'int' [-Wformat] > > | ntohs(tuple->src.u.tcp.port), > > | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~ > > | net/netfilter/nf_conntrack_standalone.c:64:7: warning: format specifies type > > | 'unsigned short' but the argument has type 'int' [-Wformat] > > | ntohs(tuple->dst.u.tcp.port)); > > | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~ > > | net/netfilter/nf_conntrack_standalone.c:69:7: warning: format specifies type > > | 'unsigned short' but the argument has type 'int' [-Wformat] > > | ntohs(tuple->src.u.udp.port), > > | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~ > > | net/netfilter/nf_conntrack_standalone.c:70:7: warning: format specifies type > > | 'unsigned short' but the argument has type 'int' [-Wformat] > > | ntohs(tuple->dst.u.udp.port)); > > | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~ > > | net/netfilter/nf_conntrack_standalone.c:75:7: warning: format specifies type > > | 'unsigned short' but the argument has type 'int' [-Wformat] > > | ntohs(tuple->src.u.dccp.port), > > | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > > | net/netfilter/nf_conntrack_standalone.c:76:7: warning: format specifies type > > | 'unsigned short' but the argument has type 'int' [-Wformat] > > | ntohs(tuple->dst.u.dccp.port)); > > | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > > | net/netfilter/nf_conntrack_standalone.c:80:7: warning: format specifies type > > | 'unsigned short' but the argument has type 'int' [-Wformat] > > | ntohs(tuple->src.u.sctp.port), > > | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > > | net/netfilter/nf_conntrack_standalone.c:81:7: warning: format specifies type > > | 'unsigned short' but the argument has type 'int' [-Wformat] > > | ntohs(tuple->dst.u.sctp.port)); > > | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > > > > Variadic functions (printf-like) undergo default argument promotion. > > Documentation/core-api/printk-formats.rst specifically recommends > > using the promoted-to-type's format flag. > > > > Also, as per C11 6.3.1.1: > > (https://www.open-std.org/jtc1/sc22/wg14/www/docs/n1548.pdf) > > `If an int can represent all values of the original type ..., the > > value is converted to an int; otherwise, it is converted to an > > unsigned int. These are called the integer promotions.` > > Thus it makes sense to change %hu (as well as %u) to %d. > > > > It should be noted that %u does not produce the same warning as %hu in this > > context. However, it should probably be changed as well for consistency. > > Right, because they are `unsigned char` and the parameter is unnamed > for variadic functions they are also default-argument-promoted to int. > -Wformat won't warn on signedness. > > Thanks for the patch! > > Reviewed-by: Nick Desaulniers > Link: https://github.com/ClangBuiltLinux/linux/issues/378 > > Also, Nathan supplied his RB tag on v1; it's ok next time to include > it on subsequent revisions of patches, so long as you don't change the > patch too much between revisions. > > > > > Signed-off-by: Justin Stitt > > --- > > Diff between v1 -> v2: > > * update commit message and subject line > > > > Note: The architecture (arm64) is critical for reproducing this warning. > > > > net/netfilter/nf_conntrack_standalone.c | 10 +++++----- > > 1 file changed, 5 insertions(+), 5 deletions(-) > > > > diff --git a/net/netfilter/nf_conntrack_standalone.c b/net/netfilter/nf_conntrack_standalone.c > > index 6ad7bbc90d38..afbec8a12c5e 100644 > > --- a/net/netfilter/nf_conntrack_standalone.c > > +++ b/net/netfilter/nf_conntrack_standalone.c > > @@ -53,30 +53,30 @@ print_tuple(struct seq_file *s, const struct nf_conntrack_tuple *tuple, > > > > switch (l4proto->l4proto) { > > case IPPROTO_ICMP: > > - seq_printf(s, "type=%u code=%u id=%u ", > > + seq_printf(s, "type=%d code=%d id=%d ", > > tuple->dst.u.icmp.type, > > tuple->dst.u.icmp.code, > > ntohs(tuple->src.u.icmp.id)); > > break; > > case IPPROTO_TCP: > > - seq_printf(s, "sport=%hu dport=%hu ", > > + seq_printf(s, "sport=%d dport=%d ", > > ntohs(tuple->src.u.tcp.port), > > ntohs(tuple->dst.u.tcp.port)); > > break; > > case IPPROTO_UDPLITE: > > case IPPROTO_UDP: > > - seq_printf(s, "sport=%hu dport=%hu ", > > + seq_printf(s, "sport=%d dport=%d ", > > ntohs(tuple->src.u.udp.port), > > ntohs(tuple->dst.u.udp.port)); > > > > break; > > case IPPROTO_DCCP: > > - seq_printf(s, "sport=%hu dport=%hu ", > > + seq_printf(s, "sport=%d dport=%d ", > > ntohs(tuple->src.u.dccp.port), > > ntohs(tuple->dst.u.dccp.port)); > > break; > > case IPPROTO_SCTP: > > - seq_printf(s, "sport=%hu dport=%hu ", > > + seq_printf(s, "sport=%d dport=%d ", > > ntohs(tuple->src.u.sctp.port), > > ntohs(tuple->dst.u.sctp.port)); > > break; > > -- > > 2.30.2 > > > > > -- > Thanks, > ~Nick Desaulniers -- Thanks, ~Nick Desaulniers