From: Guenter Roeck <linux@roeck-us.net>
To: Masahiro Yamada <yamada.masahiro@socionext.com>
Cc: Jean Delvare <jdelvare@suse.com>,
linux-hwmon@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2] hwmon: (smsc47m1) fix (suspicious) outside array bounds warnings
Date: Thu, 6 Jun 2019 06:09:54 -0700 [thread overview]
Message-ID: <20190606130954.GA10669@roeck-us.net> (raw)
In-Reply-To: <20190606085242.31347-1-yamada.masahiro@socionext.com>
On Thu, Jun 06, 2019 at 05:52:42PM +0900, Masahiro Yamada wrote:
> Kbuild test robot reports outside array bounds warnings.
>
> This is reproducible for ARCH=sh allmodconfig with the kernel.org
> toolchains available at:
>
> https://mirrors.edge.kernel.org/pub/tools/crosstool/files/bin/x86_64/8.1.0/x86_64-gcc-8.1.0-nolibc-sh4-linux.tar.xz
>
> CC [M] drivers/hwmon/smsc47m1.o
> drivers/hwmon/smsc47m1.c: In function 'fan_div_store':
> drivers/hwmon/smsc47m1.c:370:49: warning: array subscript [0, 2] is outside array bounds of 'u8[3]' {aka 'unsigned char[3]'} [-Warray-bounds]
> tmp = 192 - (old_div * (192 - data->fan_preload[nr])
> ~~~~~~~~~~~~~~~~~^~~~
> drivers/hwmon/smsc47m1.c:372:19: warning: array subscript [0, 2] is outside array bounds of 'u8[3]' {aka 'unsigned char[3]'} [-Warray-bounds]
> data->fan_preload[nr] = clamp_val(tmp, 0, 191);
> ~~~~~~~~~~~~~~~~~^~~~
> drivers/hwmon/smsc47m1.c:373:53: warning: array subscript [0, 2] is outside array bounds of 'const u8[3]' {aka 'const unsigned char[3]'} [-Warray-bounds]
> smsc47m1_write_value(data, SMSC47M1_REG_FAN_PRELOAD[nr],
> ~~~~~~~~~~~~~~~~~~~~~~~~^~~~
>
> Looking at the code, I believe these are false positives.
>
> While it is ridiculous to patch our driver to make the insane
> compiler happy, clarifying the unreachable path will be helpful
> not only for compilers but also for humans.
>
> Reported-by: kbuild test robot <lkp@intel.com>
> Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
Applied.
Thanks,
Guenter
> ---
>
> Changes in v2:
> - Use unreachable() instead of WARN_ON()
> - Mention that the report seems suspicious
>
> drivers/hwmon/smsc47m1.c | 2 ++
> 1 file changed, 2 insertions(+)
>
> diff --git a/drivers/hwmon/smsc47m1.c b/drivers/hwmon/smsc47m1.c
> index cc6aca6e436c..6d366c9cb906 100644
> --- a/drivers/hwmon/smsc47m1.c
> +++ b/drivers/hwmon/smsc47m1.c
> @@ -351,6 +351,8 @@ static ssize_t fan_div_store(struct device *dev,
> tmp |= data->fan_div[2] << 4;
> smsc47m1_write_value(data, SMSC47M2_REG_FANDIV3, tmp);
> break;
> + default:
> + unreachable();
> }
>
> /* Preserve fan min */
prev parent reply other threads:[~2019-06-06 13:09 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-06-06 8:52 [PATCH v2] hwmon: (smsc47m1) fix (suspicious) outside array bounds warnings Masahiro Yamada
2019-06-06 13:09 ` Guenter Roeck [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=20190606130954.GA10669@roeck-us.net \
--to=linux@roeck-us.net \
--cc=jdelvare@suse.com \
--cc=linux-hwmon@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=yamada.masahiro@socionext.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 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).