Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp2215736pxp; Mon, 21 Mar 2022 14:05:54 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzAFx1kc58bx/MBdGnzEwvkjhogiH8pIY3OUmxp9IbNRsNl5a3KWtDdOycVKlUdRLHZScga X-Received: by 2002:a05:6a00:22d2:b0:4fa:9d26:bc5d with SMTP id f18-20020a056a0022d200b004fa9d26bc5dmr7657728pfj.79.1647896754431; Mon, 21 Mar 2022 14:05:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1647896754; cv=none; d=google.com; s=arc-20160816; b=cGHFeYKHm9KmMF0X3uCdvFiMW+1idSfS6lHvgMUVsTZL6uv4CogK8P5KpWnSI3esuv 5gVlom4WMj+cwb3Ygtxvw4gZ0Hfr6Elh5L/PIlhc6yZImZ2hfxPa5kepzcPaTRaomAnc R/P7v6NZSMnP/ZKv5R1xkIB+AXJdFlS8SBVPgehiqDLxUv5fHjn/qJJFpBjA4UFnUHdD NntUY+4DaGForHLGGVom0rtd9Znu8nNvjy+kR4JgLWsrC3XFX9YlItGPxNwyI4Tuxcvd jc0qWN+M4j/CDbmX7uG7ZBdDECUErgLBogY3GhF9MdJwcwN1g5DZu1jwaetQGiSxPyD7 yztA== 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=VSE/zjzMF4GUAODi9hUWbSKALcdRpi7FbYvoQ5n/zHE=; b=lRmYuW07NiVZ9SiIVPsH65XvmOb9a0sSKeGhLHMDTlqTJFyW41ZQcQ6BA4qHBet18I 0EwsXMWnSVTRfJWeAHockjH8Smzz8p+tt0JrccqHAL8bDJ2IvCYYZ/1HvOUxiKnvigyc Zv1YWK7Qh2NAhD8E0YtP191BqwsIvsuHbjrOQZXsAW4P8J3VamO2fLCetKMHhjYAbHJF s1H2F8Teis9rXRIAB3Hf/DR5k18Bjm6K0POcr9MzYU9WcuRjT18cT6ND4JswP8aBwN0w WdsgYOuJ7eL/8uoH66IkFF/58j5YaZhifEgqCZ39F6H359feRsv4W+ygr/IewNhfuHlm qU3Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=fcyAfSP5; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id y4-20020a63ce04000000b003842921930bsi165535pgf.808.2022.03.21.14.05.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Mar 2022 14:05: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=@google.com header.s=20210112 header.b=fcyAfSP5; 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=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 B3D0A43AED; Mon, 21 Mar 2022 13:59:35 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1351985AbiCUSGh (ORCPT + 99 others); Mon, 21 Mar 2022 14:06:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60780 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1351980AbiCUSGd (ORCPT ); Mon, 21 Mar 2022 14:06:33 -0400 Received: from mail-pf1-x42b.google.com (mail-pf1-x42b.google.com [IPv6:2607:f8b0:4864:20::42b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AC4C015CB6D for ; Mon, 21 Mar 2022 11:05:07 -0700 (PDT) Received: by mail-pf1-x42b.google.com with SMTP id z16so16185128pfh.3 for ; Mon, 21 Mar 2022 11:05:07 -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=VSE/zjzMF4GUAODi9hUWbSKALcdRpi7FbYvoQ5n/zHE=; b=fcyAfSP5auLlxa8uxnRYod/EMf7JE1qAALckx8tRF9JKQppHhU9QysjLogLKyxYU6a 2R0dvGNpSM3MjBR8fOWEDbotvhLJ42Pxjh1OR471p6ss5wu8DTreSiar/deSJfqS5Bz0 ZJrDvhsTfX+rv0DePsGh8eO9zBQS5Q1E1B9m1Dl2X5V7XOPM9zbO8xspgoNJrJraHldJ 0/lC1CNncq0xlOpMy1ldeuil3tJ8rYv0pzU/bwMTuDCOBr8j27BAiw2yTlVByaNLzcAH MBY/ZTGVla0e3oHRwwiI3404xKCORRZ7UC0HAgiiacCLYjqVGDFCnIPNgeysH1TGdgfN R6lg== 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=VSE/zjzMF4GUAODi9hUWbSKALcdRpi7FbYvoQ5n/zHE=; b=ZpfmML6g/mh2DhCejk0y/rEVZFcJMwCWNLht8b3cgNXQ2kS4nWNfxl047rhDhWVCoF Z1Z69U2qoqoV5tL7l5ZnmngySCLjEfJ9CRzBoxtH1dB8CBR+JxMqixNF2luS82a1Ad/W oTdKDQQNooZcJLoMYGPU45oBkvTA6rBYQnSpudzLNOSq2AVcbRolLAzPL2rnASzpKbHd Vgejidnw+lgKQaknbJ75GpNOnRe+MkPaRjac1ddvssxh7+o8jYtV5PKFB3UtaLHxOvFy fcBUOrSoCdRbvyQEvd4V7XaauoalCcLWvBVYuEBJPMPnkARngxnCuLh7UHjJ8Zey/uO4 dRgA== X-Gm-Message-State: AOAM531c58B38ZlBLZtKcSi4H3kikQNTRuPWMnFOLSrqwfQ1O9Oz2oT7 ACGe9RgBrM/jMP5bLZyCn5d89Fu1p47A/HRk+/pf X-Received: by 2002:a63:1613:0:b0:382:2a7f:5ca1 with SMTP id w19-20020a631613000000b003822a7f5ca1mr13980696pgl.151.1647885906868; Mon, 21 Mar 2022 11:05:06 -0700 (PDT) MIME-Version: 1.0 References: <20220316213055.2351342-1-morbo@google.com> <20220319222228.4160598-1-morbo@google.com> In-Reply-To: From: Bill Wendling Date: Mon, 21 Mar 2022 11:04:55 -0700 Message-ID: Subject: Re: [PATCH v2] gpiolib: acpi: use correct format characters To: Linus Torvalds Cc: Mika Westerberg , Andy Shevchenko , Linus Walleij , Bartosz Golaszewski , Nathan Chancellor , Nick Desaulniers , "open list:GPIO SUBSYSTEM" , ACPI Devel Maling List , Linux Kernel Mailing List , llvm@lists.linux.dev 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 On Sat, Mar 19, 2022 at 3:55 PM Linus Torvalds wrote: > > So I think that clang warning is only annoying, not helpful, but: > > On Sat, Mar 19, 2022 at 3:22 PM Bill Wendling wrote: > > > > diff --git a/drivers/gpio/gpiolib-acpi.c b/drivers/gpio/gpiolib-acpi.c > > index a5495ad31c9c..92dd9b8784f2 100644 > > --- a/drivers/gpio/gpiolib-acpi.c > > +++ b/drivers/gpio/gpiolib-acpi.c > > @@ -388,9 +388,9 @@ static acpi_status acpi_gpiochip_alloc_event(struct acpi_resource *ares, > > > > if (pin <= 255) { > > char ev_name[5]; > > - sprintf(ev_name, "_%c%02hhX", > > + sprintf(ev_name, "_%c%02X", > > This part I approve of. > > > agpio->triggering == ACPI_EDGE_SENSITIVE ? 'E' : 'L', > > - pin); > > + (unsigned char)pin); > > But this cast seems pointless and wrong. > You're right. I was trying to ensure that the patch didn't change behavior. But the cast achieves nothing. Thanks! -bw > Casts in general are bad, and should be avoided unless there's a real > reason for them. And that reason doesn't seem to exist. We don't > actually want to truncate the value of 'pin', and just a few lines > earlier actually checked that it is in range. > > And if 'pin' can't be negative - it comes from a 'u16' table > dereference - but even if it could have been that would have been a > different bug here anyway (and should have been fixed by tightening > the check). > > So the cast doesn't add anything - not for humans, and not for a > compiler that could just optimize it away because it saw the range > check. > > End result: just fix the pointless 'hh' in the print specifier. It > doesn't add anything, and only causes problems. Anybody who uses '%02X > to print a byte should only use it for byte values - and the code > already does. > > Of course, the _reason_ for this all was a warning that was pointless > to begin with, and should never have existed. Clang was not smart > enough to take the range knowledge that it _could_ have taken into > account, and instead wrote out a completely bogus warning. > > It's completely bogus not just because clang didn't do a sufficiently > good job of range analysis - it's completely bogus because a 'varargs' > function DOES NOT TAKE arguments of type 'char'. > > So the *only* reason to use '%hhX' in the first place is that you > *want* the sprintf() to actually limit the value to a byte for you > (possibly because you have a signed char, know it will sign-extend to > 'int', and want to limit it back to 8 bits). > > If you *actually* had a 'unsigned char' to begin with, you'd be > completely insane to use %hhX. It's just pointless. > > So warning that '%hhX' is paired with an 'int' is all just completely > mindless and wrong. > > Linus