Received: by 2002:a05:7412:d8a:b0:e2:908c:2ebd with SMTP id b10csp134854rdg; Thu, 12 Oct 2023 00:36:52 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFHwtBceIc7GvFViiaQnNJXnWn8hkuLa/Fkrxo5jMC985jhRFtqj6WpY1gyUZrYThvCiBGd X-Received: by 2002:a17:903:110f:b0:1bb:f1d9:432e with SMTP id n15-20020a170903110f00b001bbf1d9432emr24475140plh.37.1697096212506; Thu, 12 Oct 2023 00:36:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697096212; cv=none; d=google.com; s=arc-20160816; b=O3LcpDwZr6A6BZek+cjTiNcTYB1r/qrqMhELTHYpFVIKs6+ygNrg6eN03IA3QjtzQO BpMNwvum2KdRZLZ5PKUCyyT6zTUl6GMpU/+ZfoEQx9+YfONwOJg+8tPwMsvJlgQQTSlj BUGF0K/oNN4FJbFHtXXD+Pjr2gTHnij6ysfWFMvWqXDcuYVAJAijdA/zi7p2fUts0FdN aS6ajUXDsbCWf8PXfw3ZF4dAMEvNc0QgSvdqPLHflbpmKceWCyZCnhTy7XrpizzRMqEy su7llXOy0A/uiPgKkU+F5FxaIhgGJxGa11kItw3lzSIAHFuAUGb3BHWNgOw+vqdEsO4p 7rcg== 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 :references:in-reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=1c+04dPNd0cx0mm93nWOErbG2Y2fVEp78ujIvGWP9AI=; fh=wqokEBkALSmdiuZf9ERHRqYvlha8PZMWDnvdueFIhNA=; b=dBPpYtANMELF0IFcf2GtfWkiBlpFdPkCFSytw0+/P/8S4fysQIlKa5rFlkCQsAeFrd H9OJVrYwPorRmmTtO4WroKvCAzTjnq4Cp0bNm9NsAH0eyT1txCvkzh3lMZ7r10IZ442Q PzsPuDkoEioLBPo/AxuWeVXABj+7HCGHhr/Fy6ouUQIQ5cAUqA01kXN/OIjVxPdNzxX9 b4Bf02wA/rxSwwiYDRoWzb+ONCBAy0Mz3wf+qd+m2VN5vDY9LD0tPxAPZq8ShxONMYMa AT1eRsczgWEKIu73rix9p2sS5yaewTHbAXAlrkEmFJJbMhIP7Avkv9rAkth3gVWsAAIP ZCWg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=JxRguLzS; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id 12-20020a170902c20c00b001c5f15d24ffsi1535999pll.116.2023.10.12.00.36.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Oct 2023 00:36:52 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=JxRguLzS; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id B4C488206D68; Thu, 12 Oct 2023 00:36:14 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1377335AbjJLHgA (ORCPT + 99 others); Thu, 12 Oct 2023 03:36:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56478 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232199AbjJLHf7 (ORCPT ); Thu, 12 Oct 2023 03:35:59 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 73EB290; Thu, 12 Oct 2023 00:35:57 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 09031C433C8; Thu, 12 Oct 2023 07:35:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1697096157; bh=vtUjYzbh3ksyEdtvSfgyPNGccq8OhGyaDiH5w29dMb4=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=JxRguLzShyfjqtscKFYcmXK4uKSohmdngtg0iVJbqrgODN+jrrlJJ8h16r9weMO4Y UIfefhoNYPiDLQv91cs6cFFgYbEXyduuTkmrQ/MM4tY3NKdoeXHe58Dd3IB4Dx90oG FNCnVVi24NKh9+3N2YIrNY52llaOSpiyqq1wSSu36lHKuDfzoMu+PJodjRi63B4buw 8qUCzocG0yZ717WL2r+3BXyabetdTsEmr80ngL37VcgdpXSnS8mlSXRfZpmm2F4P3P b2d1IWozt94EdWGjhcMrE/ESHiAsMttxtLaxgY4xIgiFybuKrRVRvF9eNog3iuFQ8/ 6dI7V9fCi3pMQ== Date: Thu, 12 Oct 2023 08:36:10 +0100 From: Jonathan Cameron To: Cc: , , , , Subject: Re: [PATCH v1] iio: adc: MCP3564: fix warn: unsigned '__x' is never less than zero. Message-ID: <20231012083610.742cc74c@jic23-huawei> In-Reply-To: References: <20231002161618.36373-1-marius.cristea@microchip.com> <20231010104444.12e61984@jic23-huawei> X-Mailer: Claws Mail 4.1.1 (GTK 3.24.38; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, 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 X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Thu, 12 Oct 2023 00:36:14 -0700 (PDT) On Wed, 11 Oct 2023 16:41:38 +0000 wrote: > Hi Jonathan, >=20 > Sorry, I think I've made a "mistake" related to naming the patches and > also not running the Smatch checker at a point in time. >=20 >=20 >=20 > On Tue, 2023-10-10 at 10:44 +0100, Jonathan Cameron wrote: > > EXTERNAL EMAIL: Do not click links or open attachments unless you > > know the content is safe > >=20 > > On Mon, 2 Oct 2023 19:16:18 +0300 > > wrote: > > =20 > > > From: Marius Cristea > > >=20 > > > The patch efea15e3c65d: "iio: adc: MCP3564: fix the static checker > > > warning" > > > leads to the following Smatch static checker warning: > > >=20 > > > =C2=A0=C2=A0 smatch warnings: > > > =C2=A0=C2=A0 drivers/iio/adc/mcp3564.c:1105 mcp3564_fill_scale_tbls()= warn: > > > unsigned '__x' is never less than zero. > > >=20 > > > vim +/__x +1105 drivers/iio/adc/mcp3564.c > > >=20 > > > =C2=A0=C2=A0 1094 > > > =C2=A0=C2=A0 1095=C2=A0 static void mcp3564_fill_scale_tbls(struct mc= p3564_state > > > *adc) > > > =C2=A0=C2=A0 1096=C2=A0 { > > > =C2=A0=C2=A0 ..... > > > =C2=A0=C2=A0 1103=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0 for (i =3D 0; i < MCP3564_MAX_PGA; i++) { > > > =C2=A0=C2=A0 1104=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 ref =3D adc->vref_mv; = =20 > > > =C2=A0> 1105=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 tmp1 =3D shift_right((u64)ref= * NANO, pow); =20 > > > =C2=A0=C2=A0 1106=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 div_u64_rem(tmp1, NANO,= &tmp0); > > > =C2=A0=C2=A0 1107 > > > =C2=A0=C2=A0 ..... > > > =C2=A0=C2=A0 1113=C2=A0 } > > >=20 > > > Reported-by: kernel test robot > > > Closes: > > > https://lore.kernel.org/oe-kbuild-all/202309280738.NWjVfVt4-lkp@intel= .com/ > > > Fixes: efea15e3c65d (iio: adc: MCP3564: fix the static checker > > > warning) =20 > >=20 > > This fix is fine but can you talk me through how the static checker > > warning fix > > in question has anything to do with this one? > >=20 > > Was it just a case of fixing that issue allowing the static checker > > to > > get further before giving up?=C2=A0 In which case the description needs > > modifying. > >=20 > > Or am I missing something in the following fix? > >=20 > > diff --git a/drivers/iio/adc/mcp3564.c b/drivers/iio/adc/mcp3564.c > > index 64145f4ae55c..9ede1a5d5d7b 100644 > > --- a/drivers/iio/adc/mcp3564.c > > +++ b/drivers/iio/adc/mcp3564.c > > @@ -1422,11 +1422,8 @@ static int mcp3564_probe(struct spi_device > > *spi) > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 struct mcp3564_state *adc; > >=20 > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 indio_dev =3D devm_iio_devic= e_alloc(&spi->dev, sizeof(*adc)); > > -=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 if (!indio_dev) { > > -=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0 dev_err_probe(&indio_dev->dev, PTR_ERR(indio_dev), > > -=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0 "Can't allocate iio device\n"); > > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 if (!indio_dev) > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0 return -ENOMEM; > > -=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 } > >=20 > > =20 >=20 > I've got two bugs reported: >=20 > - The first one was reported by Dan Carpenter "Re: [bug report] iio: > adc: adding support for MCP3564 ADC". This bug was found using the > "Smatch static checker warning" and it was related to: > > --> 1426 dev_err_probe(&indio_dev->dev, =20 > PTR_ERR(indio_dev), >=20 > This bug was fixed by the above "[PATCH v1] iio: adc: MCP3564: fix the > static checker warning" and it was applied on "Applied to the togreg > branch of iio.git as that's where this driver is at the moment." >=20 > Also my mistake at this point was that I didn't setup and run the > "Smatch static checker warning" >=20 >=20 > > as that's all I'm seeing in that commit. > > =20 > Yes, that commit only handled part of the fix. >=20 >=20 >=20 > > > Signed-off-by: Marius Cristea > > > --- > > > =C2=A0drivers/iio/adc/mcp3564.c | 2 +- > > > =C2=A01 file changed, 1 insertion(+), 1 deletion(-) > > >=20 > > > diff --git a/drivers/iio/adc/mcp3564.c b/drivers/iio/adc/mcp3564.c > > > index 9ede1a5d5d7b..e3f1de5fcc5a 100644 > > > --- a/drivers/iio/adc/mcp3564.c > > > +++ b/drivers/iio/adc/mcp3564.c > > > @@ -1102,7 +1102,7 @@ static void mcp3564_fill_scale_tbls(struct > > > mcp3564_state *adc) > > >=20 > > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 for (i =3D 0; i < MCP3564_MAX_PGA; i++= ) { > > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0 ref =3D adc->vref_mv; > > > -=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0 tmp1 =3D shift_right((u64)ref * NANO, pow); > > > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0 tmp1 =3D ((u64)ref * NANO) >> pow; > > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0 div_u64_rem(tmp1, NANO, &tmp0); > > >=20 > > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0 tmp1 =3D tmp1 * mcp3564_hwgain_frac[(2 * i) + 1]; > > >=20 > > > base-commit: 5e99f692d4e32e3250ab18d511894ca797407aec =20 > > =20 >=20 > - The second bug was reported by "kernel test robot " > also by running Smatch and it was run on the initial driver (without > having the first patch applied) >=20 > smatch warnings: > drivers/iio/adc/mcp3564.c:1105 mcp3564_fill_scale_tbls() warn: unsigned > '__x' is never less than zero. > drivers/iio/adc/mcp3564.c:1426 mcp3564_probe() warn: passing zero to > 'PTR_ERR' > drivers/iio/adc/mcp3564.c:1426 mcp3564_probe() warn: address of NULL > pointer 'indio_dev' >=20 >=20 > The:"drivers/iio/adc/mcp3564.c:1426 mcp3564_probe() warn: passing zero > to 'PTR_ERR'" and "drivers/iio/adc/mcp3564.c:1426 mcp3564_probe() warn: > address of NULL pointer 'indio_dev'" were fixed by the first patch. >=20 > The "drivers/iio/adc/mcp3564.c:1105 mcp3564_fill_scale_tbls() warn: > unsigned '__x' is never less than zero." is fixed by the last patch > "[PATCH v1] iio: adc: MCP3564: fix warn: unsigned '__x' is never less > than zero." > by changeing: >=20 > - tmp1 =3D shift_right((u64)ref * NANO, pow); > + tmp1 =3D ((u64)ref * NANO) >> pow; >=20 > shift_right function is "Required to safely shift negative values" but > my value is always unsigned so it doesn't make sense to used it. This > error was reported when I have run the Smatch over the driver + first > patch (what was the latest from togreg). >=20 > I have applied the patch on top of what was the "latest" from togreg > branch and not on the initial driver. >=20 >=20 > I could change the description or I could provide a patch to handle > both warning reporting at once. If there are multiple issues then should be multiple patches. So starting point is definitely a version of this one with the correct description. Thanks, Jonathan >=20 > Thanks, > Marius