From: Arnd Bergmann <arnd@arndb.de>
To: Jonathan Cameron <jic23@kernel.org>
Cc: clang-built-linux@googlegroups.com,
Nick Desaulniers <ndesaulniers@google.com>,
Nathan Chancellor <natechancellor@gmail.com>,
Arnd Bergmann <arnd@arndb.de>, Hartmut Knaack <knaack.h@gmx.de>,
Lars-Peter Clausen <lars@metafoo.de>,
Peter Meerwald-Stadler <pmeerw@pmeerw.net>,
linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH] iio: ssp_sensors: avoid uninitialized variable usage
Date: Fri, 22 Mar 2019 15:09:22 +0100 [thread overview]
Message-ID: <20190322140937.341976-1-arnd@arndb.de> (raw)
clang points out that 'calculated_time' is only sometimes
initialized here, which leads to incorrect data being
passed into another function:
drivers/iio/common/ssp_sensors/ssp_iio.c:95:6: error: variable 'calculated_time' is used uninitialized whenever 'if' condition is false [-Werror,-Wsometimes-uninitialized]
if (indio_dev->scan_timestamp) {
^~~~~~~~~~~~~~~~~~~~~~~~~
drivers/iio/common/ssp_sensors/ssp_iio.c:102:9: note: uninitialized use occurs here
calculated_time);
^~~~~~~~~~~~~~~
drivers/iio/common/ssp_sensors/ssp_iio.c:95:2: note: remove the 'if' if its condition is always true
if (indio_dev->scan_timestamp) {
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
drivers/iio/common/ssp_sensors/ssp_iio.c:84:25: note: initialize the variable 'calculated_time' to silence this warning
int64_t calculated_time;
^
The data is subsequently ignored by iio_push_to_buffers_with_timestamp(),
but the warning still feels legitimate and to work around it, we can
initialize the time in the other case.
Link: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=18501
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
drivers/iio/common/ssp_sensors/ssp_iio.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/drivers/iio/common/ssp_sensors/ssp_iio.c b/drivers/iio/common/ssp_sensors/ssp_iio.c
index 645f2e3975db..81e8f4844c90 100644
--- a/drivers/iio/common/ssp_sensors/ssp_iio.c
+++ b/drivers/iio/common/ssp_sensors/ssp_iio.c
@@ -96,6 +96,8 @@ int ssp_common_process_data(struct iio_dev *indio_dev, void *buf,
memcpy(&time, &((char *)buf)[len], SSP_TIME_SIZE);
calculated_time =
timestamp + (int64_t)le32_to_cpu(time) * 1000000;
+ } else {
+ calculated_time = 0;
}
return iio_push_to_buffers_with_timestamp(indio_dev, spd->buffer,
--
2.20.0
next reply other threads:[~2019-03-22 14:10 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-03-22 14:09 Arnd Bergmann [this message]
2019-03-22 15:01 ` [PATCH] iio: ssp_sensors: avoid uninitialized variable usage Nathan Chancellor
2019-03-24 15:34 ` 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=20190322140937.341976-1-arnd@arndb.de \
--to=arnd@arndb.de \
--cc=clang-built-linux@googlegroups.com \
--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=natechancellor@gmail.com \
--cc=ndesaulniers@google.com \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox