Linux-IIO Archive on lore.kernel.org
 help / color / Atom feed
From: Colin Ian King <colin.king@canonical.com>
To: Lars-Peter Clausen <lars@metafoo.de>,
	Jonathan Cameron <jic23@kernel.org>,
	Hartmut Knaack <knaack.h@gmx.de>,
	Peter Meerwald-Stadler <pmeerw@pmeerw.ne>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Michael Hennerich <Michael.Hennerich@analog.com>,
	Stefan Popa <stefan.popa@analog.com>,
	linux-iio@vger.kernel.org,
	"devel@driverdev.osuosl.org" <devel@driverdev.osuosl.org>
Cc: "linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: static analysis bug report in drivers/staging/iio/dac/ad5380.c
Date: Thu, 15 Aug 2019 11:21:22 +0100
Message-ID: <dd9e8ad0-31c8-a06f-be6b-e665e9b2c1c2@canonical.com> (raw)

Hi,

Static analysis with Coverity Scan has detected a potential assignment
bug in ad5380.c:

217        case IIO_CHAN_INFO_CALIBBIAS:
218                ret = regmap_read(st->regmap,
AD5380_REG_OFFSET(chan->address),
219                                        val);
220                if (ret)
221                        return ret;
222                *val >>= chan->scan_type.shift;

CID 43178 (#1 of 1): Unused value (UNUSED_VALUE)assigned_pointer:
Assigning value from val - (1 << chan->scan_type.realbits) / 2 to val
here, but that stored value is not used.

223                val -= (1 << chan->scan_type.realbits) / 2;
224                return IIO_VAL_INT;

val is a pointer and so updating it before a return is probably not the
intention.  I suspect the intention was probably:

		   *val -= (1 << chan->scan_type.realbits) / 2;

However, I'm not confident about this as the following case has:

225        case IIO_CHAN_INFO_SCALE:
226                *val = 2 * st->vref;
227                *val2 = chan->scan_type.realbits;
228                return IIO_VAL_FRACTIONAL_LOG2;

which may imply the update maybe to *val2 instead, e.g.:

		*val2 -= (1 << chan->scan_type.realbits) / 2;

Any ideas?

Colin

             reply index

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-08-15 10:21 Colin Ian King [this message]
2019-08-15 11:40 ` Lars-Peter Clausen

Reply instructions:

You may reply publically 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=dd9e8ad0-31c8-a06f-be6b-e665e9b2c1c2@canonical.com \
    --to=colin.king@canonical.com \
    --cc=Michael.Hennerich@analog.com \
    --cc=devel@driverdev.osuosl.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=jic23@kernel.org \
    --cc=knaack.h@gmx.de \
    --cc=lars@metafoo.de \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=pmeerw@pmeerw.ne \
    --cc=stefan.popa@analog.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

Linux-IIO Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-iio/0 linux-iio/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-iio linux-iio/ https://lore.kernel.org/linux-iio \
		linux-iio@vger.kernel.org linux-iio@archiver.kernel.org
	public-inbox-index linux-iio


Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-iio


AGPL code for this site: git clone https://public-inbox.org/ public-inbox