From mboxrd@z Thu Jan 1 00:00:00 1970 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 B16D0C43334 for ; Thu, 7 Jul 2022 18:01:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234713AbiGGSBg convert rfc822-to-8bit (ORCPT ); Thu, 7 Jul 2022 14:01:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34940 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235422AbiGGSBe (ORCPT ); Thu, 7 Jul 2022 14:01:34 -0400 Received: from relay5.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 113B126132 for ; Thu, 7 Jul 2022 11:01:33 -0700 (PDT) Received: from omf11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 1B3526101C; Thu, 7 Jul 2022 18:01:31 +0000 (UTC) Received: from [HIDDEN] (Authenticated sender: joe@perches.com) by omf11.hostedemail.com (Postfix) with ESMTPA id E45E020037; Thu, 7 Jul 2022 18:01:27 +0000 (UTC) Message-ID: Subject: Re: [PATCH] net: ipv4: fix clang -Wformat warning From: Joe Perches To: Justin Stitt Cc: Steffen Klassert , Herbert Xu , "David S . Miller" , Hideaki YOSHIFUJI , David Ahern , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Nathan Chancellor , Nick Desaulniers , Tom Rix , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, llvm@lists.linux.dev Date: Thu, 07 Jul 2022 11:01:26 -0700 In-Reply-To: References: <20220707173040.704116-1-justinstitt@google.com> <6f5a1c04746feb04add15107c70332ac603e4561.camel@perches.com> Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 8BIT User-Agent: Evolution 3.44.1-0ubuntu1 MIME-Version: 1.0 X-Stat-Signature: 9hji8x14hjnfib6t8mqzghy4hgmidssk X-Rspamd-Server: rspamout05 X-Rspamd-Queue-Id: E45E020037 X-Session-Marker: 6A6F6540706572636865732E636F6D X-Session-ID: U2FsdGVkX1+YCj/8yCY3yEUbxnuMVC5Ve/GvPfwKDhc= X-HE-Tag: 1657216887-660842 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, 2022-07-07 at 10:47 -0700, Justin Stitt wrote: > On Thu, Jul 7, 2022 at 10:40 AM Joe Perches wrote: > > > > On Thu, 2022-07-07 at 10:30 -0700, Justin Stitt wrote: > > > When building with Clang we encounter this warning: > > > > net/ipv4/ah4.c:513:4: error: format specifies type 'unsigned short' but > > > > the argument has type 'int' [-Werror,-Wformat] > > > > aalg_desc->uinfo.auth.icv_fullbits / 8); > > > > > > `aalg_desc->uinfo.auth.icv_fullbits` is a u16 but due to default > > > argument promotion becomes an int. > > > > > > Variadic functions (printf-like) undergo default argument promotion. > > > Documentation/core-api/printk-formats.rst specifically recommends using > > > the promoted-to-type's format flag. > > > > > > 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 to %d not only to follow this standard but to suppress the warning > > > as well. > > > > I think it also makes sense to use %u and not %d > > as the original type is unsigned. > Yeah, that would also work. An integer (even a signed one) fully > encompasses a u16 so it's really a choice of style. Do you think the > change to %u warrants a v2 of this patch? As it's rather odd output to use '%u != %d', probably. Your patch, up to you. > > > > > diff --git a/net/ipv4/ah4.c b/net/ipv4/ah4.c > > [] > > > @@ -507,7 +507,7 @@ static int ah_init_state(struct xfrm_state *x) > > > > > > if (aalg_desc->uinfo.auth.icv_fullbits/8 != > > > crypto_ahash_digestsize(ahash)) { > > > - pr_info("%s: %s digestsize %u != %hu\n", > > > + pr_info("%s: %s digestsize %u != %d\n", > > > __func__, x->aalg->alg_name, > > > crypto_ahash_digestsize(ahash), > > > aalg_desc->uinfo.auth.icv_fullbits / 8); > >