Message ID | 20231002161618.36373-1-marius.cristea@microchip.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2a8e:b0:403:3b70:6f57 with SMTP id in14csp1609336vqb; Mon, 2 Oct 2023 11:20:40 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFMbRDD/oTzrJ9vw5JhcKVAJKdBb/FAJYltAi7OMBQxOSlKyJUDcfVWyj00e11yNgZ1H1hB X-Received: by 2002:a05:6358:949d:b0:145:63e6:8710 with SMTP id i29-20020a056358949d00b0014563e68710mr15164740rwb.23.1696270839935; Mon, 02 Oct 2023 11:20:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696270839; cv=none; d=google.com; s=arc-20160816; b=mtyTgN3MYeiffdegqa+IdqAGBbR+58twExxklCwYUPnlta55E8w2lkgy4fiUUIgoRr 2hdywqN0YkCW71c1mLOyOMa6VpbR0ywfOagm6mQwx3ezsvvRqSWcZxXee5lSZqMyYjrb aX/YS6H45wtoXMcBHiflXJdDQ6Y4UT+OQ4XgnW+i8gfr7NA6HfYHcReoUY/9rgwCZE1z Kg1yug0d6+2x7ueFg8rKDZ9WSvWPSZIvqOzBqNZeJSrQHejoM4qaMnvuh472cpi2ekmg ZhR9qwkhbnTCMFq4lxt4nIzKStQoPSZm228WZv8xnsm03DtrE3bnUkqLq9q+TGH6J3XG BfYw== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=C79CIhIy0nXoXIzrm7gnrZ24ZRyaYzQAxnTvfUvX5BU=; fh=OahkkZGRMsx/QsvTzHLvmCoK5Fz3HImW7eii1n0wrVw=; b=k5WCg4QhDn8S5bobN0mmgct3J7WVIc/cb6l9PCEsWwq1OUEBVm8eoUtYnWm7e9NXc3 IYSRR4o2DwwitNn4uirFBXPFbol6jMPS4N06kr2SMZiK23XIoUy5SJBFahPpKu1oN5WM caGm4jIsvxL6mNfBxhLAfavALdasVkicaevf2Px79LufvVHqUQOXKb2G8HH5nUBiCDiq QqTC0N5ZTttiTLWjMxhfDU00luo5s4xHig5GoQ2frMebdr+lITZny7mYowBO+S/7KdkQ rYSRzPDM2EmN1vA5hSxAukBCaCflf2qg2dMDVDX8K5MN50jgBk0JfElGpe1uYFOTrkm/ 3feQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@microchip.com header.s=mchp header.b="lu8FI5Q/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=microchip.com Received: from agentk.vger.email (agentk.vger.email. [23.128.96.32]) by mx.google.com with ESMTPS id 126-20020a630284000000b00565f611a1f8si26523933pgc.263.2023.10.02.11.20.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Oct 2023 11:20:39 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) client-ip=23.128.96.32; Authentication-Results: mx.google.com; dkim=pass header.i=@microchip.com header.s=mchp header.b="lu8FI5Q/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=microchip.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id 14D3A80BD392; Mon, 2 Oct 2023 09:17:07 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238446AbjJBQQg (ORCPT <rfc822;pusanteemu@gmail.com> + 18 others); Mon, 2 Oct 2023 12:16:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37816 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238488AbjJBQQc (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Mon, 2 Oct 2023 12:16:32 -0400 Received: from esa.microchip.iphmx.com (esa.microchip.iphmx.com [68.232.153.233]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C63889E; Mon, 2 Oct 2023 09:16:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=microchip.com; i=@microchip.com; q=dns/txt; s=mchp; t=1696263389; x=1727799389; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=DPrZPdYeRNfXZOtbRB8PnTVno3GzcqOBQS4+4QktUg4=; b=lu8FI5Q/DBu+DUAfA7dIG6R/munxfToM5VLF8zyz56uM6I/YVxSaGXSG s/dFBKkd4CxsjMputLBUnB+2DZHClgj/5zWvbYJtXLZ1hm5rj0vRz7w/q W28497nGRh4RMwpO2C6E5hBolRIDNVJY1WGAv2DtiN7TuPI1YH2IXWan9 jBle+S1ccjNcXa1sDfthA1KpWwZuXXbEVEKrX8kY6ftBZSBaUZoqBYNVx UAorNKaOyZPbJOUK1KUUjeJNq+PM+v3OLoHJXrkcsDiDUp7iOdF0K1AYg ljYlkw3CK7IxeVPRXXd4ZwdqdGs4/Nu/2n3Xsu4j7lo3gxnvk58QTEnMo Q==; X-CSE-ConnectionGUID: M5MHFYEZQ66VfybJvKr2SQ== X-CSE-MsgGUID: yuxl+01OQCaK38yX3xDJQg== X-ThreatScanner-Verdict: Negative X-IronPort-AV: E=Sophos;i="6.03,194,1694761200"; d="scan'208";a="7940525" X-Amp-Result: SKIPPED(no attachment in message) Received: from unknown (HELO email.microchip.com) ([170.129.1.10]) by esa1.microchip.iphmx.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 02 Oct 2023 09:16:29 -0700 Received: from chn-vm-ex01.mchp-main.com (10.10.85.143) by chn-vm-ex01.mchp-main.com (10.10.85.143) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.21; Mon, 2 Oct 2023 09:16:28 -0700 Received: from marius-VM.mshome.net (10.10.85.11) by chn-vm-ex01.mchp-main.com (10.10.85.143) with Microsoft SMTP Server id 15.1.2507.21 via Frontend Transport; Mon, 2 Oct 2023 09:16:27 -0700 From: <marius.cristea@microchip.com> To: <jic23@kernel.org>, <lars@metafoo.de>, <lgirdwood@gmail.com>, <broonie@kernel.org> CC: <linux-iio@vger.kernel.org>, <linux-kernel@vger.kernel.org>, <marius.cristea@microchip.com> Subject: [PATCH v1] iio: adc: MCP3564: fix warn: unsigned '__x' is never less than zero. Date: Mon, 2 Oct 2023 19:16:18 +0300 Message-ID: <20231002161618.36373-1-marius.cristea@microchip.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (agentk.vger.email [0.0.0.0]); Mon, 02 Oct 2023 09:17:07 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1778668892328580466 X-GMAIL-MSGID: 1778668892328580466 |
Series |
[v1] iio: adc: MCP3564: fix warn: unsigned '__x' is never less than zero.
|
|
Commit Message
marius.cristea@microchip.com
Oct. 2, 2023, 4:16 p.m. UTC
From: Marius Cristea <marius.cristea@microchip.com> The patch efea15e3c65d: "iio: adc: MCP3564: fix the static checker warning" leads to the following Smatch static checker warning: smatch warnings: drivers/iio/adc/mcp3564.c:1105 mcp3564_fill_scale_tbls() warn: unsigned '__x' is never less than zero. vim +/__x +1105 drivers/iio/adc/mcp3564.c 1094 1095 static void mcp3564_fill_scale_tbls(struct mcp3564_state *adc) 1096 { ..... 1103 for (i = 0; i < MCP3564_MAX_PGA; i++) { 1104 ref = adc->vref_mv; > 1105 tmp1 = shift_right((u64)ref * NANO, pow); 1106 div_u64_rem(tmp1, NANO, &tmp0); 1107 ..... 1113 } Reported-by: kernel test robot <lkp@intel.com> Closes: https://lore.kernel.org/oe-kbuild-all/202309280738.NWjVfVt4-lkp@intel.com/ Fixes: efea15e3c65d (iio: adc: MCP3564: fix the static checker warning) Signed-off-by: Marius Cristea <marius.cristea@microchip.com> --- drivers/iio/adc/mcp3564.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) base-commit: 5e99f692d4e32e3250ab18d511894ca797407aec
Comments
On Mon, 2 Oct 2023 19:16:18 +0300 <marius.cristea@microchip.com> wrote: > From: Marius Cristea <marius.cristea@microchip.com> > > The patch efea15e3c65d: "iio: adc: MCP3564: fix the static checker warning" > leads to the following Smatch static checker warning: > > smatch warnings: > drivers/iio/adc/mcp3564.c:1105 mcp3564_fill_scale_tbls() warn: unsigned '__x' is never less than zero. > > vim +/__x +1105 drivers/iio/adc/mcp3564.c > > 1094 > 1095 static void mcp3564_fill_scale_tbls(struct mcp3564_state *adc) > 1096 { > ..... > 1103 for (i = 0; i < MCP3564_MAX_PGA; i++) { > 1104 ref = adc->vref_mv; > > 1105 tmp1 = shift_right((u64)ref * NANO, pow); > 1106 div_u64_rem(tmp1, NANO, &tmp0); > 1107 > ..... > 1113 } > > Reported-by: kernel test robot <lkp@intel.com> > Closes: https://lore.kernel.org/oe-kbuild-all/202309280738.NWjVfVt4-lkp@intel.com/ > Fixes: efea15e3c65d (iio: adc: MCP3564: fix the static checker warning) 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? Was it just a case of fixing that issue allowing the static checker to get further before giving up? In which case the description needs modifying. Or am I missing something in the following fix? 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) struct mcp3564_state *adc; indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*adc)); - if (!indio_dev) { - dev_err_probe(&indio_dev->dev, PTR_ERR(indio_dev), - "Can't allocate iio device\n"); + if (!indio_dev) return -ENOMEM; - } as that's all I'm seeing in that commit. > Signed-off-by: Marius Cristea <marius.cristea@microchip.com> > --- > drivers/iio/adc/mcp3564.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > 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) > > for (i = 0; i < MCP3564_MAX_PGA; i++) { > ref = adc->vref_mv; > - tmp1 = shift_right((u64)ref * NANO, pow); > + tmp1 = ((u64)ref * NANO) >> pow; > div_u64_rem(tmp1, NANO, &tmp0); > > tmp1 = tmp1 * mcp3564_hwgain_frac[(2 * i) + 1]; > > base-commit: 5e99f692d4e32e3250ab18d511894ca797407aec
Hi Jonathan, 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. 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 > > On Mon, 2 Oct 2023 19:16:18 +0300 > <marius.cristea@microchip.com> wrote: > > > From: Marius Cristea <marius.cristea@microchip.com> > > > > The patch efea15e3c65d: "iio: adc: MCP3564: fix the static checker > > warning" > > leads to the following Smatch static checker warning: > > > > smatch warnings: > > drivers/iio/adc/mcp3564.c:1105 mcp3564_fill_scale_tbls() warn: > > unsigned '__x' is never less than zero. > > > > vim +/__x +1105 drivers/iio/adc/mcp3564.c > > > > 1094 > > 1095 static void mcp3564_fill_scale_tbls(struct mcp3564_state > > *adc) > > 1096 { > > ..... > > 1103 for (i = 0; i < MCP3564_MAX_PGA; i++) { > > 1104 ref = adc->vref_mv; > > > 1105 tmp1 = shift_right((u64)ref * NANO, pow); > > 1106 div_u64_rem(tmp1, NANO, &tmp0); > > 1107 > > ..... > > 1113 } > > > > Reported-by: kernel test robot <lkp@intel.com> > > Closes: > > https://lore.kernel.org/oe-kbuild-all/202309280738.NWjVfVt4-lkp@intel.com/ > > Fixes: efea15e3c65d (iio: adc: MCP3564: fix the static checker > > warning) > > 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? > > Was it just a case of fixing that issue allowing the static checker > to > get further before giving up? In which case the description needs > modifying. > > Or am I missing something in the following fix? > > 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) > struct mcp3564_state *adc; > > indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*adc)); > - if (!indio_dev) { > - dev_err_probe(&indio_dev->dev, PTR_ERR(indio_dev), > - "Can't allocate iio device\n"); > + if (!indio_dev) > return -ENOMEM; > - } > > I've got two bugs reported: - 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, PTR_ERR(indio_dev), 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." Also my mistake at this point was that I didn't setup and run the "Smatch static checker warning" > as that's all I'm seeing in that commit. > Yes, that commit only handled part of the fix. > > Signed-off-by: Marius Cristea <marius.cristea@microchip.com> > > --- > > drivers/iio/adc/mcp3564.c | 2 +- > > 1 file changed, 1 insertion(+), 1 deletion(-) > > > > 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) > > > > for (i = 0; i < MCP3564_MAX_PGA; i++) { > > ref = adc->vref_mv; > > - tmp1 = shift_right((u64)ref * NANO, pow); > > + tmp1 = ((u64)ref * NANO) >> pow; > > div_u64_rem(tmp1, NANO, &tmp0); > > > > tmp1 = tmp1 * mcp3564_hwgain_frac[(2 * i) + 1]; > > > > base-commit: 5e99f692d4e32e3250ab18d511894ca797407aec > - The second bug was reported by "kernel test robot <lkp@intel.com>" also by running Smatch and it was run on the initial driver (without having the first patch applied) 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' 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. 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: - tmp1 = shift_right((u64)ref * NANO, pow); + tmp1 = ((u64)ref * NANO) >> pow; 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). I have applied the patch on top of what was the "latest" from togreg branch and not on the initial driver. I could change the description or I could provide a patch to handle both warning reporting at once. Thanks, Marius
On Wed, 11 Oct 2023 16:41:38 +0000 <Marius.Cristea@microchip.com> wrote: > Hi Jonathan, > > 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. > > > > 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 > > > > On Mon, 2 Oct 2023 19:16:18 +0300 > > <marius.cristea@microchip.com> wrote: > > > > > From: Marius Cristea <marius.cristea@microchip.com> > > > > > > The patch efea15e3c65d: "iio: adc: MCP3564: fix the static checker > > > warning" > > > leads to the following Smatch static checker warning: > > > > > > smatch warnings: > > > drivers/iio/adc/mcp3564.c:1105 mcp3564_fill_scale_tbls() warn: > > > unsigned '__x' is never less than zero. > > > > > > vim +/__x +1105 drivers/iio/adc/mcp3564.c > > > > > > 1094 > > > 1095 static void mcp3564_fill_scale_tbls(struct mcp3564_state > > > *adc) > > > 1096 { > > > ..... > > > 1103 for (i = 0; i < MCP3564_MAX_PGA; i++) { > > > 1104 ref = adc->vref_mv; > > > > 1105 tmp1 = shift_right((u64)ref * NANO, pow); > > > 1106 div_u64_rem(tmp1, NANO, &tmp0); > > > 1107 > > > ..... > > > 1113 } > > > > > > Reported-by: kernel test robot <lkp@intel.com> > > > Closes: > > > https://lore.kernel.org/oe-kbuild-all/202309280738.NWjVfVt4-lkp@intel.com/ > > > Fixes: efea15e3c65d (iio: adc: MCP3564: fix the static checker > > > warning) > > > > 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? > > > > Was it just a case of fixing that issue allowing the static checker > > to > > get further before giving up? In which case the description needs > > modifying. > > > > Or am I missing something in the following fix? > > > > 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) > > struct mcp3564_state *adc; > > > > indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*adc)); > > - if (!indio_dev) { > > - dev_err_probe(&indio_dev->dev, PTR_ERR(indio_dev), > > - "Can't allocate iio device\n"); > > + if (!indio_dev) > > return -ENOMEM; > > - } > > > > > > I've got two bugs reported: > > - 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, > PTR_ERR(indio_dev), > > 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." > > Also my mistake at this point was that I didn't setup and run the > "Smatch static checker warning" > > > > as that's all I'm seeing in that commit. > > > Yes, that commit only handled part of the fix. > > > > > > Signed-off-by: Marius Cristea <marius.cristea@microchip.com> > > > --- > > > drivers/iio/adc/mcp3564.c | 2 +- > > > 1 file changed, 1 insertion(+), 1 deletion(-) > > > > > > 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) > > > > > > for (i = 0; i < MCP3564_MAX_PGA; i++) { > > > ref = adc->vref_mv; > > > - tmp1 = shift_right((u64)ref * NANO, pow); > > > + tmp1 = ((u64)ref * NANO) >> pow; > > > div_u64_rem(tmp1, NANO, &tmp0); > > > > > > tmp1 = tmp1 * mcp3564_hwgain_frac[(2 * i) + 1]; > > > > > > base-commit: 5e99f692d4e32e3250ab18d511894ca797407aec > > > > - The second bug was reported by "kernel test robot <lkp@intel.com>" > also by running Smatch and it was run on the initial driver (without > having the first patch applied) > > 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' > > > 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. > > 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: > > - tmp1 = shift_right((u64)ref * NANO, pow); > + tmp1 = ((u64)ref * NANO) >> pow; > > 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). > > I have applied the patch on top of what was the "latest" from togreg > branch and not on the initial driver. > > > 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 > > Thanks, > Marius
Hi Jonathan, On Thu, 2023-10-12 at 08:36 +0100, Jonathan Cameron wrote: > EXTERNAL EMAIL: Do not click links or open attachments unless you > know the content is safe > > On Wed, 11 Oct 2023 16:41:38 +0000 > <Marius.Cristea@microchip.com> wrote: > > > Hi Jonathan, > > > > 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. > > > > > > > > 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 > > > > > > On Mon, 2 Oct 2023 19:16:18 +0300 > > > <marius.cristea@microchip.com> wrote: > > > > > > > From: Marius Cristea <marius.cristea@microchip.com> > > > > > > > > The patch efea15e3c65d: "iio: adc: MCP3564: fix the static > > > > checker > > > > warning" > > > > leads to the following Smatch static checker warning: > > > > > > > > smatch warnings: > > > > drivers/iio/adc/mcp3564.c:1105 mcp3564_fill_scale_tbls() > > > > warn: > > > > unsigned '__x' is never less than zero. > > > > > > > > vim +/__x +1105 drivers/iio/adc/mcp3564.c > > > > > > > > 1094 > > > > 1095 static void mcp3564_fill_scale_tbls(struct > > > > mcp3564_state > > > > *adc) > > > > 1096 { > > > > ..... > > > > 1103 for (i = 0; i < MCP3564_MAX_PGA; i++) { > > > > 1104 ref = adc->vref_mv; > > > > > 1105 tmp1 = shift_right((u64)ref * NANO, > > > > pow); > > > > 1106 div_u64_rem(tmp1, NANO, &tmp0); > > > > 1107 > > > > ..... > > > > 1113 } > > > > > > > > Reported-by: kernel test robot <lkp@intel.com> > > > > Closes: > > > > https://lore.kernel.org/oe-kbuild-all/202309280738.NWjVfVt4-lkp@intel.com/ > > > > Fixes: efea15e3c65d (iio: adc: MCP3564: fix the static checker > > > > warning) > > > > > > 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? > > > > > > Was it just a case of fixing that issue allowing the static > > > checker > > > to > > > get further before giving up? In which case the description > > > needs > > > modifying. > > > > > > Or am I missing something in the following fix? > > > > > > 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) > > > struct mcp3564_state *adc; > > > > > > indio_dev = devm_iio_device_alloc(&spi->dev, > > > sizeof(*adc)); > > > - if (!indio_dev) { > > > - dev_err_probe(&indio_dev->dev, > > > PTR_ERR(indio_dev), > > > - "Can't allocate iio device\n"); > > > + if (!indio_dev) > > > return -ENOMEM; > > > - } > > > > > > > > > > I've got two bugs reported: > > > > - 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, > > PTR_ERR(indio_dev), > > > > 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." > > > > Also my mistake at this point was that I didn't setup and run the > > "Smatch static checker warning" > > > > > > > as that's all I'm seeing in that commit. > > > > > Yes, that commit only handled part of the fix. > > > > > > > > > > Signed-off-by: Marius Cristea <marius.cristea@microchip.com> > > > > --- > > > > drivers/iio/adc/mcp3564.c | 2 +- > > > > 1 file changed, 1 insertion(+), 1 deletion(-) > > > > > > > > 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) > > > > > > > > for (i = 0; i < MCP3564_MAX_PGA; i++) { > > > > ref = adc->vref_mv; > > > > - tmp1 = shift_right((u64)ref * NANO, pow); > > > > + tmp1 = ((u64)ref * NANO) >> pow; > > > > div_u64_rem(tmp1, NANO, &tmp0); > > > > > > > > tmp1 = tmp1 * mcp3564_hwgain_frac[(2 * i) + 1]; > > > > > > > > base-commit: 5e99f692d4e32e3250ab18d511894ca797407aec > > > > > > > - The second bug was reported by "kernel test robot > > <lkp@intel.com>" > > also by running Smatch and it was run on the initial driver > > (without > > having the first patch applied) > > > > 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' > > > > > > 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. > > > > 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: > > > > - tmp1 = shift_right((u64)ref * NANO, pow); > > + tmp1 = ((u64)ref * NANO) >> pow; > > > > 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). > > > > I have applied the patch on top of what was the "latest" from > > togreg > > branch and not on the initial driver. > > > > > > 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. > Actually there was 2 bug reports and the second one includes the first bug report. For the first bug/warming report I already submit a patch that was applied to togreg branch (commit efea15e3c65d96bac17a4d8104e3fff7c07cc910). For the second bug/warming report I have "fixed" only the part that wasn't fixed before. I will resubmit this patch updating the description. > Thanks, > > Jonathan > > > > > Thanks, > > Marius > Thanks, Marius
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) for (i = 0; i < MCP3564_MAX_PGA; i++) { ref = adc->vref_mv; - tmp1 = shift_right((u64)ref * NANO, pow); + tmp1 = ((u64)ref * NANO) >> pow; div_u64_rem(tmp1, NANO, &tmp0); tmp1 = tmp1 * mcp3564_hwgain_frac[(2 * i) + 1];