linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Marcelo Schmitt <marcelo.schmitt1@gmail.com>
To: "Colin King (gmail)" <colin.i.king@gmail.com>
Cc: Jonathan Cameron <jic23@kernel.org>,
	linux-iio@vger.kernel.org,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: Re: iio:adc:ad7280a: Move out of staging
Date: Fri, 4 Mar 2022 23:32:17 -0300	[thread overview]
Message-ID: <YiLLsQmnK+f6hjvi@marsc.168.1.7> (raw)
In-Reply-To: <69aeef03-69ba-07f4-2506-31e481f86c76@gmail.com>

On 02/24, Colin King (gmail) wrote:
> Hi,
> 
> Static analysis with clang scan picked up a potential issue with
> drivers/iio/adc/ad7280a.c in function ad7280a_write_thresh, the analysis is
> as follows:
> 
>         switch (chan->type) {
>         case IIO_VOLTAGE:
>                 value = ((val - 1000) * 100) / 1568; /* LSB 15.68mV */
>                 value = clamp(value, 0L, 0xFFL);
> 
>                 ^^
> Note: variable value is being assigned a value
> 
>                 switch (dir) {
>                 case IIO_EV_DIR_RISING:
>                         addr = AD7280A_CELL_OVERVOLTAGE_REG;
>                         ret = ad7280_write(st, AD7280A_DEVADDR_MASTER, addr,
>                                            1, val);
>                         if (ret)
>                                 break;
>                         st->cell_threshhigh = value;
> 
> ..and value is being used here ^^
> 
>                         break;
>                 case IIO_EV_DIR_FALLING:
>                         addr = AD7280A_CELL_UNDERVOLTAGE_REG;
>                         ret = ad7280_write(st, AD7280A_DEVADDR_MASTER, addr,
>                                            1, val);
>                         if (ret)
>                                 break;
>                         st->cell_threshlow = value;
> 
> and value is being used here ^^
> 
>                         break;
>                 default:
>                         ret = -EINVAL;
>                         goto err_unlock;
>                 }
>                 break;
> 
> However for the IIO_TEMP case:
> 
>         case IIO_TEMP:
>                 value = (val * 10) / 196; /* LSB 19.6mV */
>                 value = clamp(value, 0L, 0xFFL);
> 
>                 ^^
> Note: variable value is being assigned a value
> 
>                 switch (dir) {
>                 case IIO_EV_DIR_RISING:
>                         addr = AD7280A_AUX_ADC_OVERVOLTAGE_REG;
>                         ret = ad7280_write(st, AD7280A_DEVADDR_MASTER, addr,
>                                            1, val);
>                         if (ret)
>                                 break;
>                         st->aux_threshhigh = val;
>                                              ^^
> But val is being used here rather than value
> 
>                         break;
>                 case IIO_EV_DIR_FALLING:
>                         addr = AD7280A_AUX_ADC_UNDERVOLTAGE_REG;
>                         ret = ad7280_write(st, AD7280A_DEVADDR_MASTER, addr,
>                                            1, val);
>                         if (ret)
>                                 break;
>                         st->aux_threshlow = val;
>                                             ^^
> and val us being used here rather than value too
> 
> 
> So for the IIO_TEMP case either the assignment to value is redundant or the
> setting of st->aux_threshhigh or st->auxthreashlow is incorrect.

Good catch. This has really slipped through my review.
It's impressive how we can discuss changes at one specific part of the
code and miss inconsistencies a few lines below it.

Thanks,
Marcelo

> 
> Colin

      parent reply	other threads:[~2022-03-05  2:32 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-02-24 22:56 iio:adc:ad7280a: Move out of staging Colin King (gmail)
2022-02-26 18:01 ` Jonathan Cameron
2022-03-05  2:32 ` Marcelo Schmitt [this message]

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=YiLLsQmnK+f6hjvi@marsc.168.1.7 \
    --to=marcelo.schmitt1@gmail.com \
    --cc=colin.i.king@gmail.com \
    --cc=jic23@kernel.org \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).