All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jonathan Cameron <jic23@kernel.org>
To: <marius.cristea@microchip.com>
Cc: <lars@metafoo.de>, <lgirdwood@gmail.com>, <broonie@kernel.org>,
	<linux-iio@vger.kernel.org>, <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH v1] iio: adc: MCP3564: fix warn: unsigned '__x' is never less than zero.
Date: Tue, 10 Oct 2023 10:44:44 +0100	[thread overview]
Message-ID: <20231010104444.12e61984@jic23-huawei> (raw)
In-Reply-To: <20231002161618.36373-1-marius.cristea@microchip.com>

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


  reply	other threads:[~2023-10-10  9:45 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-10-02 16:16 [PATCH v1] iio: adc: MCP3564: fix warn: unsigned '__x' is never less than zero marius.cristea
2023-10-10  9:44 ` Jonathan Cameron [this message]
2023-10-11 16:41   ` Marius.Cristea
2023-10-12  7:36     ` Jonathan Cameron
2023-10-12  8:18       ` Marius.Cristea

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20231010104444.12e61984@jic23-huawei \
    --to=jic23@kernel.org \
    --cc=broonie@kernel.org \
    --cc=lars@metafoo.de \
    --cc=lgirdwood@gmail.com \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=marius.cristea@microchip.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.