Received: by 2002:a05:6358:16cc:b0:ea:6187:17c9 with SMTP id r12csp642276rwl; Sun, 25 Dec 2022 04:30:12 -0800 (PST) X-Google-Smtp-Source: AMrXdXv4G6bbxQiTLZ4VQh3wwnnMrg/8n5c4VzmijobagBUrU9IiQ/x1tYqhTmDADbFvkd3tc/yT X-Received: by 2002:a17:902:c404:b0:192:5eee:323a with SMTP id k4-20020a170902c40400b001925eee323amr13594021plk.28.1671971411873; Sun, 25 Dec 2022 04:30:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1671971411; cv=none; d=google.com; s=arc-20160816; b=Mb1KGKslaB6ubuh4IBNxq8kRu2AH/a90MN0FEYyuxuBaISdxawVLDRcQ1ua1IMv8U6 YIc1BsoL7d1fs0gnIZpcI0DL9Ac+sTo21cfRR9pQ+3NyEKG2sF7Ctn+KQoFu6KEbg/gW 7zT87LynZ4OGWlp5g9I8dO8fKF5xn1AEXXfWWaxn32Dg3F2bdW79ljVXGGo0smDz6tn5 CiqAJ4dIdLU0J8DoKVC2Onwwfyl4jEuIPs5NCs4gDckbUOL8Kptacfb2LZlO6TN55RUU wtRLhNzbZqVF3uoCWcAn84b483/D8kv/e1f3A9zsT7i0wVouA2BigMMkHugBpasznlYY BJAg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:to:references:message-id :content-transfer-encoding:cc:date:in-reply-to:from:subject :mime-version:dkim-signature; bh=AlnLyJ2BHwOq0v6YM5eXS65npGm8qINlxvZC0I9lVgQ=; b=xtbK/es+HRvcfc5ZumNXeRyU+0eGM+vpwB4fEEFg+oFNdrh45HSKNhlRcxxJBaXnQw JzZ01JCglASusLyR9ZhmDQLiqaf+lr9ai+DLRx68BGawhq6qwfwkVp/s1FJNFHnsWdZd 2jMQlJdsOb9H2PiTTUB0sQCVSq3MO73y2s8qepJnU59mYavOjq9KNrOKBXoB8PqlfOYD jQr6jNqkiUCKKLElAV2r7lMTU8ngtiSsAyquUDlfRDuKrDwWsUJKJGJvKCcvBCbkrbNU qeS40/0P4LVJBG0L/iDxAkLWewn1z0UV1YRwROFWMnIUgmD1SG/INasNXrd3BmdVuS3W sLZA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=KOqteYkK; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b11-20020a170903228b00b00188bee6e9f2si9136553plh.239.2022.12.25.04.30.01; Sun, 25 Dec 2022 04:30:11 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=KOqteYkK; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229895AbiLYLvD (ORCPT + 66 others); Sun, 25 Dec 2022 06:51:03 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47450 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229631AbiLYLu6 (ORCPT ); Sun, 25 Dec 2022 06:50:58 -0500 Received: from mail-lj1-x233.google.com (mail-lj1-x233.google.com [IPv6:2a00:1450:4864:20::233]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C6EA4B3E for ; Sun, 25 Dec 2022 03:50:52 -0800 (PST) Received: by mail-lj1-x233.google.com with SMTP id s22so9351368ljp.5 for ; Sun, 25 Dec 2022 03:50:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=AlnLyJ2BHwOq0v6YM5eXS65npGm8qINlxvZC0I9lVgQ=; b=KOqteYkKtgJyR7TLsHd/wtr0yFSNfCI7LJtbi9Wlvv5KF6a0t/eXNn1I7Roio0Scku zNS2DGEaTz8AGBPLyxNItIrD8GNHNd0DlMWT74LWYXLYXVycJOljbXNDdj9LkpjVgrlr AuWUuhzEas2Y1VMrEgLemv5neOV+jEkICHzacQ7nYrTx8pN61PMr41cSQY7iq3mNjaxn qg91Dl4xt7E/+E7VL/mNEYIQIo7AVoG+4MoA5pD09aLogjvZdqFj1C/9JtMUyZvuym1T L56tniLHtEPckCPXgBMqzCp6qWO096my1InWmhbPOfsO2AuyCIEOV3232g//OfmPzhHr YMwA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=AlnLyJ2BHwOq0v6YM5eXS65npGm8qINlxvZC0I9lVgQ=; b=qOqLOip2pn6d76IQtCpvpRPhlKuwTJIo3XGn9bOI6HyvblUAmaZ1vzK00/evcyKhZ1 9aynU/NF/cicY2iLX6uypTzRceIN4yj7qt2BoGopvWFWIGUcasuAUOzHF3Mv7myoAAAK /P9qnHd8M8z22NNPPpm7ElN37eoaWcAoEy0IdAizpAJD307Ajublbr7VtsUU1L3uBuWt ZWKJWNvJpbLwrCo+i8Xf7vAPtyDGlWqXk2kxR0dPTdq3W2E3tHk/Y7mPk7IDubiUwt9t BpYgHhk9nDkgm8DzII8T07LF2QxedQDBraidZcFZ/jjm/R0OBEoG/BUS4zyyijTVbSno RhEw== X-Gm-Message-State: AFqh2kqCmBZAZuSIH2hHY8H/aKwPT9qN07mgN3jqpSuWA+qXWRGUl9I6 gYS+YCI3SCpH5KBZq0IooAyo4B/uThCp+Q== X-Received: by 2002:a2e:8244:0:b0:276:dc01:8058 with SMTP id j4-20020a2e8244000000b00276dc018058mr4260997ljh.1.1671969050971; Sun, 25 Dec 2022 03:50:50 -0800 (PST) Received: from [10.0.207.73] ([185.32.8.213]) by smtp.gmail.com with ESMTPSA id bj31-20020a2eaa9f000000b0027facd123a0sm959608ljb.106.2022.12.25.03.50.49 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sun, 25 Dec 2022 03:50:49 -0800 (PST) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (1.0) Subject: Re: drivers/gpio/gpio-exar.c:52 exar_offset_to_sel_addr() warn: replace divide condition 'pin / 8' with 'pin >= 8' From: Andy Shevchenko X-Mailer: iPhone Mail (16H71) In-Reply-To: Date: Sun, 25 Dec 2022 12:50:46 +0100 Cc: oe-kbuild@lists.linux.dev, Qingtao Cao , lkp@intel.com, oe-kbuild-all@lists.linux.dev, linux-kernel@vger.kernel.org, Bartosz Golaszewski Content-Transfer-Encoding: quoted-printable Message-Id: References: <202212181140.EAWl7FKx-lkp@intel.com> <3D147284-AF8C-4414-9BE1-C83032B6C15D@gmail.com> To: Dan Carpenter X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=ham 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 L=C3=A4hetetty iPhonesta > Andy Shevchenko kirjoitti 25.12.2022 kello 12.= 45: >=20 >=20 >=20 > L=C3=A4hetetty iPhonesta >=20 >>> Dan Carpenter kirjoitti 24.12.2022 kello 20.30: >>>=20 >>> On Sat, Dec 24, 2022 at 05:19:27PM +0100, Andy Shevchenko wrote: >>>=20 >>>=20 >>> L=C3=A4hetetty iPhonesta >>>=20 >>>> Dan Carpenter kirjoitti 23.12.2022 kello 11.54: >>>>=20 >>>> tree: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.= git master >>>> head: f9ff5644bcc04221bae56f922122f2b7f5d24d62 >>>> commit: 5134272f9f3f71d4e1f3aa15cb09321af49b3646 gpio: exar: access MPI= O registers on cascaded chips >>>> config: ia64-randconfig-m031-20221218 >>>> compiler: ia64-linux-gcc (GCC) 12.1.0 >>>>=20 >>>> If you fix the issue, kindly add following tag where applicable >>>> | Reported-by: kernel test robot >>>> | Reported-by: Dan Carpenter >>>>=20 >>>> smatch warnings: >>>> drivers/gpio/gpio-exar.c:52 exar_offset_to_sel_addr() warn: replace div= ide condition 'pin / 8' with 'pin >=3D 8' >>>> drivers/gpio/gpio-exar.c:62 exar_offset_to_lvl_addr() warn: replace div= ide condition 'pin / 8' with 'pin >=3D 8' >>>>=20 >>>=20 >>>=20 >>>=20 >>> I don=E2=80=99t think this is a good advice. If we want to limit that, w= e need >>> to check also upper limit. But. The GPIO framework does that. So, >>> changing / to >=3D is bogus. >>=20 >>=20 >> How is checking pin / 8 not mathematically equivalent to pin >=3D 8? >=20 > The point is that semantically the / is better in case this code will ever= support more than two banks of pins. On top of that it=E2=80=99s paired with pin % 8. >=20 >> I don't understand this code at all. The divide is inscrutable Is it >> storing something in in the lower 3 bits and something in bit 4? In >> that case it might be nicer to just check (pin & BIT(4)). >>=20 >> regards, >> dan carpenter >>=20 >>>=20 >>>=20 >>>> vim +52 drivers/gpio/gpio-exar.c >>>>=20 >>>> 696868d0a79c21 Bartosz Golaszewski 2020-09-30 47 static unsigned int >>>> 696868d0a79c21 Bartosz Golaszewski 2020-09-30 48 exar_offset_to_sel_a= ddr(struct exar_gpio_chip *exar_gpio, unsigned int offset) >>>> 696868d0a79c21 Bartosz Golaszewski 2020-09-30 49 { >>>> 5134272f9f3f71 Qingtao Cao 2022-09-02 50 unsigned int pin= =3D exar_gpio->first_pin + (offset % 16); >>>> 5134272f9f3f71 Qingtao Cao 2022-09-02 51 unsigned int cas= caded =3D offset / 16; >>>> 5134272f9f3f71 Qingtao Cao 2022-09-02 @52 unsigned int add= r =3D pin / 8 ? EXAR_OFFSET_MPIOSEL_HI : EXAR_OFFSET_MPIOSEL_LO; >>>>=20 >>>> Why not change this to pin > 8 instead. Comparisons are faster than >>>> divide ops. Way more readable too. >>>>=20 >>>> 5134272f9f3f71 Qingtao Cao 2022-09-02 53 =20 >>>> 5134272f9f3f71 Qingtao Cao 2022-09-02 54 return addr + (c= ascaded ? exar_gpio->cascaded_offset : 0); >>>> 696868d0a79c21 Bartosz Golaszewski 2020-09-30 55 } >>>> 696868d0a79c21 Bartosz Golaszewski 2020-09-30 56 =20 >>>> 696868d0a79c21 Bartosz Golaszewski 2020-09-30 57 static unsigned int >>>> 696868d0a79c21 Bartosz Golaszewski 2020-09-30 58 exar_offset_to_lvl_a= ddr(struct exar_gpio_chip *exar_gpio, unsigned int offset) >>>> 696868d0a79c21 Bartosz Golaszewski 2020-09-30 59 { >>>> 5134272f9f3f71 Qingtao Cao 2022-09-02 60 unsigned int pin= =3D exar_gpio->first_pin + (offset % 16); >>>> 5134272f9f3f71 Qingtao Cao 2022-09-02 61 unsigned int cas= caded =3D offset / 16; >>>> 5134272f9f3f71 Qingtao Cao 2022-09-02 @62 unsigned int add= r =3D pin / 8 ? EXAR_OFFSET_MPIOLVL_HI : EXAR_OFFSET_MPIOLVL_LO; >>>> 5134272f9f3f71 Qingtao Cao 2022-09-02 63 =20 >>>> 5134272f9f3f71 Qingtao Cao 2022-09-02 64 return addr + (c= ascaded ? exar_gpio->cascaded_offset : 0); >>>> 696868d0a79c21 Bartosz Golaszewski 2020-09-30 65 } >>>>=20 >>>> --=20 >>>> 0-DAY CI Kernel Test Service >>>> https://01.org/lkp >>>>=20