From: "Stefan Brüns" <stefan.bruens@rwth-aachen.de>
To: Colin King <colin.king@canonical.com>
Cc: Jonathan Cameron <jic23@kernel.org>,
Hartmut Knaack <knaack.h@gmx.de>,
Lars-Peter Clausen <lars@metafoo.de>,
Peter Meerwald-Stadler <pmeerw@pmeerw.net>,
linux-iio@vger.kernel.org, kernel-janitors@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH] iio: adc: ina2xx: fix missing break statement
Date: Wed, 10 Oct 2018 10:42:39 +0000 [thread overview]
Message-ID: <1884341.stJYpOWv9L@pebbles> (raw)
In-Reply-To: <20181008210904.9362-1-colin.king@canonical.com>
[-- Attachment #1: Type: text/plain, Size: 1767 bytes --]
On Montag, 8. Oktober 2018 23:09:04 CEST Colin King wrote:
> From: Colin Ian King <colin.king@canonical.com>
>
> The IIO_CHAN_INFO_SCALE case is missing a break statement and in
> the unlikely event that chan->address is not matched in the nested
> switch statement then the code falls through to the following
> IIO_CHAN_INFO_HARDWAREGAIN case. Fix this by adding the missing
> break. While we are fixing this, it's probably a good idea to
> add in a break statement to the IIO_CHAN_INFO_HARDWAREGAIN case
> too (this is a moot point).
>
> Detected by CoverityScan, CID#1462408 ("Missing break in switch")
Although it is good for code clarity to add a break statement, the code can
never return anything but -EINVAL in case chan->address is not handled in
IIO_CHAN_INFO_SCALE:
-----
switch (mask) {
case IIO_CHAN_INFO_SCALE:
switch (chan->address) {
case INA2XX_SHUNT_VOLTAGE:
... return IIO_VAL_FRACTIONAL;
case INA2XX_BUS_VOLTAGE:
... return IIO_VAL_FRACTIONAL;
case INA2XX_CURRENT:
... return IIO_VAL_FRACTIONAL;
case INA2XX_POWER:
... return IIO_VAL_FRACTIONAL;
}
case IIO_CHAN_INFO_HARDWAREGAIN:
switch (chan->address) {
case INA2XX_SHUNT_VOLTAGE:
... return IIO_VAL_FRACTIONAL;
case INA2XX_BUS_VOLTAGE:
... return IIO_VAL_INT;
}
}
return -EINVAL;
-----
The addresses handled in INFO_HARDWAREGAIN is a subset of the ones in
INFO_SCALE.
I would prefer an early "return -EINVAL" here, as it matches better with the
other "switch (mask)" cases above.
Kind regards,
Stefan
--
Stefan Brüns / Bergstraße 21 / 52062 Aachen
home: +49 241 53809034 mobile: +49 151 50412019
[-- Attachment #2: This is a digitally signed message part. --]
[-- Type: application/pgp-signature, Size: 195 bytes --]
WARNING: multiple messages have this Message-ID (diff)
From: "Stefan Brüns" <stefan.bruens@rwth-aachen.de>
To: Colin King <colin.king@canonical.com>
Cc: Jonathan Cameron <jic23@kernel.org>,
Hartmut Knaack <knaack.h@gmx.de>,
Lars-Peter Clausen <lars@metafoo.de>,
Peter Meerwald-Stadler <pmeerw@pmeerw.net>,
<linux-iio@vger.kernel.org>, <kernel-janitors@vger.kernel.org>,
<linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] iio: adc: ina2xx: fix missing break statement
Date: Wed, 10 Oct 2018 12:42:39 +0200 [thread overview]
Message-ID: <1884341.stJYpOWv9L@pebbles> (raw)
In-Reply-To: <20181008210904.9362-1-colin.king@canonical.com>
[-- Attachment #1: Type: text/plain, Size: 1767 bytes --]
On Montag, 8. Oktober 2018 23:09:04 CEST Colin King wrote:
> From: Colin Ian King <colin.king@canonical.com>
>
> The IIO_CHAN_INFO_SCALE case is missing a break statement and in
> the unlikely event that chan->address is not matched in the nested
> switch statement then the code falls through to the following
> IIO_CHAN_INFO_HARDWAREGAIN case. Fix this by adding the missing
> break. While we are fixing this, it's probably a good idea to
> add in a break statement to the IIO_CHAN_INFO_HARDWAREGAIN case
> too (this is a moot point).
>
> Detected by CoverityScan, CID#1462408 ("Missing break in switch")
Although it is good for code clarity to add a break statement, the code can
never return anything but -EINVAL in case chan->address is not handled in
IIO_CHAN_INFO_SCALE:
-----
switch (mask) {
case IIO_CHAN_INFO_SCALE:
switch (chan->address) {
case INA2XX_SHUNT_VOLTAGE:
... return IIO_VAL_FRACTIONAL;
case INA2XX_BUS_VOLTAGE:
... return IIO_VAL_FRACTIONAL;
case INA2XX_CURRENT:
... return IIO_VAL_FRACTIONAL;
case INA2XX_POWER:
... return IIO_VAL_FRACTIONAL;
}
case IIO_CHAN_INFO_HARDWAREGAIN:
switch (chan->address) {
case INA2XX_SHUNT_VOLTAGE:
... return IIO_VAL_FRACTIONAL;
case INA2XX_BUS_VOLTAGE:
... return IIO_VAL_INT;
}
}
return -EINVAL;
-----
The addresses handled in INFO_HARDWAREGAIN is a subset of the ones in
INFO_SCALE.
I would prefer an early "return -EINVAL" here, as it matches better with the
other "switch (mask)" cases above.
Kind regards,
Stefan
--
Stefan Brüns / Bergstraße 21 / 52062 Aachen
home: +49 241 53809034 mobile: +49 151 50412019
[-- Attachment #2: This is a digitally signed message part. --]
[-- Type: application/pgp-signature, Size: 195 bytes --]
next prev parent reply other threads:[~2018-10-10 10:42 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-10-08 21:09 [PATCH] iio: adc: ina2xx: fix missing break statement Colin King
2018-10-08 21:09 ` Colin King
2018-10-10 7:51 ` Matt Ranostay
2018-10-10 7:51 ` Matt Ranostay
2018-10-10 7:59 ` Colin Ian King
2018-10-10 7:59 ` Colin Ian King
2018-10-10 10:42 ` Stefan Brüns [this message]
2018-10-10 10:42 ` Stefan Brüns
2018-10-13 12:44 ` Jonathan Cameron
2018-10-13 12:44 ` Jonathan Cameron
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=1884341.stJYpOWv9L@pebbles \
--to=stefan.bruens@rwth-aachen.de \
--cc=colin.king@canonical.com \
--cc=jic23@kernel.org \
--cc=kernel-janitors@vger.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.net \
/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.