* [PATCH] iio: common: ssp_sensors: Initialize calculated_time in ssp_common_process_data
@ 2019-03-07 21:45 Nathan Chancellor
2019-03-08 0:35 ` Nick Desaulniers
0 siblings, 1 reply; 5+ messages in thread
From: Nathan Chancellor @ 2019-03-07 21:45 UTC (permalink / raw)
To: Jonathan Cameron
Cc: Hartmut Knaack, Lars-Peter Clausen, Peter Meerwald-Stadler,
linux-iio, linux-kernel, clang-built-linux, Nick Desaulniers,
Nathan Chancellor
When building with -Wsometimes-uninitialized, Clang warns:
drivers/iio/common/ssp_sensors/ssp_iio.c:95:6: warning: variable
'calculated_time' is used uninitialized whenever 'if' condition is false
[-Wsometimes-uninitialized]
While it isn't wrong, this will never be a problem because
iio_push_to_buffers_with_timestamp only uses calculated_time
on the same condition that it is assigned (when scan_timestamp
is not zero). While iio_push_to_buffers_with_timestamp is marked
as inline, Clang does inlining in the optimization stage, which
happens after the semantic analysis phase (plus inline is merely
a hint to the compiler).
Fix this by just zero initializing calculated_time.
Link: https://github.com/ClangBuiltLinux/linux/issues/394
Signed-off-by: Nathan Chancellor <natechancellor@gmail.com>
---
drivers/iio/common/ssp_sensors/ssp_iio.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/iio/common/ssp_sensors/ssp_iio.c b/drivers/iio/common/ssp_sensors/ssp_iio.c
index 645f2e3975db..e38f704d88b7 100644
--- a/drivers/iio/common/ssp_sensors/ssp_iio.c
+++ b/drivers/iio/common/ssp_sensors/ssp_iio.c
@@ -81,7 +81,7 @@ int ssp_common_process_data(struct iio_dev *indio_dev, void *buf,
unsigned int len, int64_t timestamp)
{
__le32 time;
- int64_t calculated_time;
+ int64_t calculated_time = 0;
struct ssp_sensor_data *spd = iio_priv(indio_dev);
if (indio_dev->scan_bytes == 0)
--
2.21.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH] iio: common: ssp_sensors: Initialize calculated_time in ssp_common_process_data
2019-03-07 21:45 [PATCH] iio: common: ssp_sensors: Initialize calculated_time in ssp_common_process_data Nathan Chancellor
@ 2019-03-08 0:35 ` Nick Desaulniers
2019-03-10 9:37 ` Jonathan Cameron
0 siblings, 1 reply; 5+ messages in thread
From: Nick Desaulniers @ 2019-03-08 0:35 UTC (permalink / raw)
To: Nathan Chancellor
Cc: Jonathan Cameron, Hartmut Knaack, Lars-Peter Clausen,
Peter Meerwald-Stadler, linux-iio, LKML, clang-built-linux
On Thu, Mar 7, 2019 at 1:46 PM Nathan Chancellor
<natechancellor@gmail.com> wrote:
>
> When building with -Wsometimes-uninitialized, Clang warns:
>
> drivers/iio/common/ssp_sensors/ssp_iio.c:95:6: warning: variable
> 'calculated_time' is used uninitialized whenever 'if' condition is false
> [-Wsometimes-uninitialized]
>
> While it isn't wrong, this will never be a problem because
> iio_push_to_buffers_with_timestamp only uses calculated_time
> on the same condition that it is assigned (when scan_timestamp
> is not zero). While iio_push_to_buffers_with_timestamp is marked
> as inline, Clang does inlining in the optimization stage, which
> happens after the semantic analysis phase (plus inline is merely
> a hint to the compiler).
>
> Fix this by just zero initializing calculated_time.
>
> Link: https://github.com/ClangBuiltLinux/linux/issues/394
> Signed-off-by: Nathan Chancellor <natechancellor@gmail.com>
Knowing that the same invariant holds across function boundaries to
protect access of unitialized values and thus undefined behavior
sounds tricky to diagnose accurately. Thanks for the patch.
Reviewed-by: Nick Desaulniers <ndesaulniers@google.com>
> ---
> drivers/iio/common/ssp_sensors/ssp_iio.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/iio/common/ssp_sensors/ssp_iio.c b/drivers/iio/common/ssp_sensors/ssp_iio.c
> index 645f2e3975db..e38f704d88b7 100644
> --- a/drivers/iio/common/ssp_sensors/ssp_iio.c
> +++ b/drivers/iio/common/ssp_sensors/ssp_iio.c
> @@ -81,7 +81,7 @@ int ssp_common_process_data(struct iio_dev *indio_dev, void *buf,
> unsigned int len, int64_t timestamp)
> {
> __le32 time;
> - int64_t calculated_time;
> + int64_t calculated_time = 0;
> struct ssp_sensor_data *spd = iio_priv(indio_dev);
>
> if (indio_dev->scan_bytes == 0)
> --
> 2.21.0
>
--
Thanks,
~Nick Desaulniers
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] iio: common: ssp_sensors: Initialize calculated_time in ssp_common_process_data
2019-03-08 0:35 ` Nick Desaulniers
@ 2019-03-10 9:37 ` Jonathan Cameron
2019-03-11 11:10 ` Arnd Bergmann
0 siblings, 1 reply; 5+ messages in thread
From: Jonathan Cameron @ 2019-03-10 9:37 UTC (permalink / raw)
To: Nick Desaulniers
Cc: Nathan Chancellor, Hartmut Knaack, Lars-Peter Clausen,
Peter Meerwald-Stadler, linux-iio, LKML, clang-built-linux
On Thu, 7 Mar 2019 16:35:26 -0800
Nick Desaulniers <ndesaulniers@google.com> wrote:
> On Thu, Mar 7, 2019 at 1:46 PM Nathan Chancellor
> <natechancellor@gmail.com> wrote:
> >
> > When building with -Wsometimes-uninitialized, Clang warns:
> >
> > drivers/iio/common/ssp_sensors/ssp_iio.c:95:6: warning: variable
> > 'calculated_time' is used uninitialized whenever 'if' condition is false
> > [-Wsometimes-uninitialized]
> >
> > While it isn't wrong, this will never be a problem because
> > iio_push_to_buffers_with_timestamp only uses calculated_time
> > on the same condition that it is assigned (when scan_timestamp
> > is not zero). While iio_push_to_buffers_with_timestamp is marked
> > as inline, Clang does inlining in the optimization stage, which
> > happens after the semantic analysis phase (plus inline is merely
> > a hint to the compiler).
> >
> > Fix this by just zero initializing calculated_time.
> >
> > Link: https://github.com/ClangBuiltLinux/linux/issues/394
> > Signed-off-by: Nathan Chancellor <natechancellor@gmail.com>
>
> Knowing that the same invariant holds across function boundaries to
> protect access of unitialized values and thus undefined behavior
> sounds tricky to diagnose accurately. Thanks for the patch.
> Reviewed-by: Nick Desaulniers <ndesaulniers@google.com>
Applied to the togreg branch of iio.git and pushed out as testing
for the autobuilders to play with it.
Note this is going to be a while before it hits mainline but as
it is a false (if reasonable!) warning I'm not going to rush
it in as a fix.
Thanks,
Jonathan
>
> > ---
> > drivers/iio/common/ssp_sensors/ssp_iio.c | 2 +-
> > 1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/drivers/iio/common/ssp_sensors/ssp_iio.c b/drivers/iio/common/ssp_sensors/ssp_iio.c
> > index 645f2e3975db..e38f704d88b7 100644
> > --- a/drivers/iio/common/ssp_sensors/ssp_iio.c
> > +++ b/drivers/iio/common/ssp_sensors/ssp_iio.c
> > @@ -81,7 +81,7 @@ int ssp_common_process_data(struct iio_dev *indio_dev, void *buf,
> > unsigned int len, int64_t timestamp)
> > {
> > __le32 time;
> > - int64_t calculated_time;
> > + int64_t calculated_time = 0;
> > struct ssp_sensor_data *spd = iio_priv(indio_dev);
> >
> > if (indio_dev->scan_bytes == 0)
> > --
> > 2.21.0
> >
>
>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] iio: common: ssp_sensors: Initialize calculated_time in ssp_common_process_data
2019-03-10 9:37 ` Jonathan Cameron
@ 2019-03-11 11:10 ` Arnd Bergmann
2019-03-11 13:50 ` Nathan Chancellor
0 siblings, 1 reply; 5+ messages in thread
From: Arnd Bergmann @ 2019-03-11 11:10 UTC (permalink / raw)
To: Jonathan Cameron
Cc: Nick Desaulniers, Nathan Chancellor, Hartmut Knaack,
Lars-Peter Clausen, Peter Meerwald-Stadler, linux-iio, LKML,
clang-built-linux
On Sun, Mar 10, 2019 at 10:37 AM Jonathan Cameron <jic23@kernel.org> wrote:
> On Thu, 7 Mar 2019 16:35:26 -0800 Nick Desaulniers <ndesaulniers@google.com> wrote:
> > On Thu, Mar 7, 2019 at 1:46 PM Nathan Chancellor <natechancellor@gmail.com> wrote:
> > >
> > > When building with -Wsometimes-uninitialized, Clang warns:
> > >
> > > drivers/iio/common/ssp_sensors/ssp_iio.c:95:6: warning: variable
> > > 'calculated_time' is used uninitialized whenever 'if' condition is false
> > > [-Wsometimes-uninitialized]
> > >
> > > While it isn't wrong, this will never be a problem because
> > > iio_push_to_buffers_with_timestamp only uses calculated_time
> > > on the same condition that it is assigned (when scan_timestamp
> > > is not zero). While iio_push_to_buffers_with_timestamp is marked
> > > as inline, Clang does inlining in the optimization stage, which
> > > happens after the semantic analysis phase (plus inline is merely
> > > a hint to the compiler).
> > >
> > > Fix this by just zero initializing calculated_time.
> > >
> > > Link: https://github.com/ClangBuiltLinux/linux/issues/394
> > > Signed-off-by: Nathan Chancellor <natechancellor@gmail.com>
> >
> > Knowing that the same invariant holds across function boundaries to
> > protect access of unitialized values and thus undefined behavior
> > sounds tricky to diagnose accurately. Thanks for the patch.
> > Reviewed-by: Nick Desaulniers <ndesaulniers@google.com>
> Applied to the togreg branch of iio.git and pushed out as testing
> for the autobuilders to play with it.
>
> Note this is going to be a while before it hits mainline but as
> it is a false (if reasonable!) warning I'm not going to rush
> it in as a fix.
I think it's actually a correct warning, it just doesn't trigger
on gcc because of a known gcc bug.
I'm not sure however why I don't see the warning with clang-8
on my local build. Is this something I have to enable
separately?
Arnd
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] iio: common: ssp_sensors: Initialize calculated_time in ssp_common_process_data
2019-03-11 11:10 ` Arnd Bergmann
@ 2019-03-11 13:50 ` Nathan Chancellor
0 siblings, 0 replies; 5+ messages in thread
From: Nathan Chancellor @ 2019-03-11 13:50 UTC (permalink / raw)
To: Arnd Bergmann
Cc: Jonathan Cameron, Nick Desaulniers, Hartmut Knaack,
Lars-Peter Clausen, Peter Meerwald-Stadler, linux-iio, LKML,
clang-built-linux
On Mon, Mar 11, 2019 at 12:10:18PM +0100, Arnd Bergmann wrote:
> On Sun, Mar 10, 2019 at 10:37 AM Jonathan Cameron <jic23@kernel.org> wrote:
> > On Thu, 7 Mar 2019 16:35:26 -0800 Nick Desaulniers <ndesaulniers@google.com> wrote:
> > > On Thu, Mar 7, 2019 at 1:46 PM Nathan Chancellor <natechancellor@gmail.com> wrote:
> > > >
> > > > When building with -Wsometimes-uninitialized, Clang warns:
> > > >
> > > > drivers/iio/common/ssp_sensors/ssp_iio.c:95:6: warning: variable
> > > > 'calculated_time' is used uninitialized whenever 'if' condition is false
> > > > [-Wsometimes-uninitialized]
> > > >
> > > > While it isn't wrong, this will never be a problem because
> > > > iio_push_to_buffers_with_timestamp only uses calculated_time
> > > > on the same condition that it is assigned (when scan_timestamp
> > > > is not zero). While iio_push_to_buffers_with_timestamp is marked
> > > > as inline, Clang does inlining in the optimization stage, which
> > > > happens after the semantic analysis phase (plus inline is merely
> > > > a hint to the compiler).
> > > >
> > > > Fix this by just zero initializing calculated_time.
> > > >
> > > > Link: https://github.com/ClangBuiltLinux/linux/issues/394
> > > > Signed-off-by: Nathan Chancellor <natechancellor@gmail.com>
> > >
> > > Knowing that the same invariant holds across function boundaries to
> > > protect access of unitialized values and thus undefined behavior
> > > sounds tricky to diagnose accurately. Thanks for the patch.
> > > Reviewed-by: Nick Desaulniers <ndesaulniers@google.com>
> > Applied to the togreg branch of iio.git and pushed out as testing
> > for the autobuilders to play with it.
> >
> > Note this is going to be a while before it hits mainline but as
> > it is a false (if reasonable!) warning I'm not going to rush
> > it in as a fix.
>
> I think it's actually a correct warning, it just doesn't trigger
> on gcc because of a known gcc bug.
>
> I'm not sure however why I don't see the warning with clang-8
> on my local build. Is this something I have to enable
> separately?
>
> Arnd
Yes, -Wsometimes-uninitialized is not on by default because
-Wuninitialized is disabled. You can either pass it via KCFLAGS or
modify scripts/Makefile.extrawarn, which is the eventual goal because
Clang can catch things that GCC can't:
https://github.com/ClangBuiltLinux/linux/issues/381
Cheers,
Nathan
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2019-03-11 13:50 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-03-07 21:45 [PATCH] iio: common: ssp_sensors: Initialize calculated_time in ssp_common_process_data Nathan Chancellor
2019-03-08 0:35 ` Nick Desaulniers
2019-03-10 9:37 ` Jonathan Cameron
2019-03-11 11:10 ` Arnd Bergmann
2019-03-11 13:50 ` Nathan Chancellor
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).