* [jic23-iio:testing 6/10] drivers/iio/adc/max14001.c:135:13: warning: result of comparison of constant 18446744073709551615 with expression of type 'typeof (_Generic((mask), char: (unsigned char)0, unsigned char: (unsigned char)0, signed char: (unsigned char)0, unsigned short: (un...
@ 2023-06-21 7:18 kernel test robot
2023-06-21 8:25 ` Andy Shevchenko
0 siblings, 1 reply; 10+ messages in thread
From: kernel test robot @ 2023-06-21 7:18 UTC (permalink / raw)
To: Kim Seer Paller; +Cc: llvm, oe-kbuild-all, Jonathan Cameron, Andy Shevchenko
tree: https://git.kernel.org/pub/scm/linux/kernel/git/jic23/iio.git testing
head: 25e201cc6ff270abc062e13ff912292097cb2827
commit: d3e93b67f934a477c5851d575a2278f07c6242fb [6/10] iio: adc: max14001: New driver
config: x86_64-allyesconfig (https://download.01.org/0day-ci/archive/20230621/202306211545.7b6CdqsL-lkp@intel.com/config)
compiler: clang version 15.0.7 (https://github.com/llvm/llvm-project.git 8dfdcc7b7bf66834a761bd8de445840ef68e4d1a)
reproduce: (https://download.01.org/0day-ci/archive/20230621/202306211545.7b6CdqsL-lkp@intel.com/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202306211545.7b6CdqsL-lkp@intel.com/
All warnings (new ones prefixed by >>):
>> drivers/iio/adc/max14001.c:135:13: warning: result of comparison of constant 18446744073709551615 with expression of type 'typeof (_Generic((mask), char: (unsigned char)0, unsigned char: (unsigned char)0, signed char: (unsigned char)0, unsigned short: (unsigned short)0, short: (unsigned short)0, unsigned int: (unsigned int)0, int: (unsigned int)0, unsigned long: (unsigned long)0, long: (unsigned long)0, unsigned long long: (unsigned long long)0, long long: (unsigned long long)0, default: (mask)))' (aka 'unsigned int') is always false [-Wtautological-constant-out-of-range-compare]
reg_data = FIELD_PREP(mask, val);
^~~~~~~~~~~~~~~~~~~~~
include/linux/bitfield.h:114:3: note: expanded from macro 'FIELD_PREP'
__BF_FIELD_CHECK(_mask, 0ULL, _val, "FIELD_PREP: "); \
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
include/linux/bitfield.h:71:53: note: expanded from macro '__BF_FIELD_CHECK'
BUILD_BUG_ON_MSG(__bf_cast_unsigned(_mask, _mask) > \
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~
include/linux/build_bug.h:39:58: note: expanded from macro 'BUILD_BUG_ON_MSG'
#define BUILD_BUG_ON_MSG(cond, msg) compiletime_assert(!(cond), msg)
~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~
include/linux/compiler_types.h:397:22: note: expanded from macro 'compiletime_assert'
_compiletime_assert(condition, msg, __compiletime_assert_, __COUNTER__)
~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
include/linux/compiler_types.h:385:23: note: expanded from macro '_compiletime_assert'
__compiletime_assert(condition, msg, prefix, suffix)
~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
include/linux/compiler_types.h:377:9: note: expanded from macro '__compiletime_assert'
if (!(condition)) \
^~~~~~~~~
1 warning generated.
vim +135 drivers/iio/adc/max14001.c
117
118 static int max14001_reg_update(struct max14001_state *st,
119 unsigned int reg_addr,
120 unsigned int mask,
121 unsigned int val)
122 {
123 int ret;
124 unsigned int reg_data;
125
126 /* Enable SPI Registers Write */
127 ret = max14001_write(st, MAX14001_WEN, MAX14001_WRITE_WEN);
128 if (ret)
129 return ret;
130
131 ret = max14001_read(st, reg_addr, ®_data);
132 if (ret)
133 return ret;
134
> 135 reg_data = FIELD_PREP(mask, val);
136
137 ret = max14001_write(st, reg_addr, reg_data);
138 if (ret)
139 return ret;
140
141 /* Write Verification Register */
142 ret = max14001_write_verification_reg(st, reg_addr);
143 if (ret)
144 return ret;
145
146 /* Disable SPI Registers Write */
147 return max14001_write(st, MAX14001_WEN, 0);
148 }
149
--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [jic23-iio:testing 6/10] drivers/iio/adc/max14001.c:135:13: warning: result of comparison of constant 18446744073709551615 with expression of type 'typeof (_Generic((mask), char: (unsigned char)0, unsigned char: (unsigned char)0, signed char: (unsigned char)0, unsigned short: (un...
2023-06-21 7:18 [jic23-iio:testing 6/10] drivers/iio/adc/max14001.c:135:13: warning: result of comparison of constant 18446744073709551615 with expression of type 'typeof (_Generic((mask), char: (unsigned char)0, unsigned char: (unsigned char)0, signed char: (unsigned char)0, unsigned short: (un kernel test robot
@ 2023-06-21 8:25 ` Andy Shevchenko
2023-06-21 8:58 ` [jic23-iio:testing 6/10] drivers/iio/adc/max14001.c:135:13: warning: result of comparison of constant 18446744073709551615 with expression of type 'typeof (_Generic((mask), char: (unsigned char)0, unsigned char: (unsigned char)0, signed char: (unsi Paller, Kim Seer
2023-07-20 9:29 ` [jic23-iio:testing 6/10] drivers/iio/adc/max14001.c:135:13: warning: result of comparison of constant 18446744073709551615 with expression of type 'typeof (_Generic((mask), char: (unsigned char)0, unsigned char: (unsigned char)0, signed char: (unsigned char)0, unsigned short: (un Arnd Bergmann
0 siblings, 2 replies; 10+ messages in thread
From: Andy Shevchenko @ 2023-06-21 8:25 UTC (permalink / raw)
To: kernel test robot; +Cc: Kim Seer Paller, llvm, oe-kbuild-all, Jonathan Cameron
On Wed, Jun 21, 2023 at 10:19 AM kernel test robot <lkp@intel.com> wrote:
>
> tree: https://git.kernel.org/pub/scm/linux/kernel/git/jic23/iio.git testing
> head: 25e201cc6ff270abc062e13ff912292097cb2827
> commit: d3e93b67f934a477c5851d575a2278f07c6242fb [6/10] iio: adc: max14001: New driver
> config: x86_64-allyesconfig (https://download.01.org/0day-ci/archive/20230621/202306211545.7b6CdqsL-lkp@intel.com/config)
> compiler: clang version 15.0.7 (https://github.com/llvm/llvm-project.git 8dfdcc7b7bf66834a761bd8de445840ef68e4d1a)
> reproduce: (https://download.01.org/0day-ci/archive/20230621/202306211545.7b6CdqsL-lkp@intel.com/reproduce)
>
> If you fix the issue in a separate patch/commit (i.e. not just a new version of
> the same patch/commit), kindly add following tags
> | Reported-by: kernel test robot <lkp@intel.com>
> | Closes: https://lore.kernel.org/oe-kbuild-all/202306211545.7b6CdqsL-lkp@intel.com/
>
> All warnings (new ones prefixed by >>):
Okay, you even haven't compiled your code :-(
This should probably use one of the functions from bitfield.h.
Like u32_encode_bits().
> >> drivers/iio/adc/max14001.c:135:13: warning: result of comparison of constant 18446744073709551615 with expression of type 'typeof (_Generic((mask), char: (unsigned char)0, unsigned char: (unsigned char)0, signed char: (unsigned char)0, unsigned short: (unsigned short)0, short: (unsigned short)0, unsigned int: (unsigned int)0, int: (unsigned int)0, unsigned long: (unsigned long)0, long: (unsigned long)0, unsigned long long: (unsigned long long)0, long long: (unsigned long long)0, default: (mask)))' (aka 'unsigned int') is always false [-Wtautological-constant-out-of-range-compare]
> reg_data = FIELD_PREP(mask, val);
> ^~~~~~~~~~~~~~~~~~~~~
> include/linux/bitfield.h:114:3: note: expanded from macro 'FIELD_PREP'
> __BF_FIELD_CHECK(_mask, 0ULL, _val, "FIELD_PREP: "); \
> ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> include/linux/bitfield.h:71:53: note: expanded from macro '__BF_FIELD_CHECK'
> BUILD_BUG_ON_MSG(__bf_cast_unsigned(_mask, _mask) > \
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~
> include/linux/build_bug.h:39:58: note: expanded from macro 'BUILD_BUG_ON_MSG'
> #define BUILD_BUG_ON_MSG(cond, msg) compiletime_assert(!(cond), msg)
> ~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~
> include/linux/compiler_types.h:397:22: note: expanded from macro 'compiletime_assert'
> _compiletime_assert(condition, msg, __compiletime_assert_, __COUNTER__)
> ~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> include/linux/compiler_types.h:385:23: note: expanded from macro '_compiletime_assert'
> __compiletime_assert(condition, msg, prefix, suffix)
> ~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> include/linux/compiler_types.h:377:9: note: expanded from macro '__compiletime_assert'
> if (!(condition)) \
> ^~~~~~~~~
> 1 warning generated.
>
>
> vim +135 drivers/iio/adc/max14001.c
>
> 117
> 118 static int max14001_reg_update(struct max14001_state *st,
> 119 unsigned int reg_addr,
> 120 unsigned int mask,
> 121 unsigned int val)
> 122 {
> 123 int ret;
> 124 unsigned int reg_data;
> 125
> 126 /* Enable SPI Registers Write */
> 127 ret = max14001_write(st, MAX14001_WEN, MAX14001_WRITE_WEN);
> 128 if (ret)
> 129 return ret;
> 130
> 131 ret = max14001_read(st, reg_addr, ®_data);
> 132 if (ret)
> 133 return ret;
> 134
> > 135 reg_data = FIELD_PREP(mask, val);
> 136
> 137 ret = max14001_write(st, reg_addr, reg_data);
> 138 if (ret)
> 139 return ret;
> 140
> 141 /* Write Verification Register */
> 142 ret = max14001_write_verification_reg(st, reg_addr);
> 143 if (ret)
> 144 return ret;
> 145
> 146 /* Disable SPI Registers Write */
> 147 return max14001_write(st, MAX14001_WEN, 0);
> 148 }
> 149
>
> --
> 0-DAY CI Kernel Test Service
> https://github.com/intel/lkp-tests/wiki
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 10+ messages in thread
* RE: [jic23-iio:testing 6/10] drivers/iio/adc/max14001.c:135:13: warning: result of comparison of constant 18446744073709551615 with expression of type 'typeof (_Generic((mask), char: (unsigned char)0, unsigned char: (unsigned char)0, signed char: (unsi...
2023-06-21 8:25 ` Andy Shevchenko
@ 2023-06-21 8:58 ` Paller, Kim Seer
2023-06-21 12:05 ` Jonathan Cameron
2023-07-20 9:29 ` [jic23-iio:testing 6/10] drivers/iio/adc/max14001.c:135:13: warning: result of comparison of constant 18446744073709551615 with expression of type 'typeof (_Generic((mask), char: (unsigned char)0, unsigned char: (unsigned char)0, signed char: (unsigned char)0, unsigned short: (un Arnd Bergmann
1 sibling, 1 reply; 10+ messages in thread
From: Paller, Kim Seer @ 2023-06-21 8:58 UTC (permalink / raw)
To: Andy Shevchenko
Cc: llvm@lists.linux.dev, oe-kbuild-all@lists.linux.dev,
Jonathan Cameron, kernel test robot
> -----Original Message-----
> From: Andy Shevchenko <andy.shevchenko@gmail.com>
> Sent: Wednesday, June 21, 2023 4:25 PM
> To: kernel test robot <lkp@intel.com>
> Cc: Paller, Kim Seer <KimSeer.Paller@analog.com>; llvm@lists.linux.dev; oe-
> kbuild-all@lists.linux.dev; Jonathan Cameron
> <Jonathan.Cameron@huawei.com>
> Subject: Re: [jic23-iio:testing 6/10] drivers/iio/adc/max14001.c:135:13:
> warning: result of comparison of constant 18446744073709551615 with
> expression of type 'typeof (_Generic((mask), char: (unsigned char)0, unsigned
> char: (unsigned char)0, signed char: (unsi...
>
> [External]
>
> On Wed, Jun 21, 2023 at 10:19 AM kernel test robot <lkp@intel.com> wrote:
> >
> > tree:
> https://urldefense.com/v3/__https://git.kernel.org/pub/scm/linux/kernel/git/ji
> c23/iio.git__;!!A3Ni8CS0y2Y!45o_-MMr4xq4e_9PWpK-sQ_qHBbFbbS7Q2J-
> fNmTvSPAQXjYhpLYDteGHSeWEbdIAv364HiQBQy2tXMdnz3oesPJvyDEVg$
> testing
> > head: 25e201cc6ff270abc062e13ff912292097cb2827
> > commit: d3e93b67f934a477c5851d575a2278f07c6242fb [6/10] iio: adc:
> > max14001: New driver
> > config: x86_64-allyesconfig
> > (https://urldefense.com/v3/__https://download.01.org/0day-ci/archive/2
> > 0230621/202306211545.7b6CdqsL-
> lkp@intel.com/config__;!!A3Ni8CS0y2Y!45o
> > _-MMr4xq4e_9PWpK-sQ_qHBbFbbS7Q2J-
> fNmTvSPAQXjYhpLYDteGHSeWEbdIAv364HiQB
> > Qy2tXMdnz3oesOgKhx9ZQ$ )
> > compiler: clang version 15.0.7
> > (https://urldefense.com/v3/__https://github.com/llvm/llvm-project.git_
> > _;!!A3Ni8CS0y2Y!45o_-MMr4xq4e_9PWpK-sQ_qHBbFbbS7Q2J-
> fNmTvSPAQXjYhpLYDt
> > eGHSeWEbdIAv364HiQBQy2tXMdnz3oesOx97mL0Q$
> > 8dfdcc7b7bf66834a761bd8de445840ef68e4d1a)
> > reproduce:
> > (https://urldefense.com/v3/__https://download.01.org/0day-ci/archive/2
> > 0230621/202306211545.7b6CdqsL-
> lkp@intel.com/reproduce__;!!A3Ni8CS0y2Y!
> > 45o_-MMr4xq4e_9PWpK-sQ_qHBbFbbS7Q2J-
> fNmTvSPAQXjYhpLYDteGHSeWEbdIAv364H
> > iQBQy2tXMdnz3oesODMiAFrg$ )
> >
> > If you fix the issue in a separate patch/commit (i.e. not just a new
> > version of the same patch/commit), kindly add following tags
> > | Reported-by: kernel test robot <lkp@intel.com>
> > | Closes:
> > | https://urldefense.com/v3/__https://lore.kernel.org/oe-kbuild-all/20
> > | 2306211545.7b6CdqsL-lkp@intel.com/__;!!A3Ni8CS0y2Y!45o_-
> MMr4xq4e_9PW
> > | pK-sQ_qHBbFbbS7Q2J-
> fNmTvSPAQXjYhpLYDteGHSeWEbdIAv364HiQBQy2tXMdnz3oe
> > | sOVGB0hTQ$
> >
> > All warnings (new ones prefixed by >>):
>
> Okay, you even haven't compiled your code :-( This should probably use one of
> the functions from bitfield.h.
> Like u32_encode_bits().
I wasn’t able to encounter and trigger this kind of warning in my build. I built
and tested the code with rpi4 and linux kernel source tree before sending the patch.
Perhaps I missed something. I will check and try to resolve this warning.
Thanks and best regards,
Kim Seer Paller
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [jic23-iio:testing 6/10] drivers/iio/adc/max14001.c:135:13: warning: result of comparison of constant 18446744073709551615 with expression of type 'typeof (_Generic((mask), char: (unsigned char)0, unsigned char: (unsigned char)0, signed char: (unsi...
2023-06-21 8:58 ` [jic23-iio:testing 6/10] drivers/iio/adc/max14001.c:135:13: warning: result of comparison of constant 18446744073709551615 with expression of type 'typeof (_Generic((mask), char: (unsigned char)0, unsigned char: (unsigned char)0, signed char: (unsi Paller, Kim Seer
@ 2023-06-21 12:05 ` Jonathan Cameron
2023-06-22 12:52 ` Paller, Kim Seer
2023-07-21 8:38 ` Arnd Bergmann
0 siblings, 2 replies; 10+ messages in thread
From: Jonathan Cameron @ 2023-06-21 12:05 UTC (permalink / raw)
To: Paller, Kim Seer
Cc: Andy Shevchenko, llvm@lists.linux.dev,
oe-kbuild-all@lists.linux.dev, kernel test robot
On Wed, 21 Jun 2023 08:58:47 +0000
"Paller, Kim Seer" <KimSeer.Paller@analog.com> wrote:
> > -----Original Message-----
> > From: Andy Shevchenko <andy.shevchenko@gmail.com>
> > Sent: Wednesday, June 21, 2023 4:25 PM
> > To: kernel test robot <lkp@intel.com>
> > Cc: Paller, Kim Seer <KimSeer.Paller@analog.com>; llvm@lists.linux.dev; oe-
> > kbuild-all@lists.linux.dev; Jonathan Cameron
> > <Jonathan.Cameron@huawei.com>
> > Subject: Re: [jic23-iio:testing 6/10] drivers/iio/adc/max14001.c:135:13:
> > warning: result of comparison of constant 18446744073709551615 with
> > expression of type 'typeof (_Generic((mask), char: (unsigned char)0, unsigned
> > char: (unsigned char)0, signed char: (unsi...
> >
> > [External]
> >
> > On Wed, Jun 21, 2023 at 10:19 AM kernel test robot <lkp@intel.com> wrote:
> > >
> > > tree:
> > https://urldefense.com/v3/__https://git.kernel.org/pub/scm/linux/kernel/git/ji
> > c23/iio.git__;!!A3Ni8CS0y2Y!45o_-MMr4xq4e_9PWpK-sQ_qHBbFbbS7Q2J-
> > fNmTvSPAQXjYhpLYDteGHSeWEbdIAv364HiQBQy2tXMdnz3oesPJvyDEVg$
> > testing
> > > head: 25e201cc6ff270abc062e13ff912292097cb2827
> > > commit: d3e93b67f934a477c5851d575a2278f07c6242fb [6/10] iio: adc:
> > > max14001: New driver
> > > config: x86_64-allyesconfig
> > > (https://urldefense.com/v3/__https://download.01.org/0day-ci/archive/2
> > > 0230621/202306211545.7b6CdqsL-
> > lkp@intel.com/config__;!!A3Ni8CS0y2Y!45o
> > > _-MMr4xq4e_9PWpK-sQ_qHBbFbbS7Q2J-
> > fNmTvSPAQXjYhpLYDteGHSeWEbdIAv364HiQB
> > > Qy2tXMdnz3oesOgKhx9ZQ$ )
> > > compiler: clang version 15.0.7
> > > (https://urldefense.com/v3/__https://github.com/llvm/llvm-project.git_
> > > _;!!A3Ni8CS0y2Y!45o_-MMr4xq4e_9PWpK-sQ_qHBbFbbS7Q2J-
> > fNmTvSPAQXjYhpLYDt
> > > eGHSeWEbdIAv364HiQBQy2tXMdnz3oesOx97mL0Q$
> > > 8dfdcc7b7bf66834a761bd8de445840ef68e4d1a)
> > > reproduce:
> > > (https://urldefense.com/v3/__https://download.01.org/0day-ci/archive/2
> > > 0230621/202306211545.7b6CdqsL-
> > lkp@intel.com/reproduce__;!!A3Ni8CS0y2Y!
> > > 45o_-MMr4xq4e_9PWpK-sQ_qHBbFbbS7Q2J-
> > fNmTvSPAQXjYhpLYDteGHSeWEbdIAv364H
> > > iQBQy2tXMdnz3oesODMiAFrg$ )
> > >
> > > If you fix the issue in a separate patch/commit (i.e. not just a new
> > > version of the same patch/commit), kindly add following tags
> > > | Reported-by: kernel test robot <lkp@intel.com>
> > > | Closes:
> > > | https://urldefense.com/v3/__https://lore.kernel.org/oe-kbuild-all/20
> > > | 2306211545.7b6CdqsL-lkp@intel.com/__;!!A3Ni8CS0y2Y!45o_-
> > MMr4xq4e_9PW
> > > | pK-sQ_qHBbFbbS7Q2J-
> > fNmTvSPAQXjYhpLYDteGHSeWEbdIAv364HiQBQy2tXMdnz3oe
> > > | sOVGB0hTQ$
> > >
> > > All warnings (new ones prefixed by >>):
> >
> > Okay, you even haven't compiled your code :-( This should probably use one of
> > the functions from bitfield.h.
> > Like u32_encode_bits().
>
> I wasn’t able to encounter and trigger this kind of warning in my build. I built
> and tested the code with rpi4 and linux kernel source tree before sending the patch.
> Perhaps I missed something. I will check and try to resolve this warning.
Also passed my (admittedly limited these days as 0-day does such a good job) local
build tests.
I guess some / most compilers could see it is constant, but a less observant
one apparently doesn't.
It's only called from one place, I'd just put the code inline so that the
constant nature of that variable is explicit. Or pass in the FIELD_PREP()
value rather than computing it in the function.
Send a new version and I'll switch it in for the one in the tree currently.
However, it looks like that code was meant to do a read modify write cycle and
doesn't use the value read. So probably a bug there anyway.
Thanks,
Jonathan
>
> Thanks and best regards,
> Kim Seer Paller
>
>
>
^ permalink raw reply [flat|nested] 10+ messages in thread
* RE: [jic23-iio:testing 6/10] drivers/iio/adc/max14001.c:135:13: warning: result of comparison of constant 18446744073709551615 with expression of type 'typeof (_Generic((mask), char: (unsigned char)0, unsigned char: (unsigned char)0, signed char: (unsi...
2023-06-21 12:05 ` Jonathan Cameron
@ 2023-06-22 12:52 ` Paller, Kim Seer
2023-07-21 8:38 ` Arnd Bergmann
1 sibling, 0 replies; 10+ messages in thread
From: Paller, Kim Seer @ 2023-06-22 12:52 UTC (permalink / raw)
To: Jonathan Cameron
Cc: Andy Shevchenko, llvm@lists.linux.dev,
oe-kbuild-all@lists.linux.dev, kernel test robot
> -----Original Message-----
> From: Jonathan Cameron <Jonathan.Cameron@Huawei.com>
> Sent: Wednesday, June 21, 2023 8:06 PM
> To: Paller, Kim Seer <KimSeer.Paller@analog.com>
> Cc: Andy Shevchenko <andy.shevchenko@gmail.com>; llvm@lists.linux.dev; oe-
> kbuild-all@lists.linux.dev; kernel test robot <lkp@intel.com>
> Subject: Re: [jic23-iio:testing 6/10] drivers/iio/adc/max14001.c:135:13:
> warning: result of comparison of constant 18446744073709551615 with
> expression of type 'typeof (_Generic((mask), char: (unsigned char)0, unsigned
> char: (unsigned char)0, signed char: (unsi...
>
> [External]
>
> On Wed, 21 Jun 2023 08:58:47 +0000
> "Paller, Kim Seer" <KimSeer.Paller@analog.com> wrote:
>
> > > -----Original Message-----
> > > From: Andy Shevchenko <andy.shevchenko@gmail.com>
> > > Sent: Wednesday, June 21, 2023 4:25 PM
> > > To: kernel test robot <lkp@intel.com>
> > > Cc: Paller, Kim Seer <KimSeer.Paller@analog.com>;
> > > llvm@lists.linux.dev; oe- kbuild-all@lists.linux.dev; Jonathan
> > > Cameron <Jonathan.Cameron@huawei.com>
> > > Subject: Re: [jic23-iio:testing 6/10] drivers/iio/adc/max14001.c:135:13:
> > > warning: result of comparison of constant 18446744073709551615 with
> > > expression of type 'typeof (_Generic((mask), char: (unsigned char)0,
> > > unsigned
> > > char: (unsigned char)0, signed char: (unsi...
> > >
> > > [External]
> > >
> > > On Wed, Jun 21, 2023 at 10:19 AM kernel test robot <lkp@intel.com>
> wrote:
> > > >
> > > > tree:
> > > https://urldefense.com/v3/__https://git.kernel.org/pub/scm/linux/ker
> > > nel/git/ji
> > > c23/iio.git__;!!A3Ni8CS0y2Y!45o_-MMr4xq4e_9PWpK-sQ_qHBbFbbS7Q2J-
> > > fNmTvSPAQXjYhpLYDteGHSeWEbdIAv364HiQBQy2tXMdnz3oesPJvyDEVg$
> > > testing
> > > > head: 25e201cc6ff270abc062e13ff912292097cb2827
> > > > commit: d3e93b67f934a477c5851d575a2278f07c6242fb [6/10] iio: adc:
> > > > max14001: New driver
> > > > config: x86_64-allyesconfig
> > > > (https://urldefense.com/v3/__https://download.01.org/0day-ci/archi
> > > > ve/2
> > > > 0230621/202306211545.7b6CdqsL-
> > > lkp@intel.com/config__;!!A3Ni8CS0y2Y!45o
> > > > _-MMr4xq4e_9PWpK-sQ_qHBbFbbS7Q2J-
> > > fNmTvSPAQXjYhpLYDteGHSeWEbdIAv364HiQB
> > > > Qy2tXMdnz3oesOgKhx9ZQ$ )
> > > > compiler: clang version 15.0.7
> > > > (https://urldefense.com/v3/__https://github.com/llvm/llvm-project.
> > > > git_
> > > > _;!!A3Ni8CS0y2Y!45o_-MMr4xq4e_9PWpK-sQ_qHBbFbbS7Q2J-
> > > fNmTvSPAQXjYhpLYDt
> > > > eGHSeWEbdIAv364HiQBQy2tXMdnz3oesOx97mL0Q$
> > > > 8dfdcc7b7bf66834a761bd8de445840ef68e4d1a)
> > > > reproduce:
> > > > (https://urldefense.com/v3/__https://download.01.org/0day-ci/archi
> > > > ve/2
> > > > 0230621/202306211545.7b6CdqsL-
> > > lkp@intel.com/reproduce__;!!A3Ni8CS0y2Y!
> > > > 45o_-MMr4xq4e_9PWpK-sQ_qHBbFbbS7Q2J-
> > > fNmTvSPAQXjYhpLYDteGHSeWEbdIAv364H
> > > > iQBQy2tXMdnz3oesODMiAFrg$ )
> > > >
> > > > If you fix the issue in a separate patch/commit (i.e. not just a
> > > > new version of the same patch/commit), kindly add following tags
> > > > | Reported-by: kernel test robot <lkp@intel.com>
> > > > | Closes:
> > > > | https://urldefense.com/v3/__https://lore.kernel.org/oe-kbuild-al
> > > > | l/20
> > > > | 2306211545.7b6CdqsL-lkp@intel.com/__;!!A3Ni8CS0y2Y!45o_-
> > > MMr4xq4e_9PW
> > > > | pK-sQ_qHBbFbbS7Q2J-
> > > fNmTvSPAQXjYhpLYDteGHSeWEbdIAv364HiQBQy2tXMdnz3oe
> > > > | sOVGB0hTQ$
> > > >
> > > > All warnings (new ones prefixed by >>):
> > >
> > > Okay, you even haven't compiled your code :-( This should probably
> > > use one of the functions from bitfield.h.
> > > Like u32_encode_bits().
> >
> > I wasn’t able to encounter and trigger this kind of warning in my
> > build. I built and tested the code with rpi4 and linux kernel source tree before
> sending the patch.
> > Perhaps I missed something. I will check and try to resolve this warning.
>
> Also passed my (admittedly limited these days as 0-day does such a good job)
> local build tests.
> I guess some / most compilers could see it is constant, but a less observant one
> apparently doesn't.
>
> It's only called from one place, I'd just put the code inline so that the constant
> nature of that variable is explicit. Or pass in the FIELD_PREP() value rather than
> computing it in the function.
>
> Send a new version and I'll switch it in for the one in the tree currently.
>
> However, it looks like that code was meant to do a read modify write cycle and
> doesn't use the value read. So probably a bug there anyway.
I think I found the problem, the code directly assign a bit without retaining the
cfg reg default value. There should be a bitwise OR in the operands. This might
resolve the warning. However, I found it difficult to replicate the build process of 0-day.
I will send the new version later.
Thanks and best regards,
Kim Seer Paller
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [jic23-iio:testing 6/10] drivers/iio/adc/max14001.c:135:13: warning: result of comparison of constant 18446744073709551615 with expression of type 'typeof (_Generic((mask), char: (unsigned char)0, unsigned char: (unsigned char)0, signed char: (unsigned char)0, unsigned short: (un...
2023-06-21 8:25 ` Andy Shevchenko
2023-06-21 8:58 ` [jic23-iio:testing 6/10] drivers/iio/adc/max14001.c:135:13: warning: result of comparison of constant 18446744073709551615 with expression of type 'typeof (_Generic((mask), char: (unsigned char)0, unsigned char: (unsigned char)0, signed char: (unsi Paller, Kim Seer
@ 2023-07-20 9:29 ` Arnd Bergmann
2023-07-20 18:18 ` Jonathan Cameron
1 sibling, 1 reply; 10+ messages in thread
From: Arnd Bergmann @ 2023-07-20 9:29 UTC (permalink / raw)
To: Andy Shevchenko, kernel test robot
Cc: Kim Seer Paller, llvm, oe-kbuild-all, Jonathan Cameron
On Wed, Jun 21, 2023, at 10:25, Andy Shevchenko wrote:
> On Wed, Jun 21, 2023 at 10:19 AM kernel test robot <lkp@intel.com> wrote:
>>
>> tree: https://git.kernel.org/pub/scm/linux/kernel/git/jic23/iio.git testing
>> head: 25e201cc6ff270abc062e13ff912292097cb2827
>> commit: d3e93b67f934a477c5851d575a2278f07c6242fb [6/10] iio: adc: max14001: New driver
>> config: x86_64-allyesconfig (https://download.01.org/0day-ci/archive/20230621/202306211545.7b6CdqsL-lkp@intel.com/config)
>> compiler: clang version 15.0.7 (https://github.com/llvm/llvm-project.git 8dfdcc7b7bf66834a761bd8de445840ef68e4d1a)
>> reproduce: (https://download.01.org/0day-ci/archive/20230621/202306211545.7b6CdqsL-lkp@intel.com/reproduce)
>>
>> If you fix the issue in a separate patch/commit (i.e. not just a new version of
>> the same patch/commit), kindly add following tags
>> | Reported-by: kernel test robot <lkp@intel.com>
>> | Closes: https://lore.kernel.org/oe-kbuild-all/202306211545.7b6CdqsL-lkp@intel.com/
>>
>> All warnings (new ones prefixed by >>):
>
> Okay, you even haven't compiled your code :-(
> This should probably use one of the functions from bitfield.h.
> Like u32_encode_bits().
I see the warning is now in linux-next. I see it only shows up with
clang and not gcc, but it would be nice to address it.
>
>> >> drivers/iio/adc/max14001.c:135:13: warning: result of comparison of constant 18446744073709551615 with expression of type 'typeof (_Generic((mask), char: (unsigned char)0, unsigned char: (unsigned char)0, signed char: (unsigned char)0, unsigned short: (unsigned short)0, short: (unsigned short)0, unsigned int: (unsigned int)0, int: (unsigned int)0, unsigned long: (unsigned long)0, long: (unsigned long)0, unsigned long long: (unsigned long long)0, long long: (unsigned long long)0, default: (mask)))' (aka 'unsigned int') is always false [-Wtautological-constant-out-of-range-compare]
>> reg_data = FIELD_PREP(mask, val);
>> ^~~~~~~~~~~~~~~~~~~~~
>> include/linux/bitfield.h:114:3: note: expanded from macro 'FIELD_PREP'
>> __BF_FIELD_CHECK(_mask, 0ULL, _val, "FIELD_PREP: "); \
>> ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>> include/linux/bitfield.h:71:53: note: expanded from macro '__BF_FIELD_CHECK'
>> BUILD_BUG_ON_MSG(__bf_cast_unsigned(_mask, _mask) > \
>> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~
>> include/linux/build_bug.h:39:58: note: expanded from macro 'BUILD_BUG_ON_MSG'
>> #define BUILD_BUG_ON_MSG(cond, msg) compiletime_assert(!(cond), msg)
>> ~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~
>> include/linux/compiler_types.h:397:22: note: expanded from macro 'compiletime_assert'
>> _compiletime_assert(condition, msg, __compiletime_assert_, __COUNTER__)
>> ~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>> include/linux/compiler_types.h:385:23: note: expanded from macro '_compiletime_assert'
>> __compiletime_assert(condition, msg, prefix, suffix)
>> ~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>> include/linux/compiler_types.h:377:9: note: expanded from macro '__compiletime_assert'
>> if (!(condition)) \
>> ^~~~~~~~~
>> 1 warning generated.
It looks like the problem is the use of FIELD_PREP() with a variable
'val' instead of a constant. I tried marking the function __always_inline
so the compiler can see the actual value ('1') that gets passed in
as a constant, but that did not change anything.
It also looks suspicious that the value first gets read from the
register and then replaced with the FIELD_PREP() output, while the
original value gets discarded. Is this intentional?
ret = max14001_read(st, reg_addr, ®_data);
if (ret)
return ret;
reg_data = FIELD_PREP(mask, val);
ret = max14001_write(st, reg_addr, reg_data);
I have managed to shut up the warning by rearranging the code like:
diff --git a/drivers/iio/adc/max14001.c b/drivers/iio/adc/max14001.c
index 18ace09601985..f2ce8f8947982 100644
--- a/drivers/iio/adc/max14001.c
+++ b/drivers/iio/adc/max14001.c
@@ -117,11 +117,9 @@ static int max14001_write_verification_reg(struct max14001_state *st,
static int max14001_reg_update(struct max14001_state *st,
unsigned int reg_addr,
- unsigned int mask,
- unsigned int val)
+ unsigned int reg_data)
{
int ret;
- unsigned int reg_data;
/* Enable SPI Registers Write */
ret = max14001_write(st, MAX14001_WEN, MAX14001_WRITE_WEN);
@@ -132,8 +130,6 @@ static int max14001_reg_update(struct max14001_state *st,
if (ret)
return ret;
- reg_data = FIELD_PREP(mask, val);
-
ret = max14001_write(st, reg_addr, reg_data);
if (ret)
return ret;
@@ -299,7 +295,7 @@ static int max14001_probe(struct spi_device *spi)
/* select external voltage reference source for the ADC */
ret = max14001_reg_update(st, MAX14001_CFG,
- MAX14001_CFG_EXRF, 1);
+ FIELD_PREP(MAX14001_CFG_EXRF, 1));
if (ret < 0)
return ret;
but it looks like there is still a bug in max14001_reg_update(),
so I'd prefer Kim Seer Paller to revisit this issue and submit
a properly tested patch.
Arnd
^ permalink raw reply related [flat|nested] 10+ messages in thread
* Re: [jic23-iio:testing 6/10] drivers/iio/adc/max14001.c:135:13: warning: result of comparison of constant 18446744073709551615 with expression of type 'typeof (_Generic((mask), char: (unsigned char)0, unsigned char: (unsigned char)0, signed char: (unsigned char)0, unsigned short: (un...
2023-07-20 9:29 ` [jic23-iio:testing 6/10] drivers/iio/adc/max14001.c:135:13: warning: result of comparison of constant 18446744073709551615 with expression of type 'typeof (_Generic((mask), char: (unsigned char)0, unsigned char: (unsigned char)0, signed char: (unsigned char)0, unsigned short: (un Arnd Bergmann
@ 2023-07-20 18:18 ` Jonathan Cameron
2023-07-20 18:22 ` Jonathan Cameron
2023-07-21 7:36 ` [jic23-iio:testing 6/10] drivers/iio/adc/max14001.c:135:13: warning: result of comparison of constant 18446744073709551615 with expression of type 'typeof (_Generic((mask), char: (unsigned char)0, unsigned char: (unsigned char)0, signed char: (unsi Paller, Kim Seer
0 siblings, 2 replies; 10+ messages in thread
From: Jonathan Cameron @ 2023-07-20 18:18 UTC (permalink / raw)
To: Arnd Bergmann
Cc: Andy Shevchenko, kernel test robot, Kim Seer Paller, llvm,
oe-kbuild-all, Jonathan Cameron, linux-iio
On Thu, 20 Jul 2023 11:29:55 +0200
"Arnd Bergmann" <arnd@arndb.de> wrote:
> On Wed, Jun 21, 2023, at 10:25, Andy Shevchenko wrote:
> > On Wed, Jun 21, 2023 at 10:19 AM kernel test robot <lkp@intel.com> wrote:
> >>
> >> tree: https://git.kernel.org/pub/scm/linux/kernel/git/jic23/iio.git testing
> >> head: 25e201cc6ff270abc062e13ff912292097cb2827
> >> commit: d3e93b67f934a477c5851d575a2278f07c6242fb [6/10] iio: adc: max14001: New driver
> >> config: x86_64-allyesconfig (https://download.01.org/0day-ci/archive/20230621/202306211545.7b6CdqsL-lkp@intel.com/config)
> >> compiler: clang version 15.0.7 (https://github.com/llvm/llvm-project.git 8dfdcc7b7bf66834a761bd8de445840ef68e4d1a)
> >> reproduce: (https://download.01.org/0day-ci/archive/20230621/202306211545.7b6CdqsL-lkp@intel.com/reproduce)
> >>
> >> If you fix the issue in a separate patch/commit (i.e. not just a new version of
> >> the same patch/commit), kindly add following tags
> >> | Reported-by: kernel test robot <lkp@intel.com>
> >> | Closes: https://lore.kernel.org/oe-kbuild-all/202306211545.7b6CdqsL-lkp@intel.com/
> >>
> >> All warnings (new ones prefixed by >>):
> >
> > Okay, you even haven't compiled your code :-(
> > This should probably use one of the functions from bitfield.h.
> > Like u32_encode_bits().
>
> I see the warning is now in linux-next. I see it only shows up with
> clang and not gcc, but it would be nice to address it.
Sorry, I managed to forget this one was still outstanding and picked up the driver.
>
> >
> >> >> drivers/iio/adc/max14001.c:135:13: warning: result of comparison of constant 18446744073709551615 with expression of type 'typeof (_Generic((mask), char: (unsigned char)0, unsigned char: (unsigned char)0, signed char: (unsigned char)0, unsigned short: (unsigned short)0, short: (unsigned short)0, unsigned int: (unsigned int)0, int: (unsigned int)0, unsigned long: (unsigned long)0, long: (unsigned long)0, unsigned long long: (unsigned long long)0, long long: (unsigned long long)0, default: (mask)))' (aka 'unsigned int') is always false [-Wtautological-constant-out-of-range-compare]
> >> reg_data = FIELD_PREP(mask, val);
> >> ^~~~~~~~~~~~~~~~~~~~~
> >> include/linux/bitfield.h:114:3: note: expanded from macro 'FIELD_PREP'
> >> __BF_FIELD_CHECK(_mask, 0ULL, _val, "FIELD_PREP: "); \
> >> ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> >> include/linux/bitfield.h:71:53: note: expanded from macro '__BF_FIELD_CHECK'
> >> BUILD_BUG_ON_MSG(__bf_cast_unsigned(_mask, _mask) > \
> >> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~
> >> include/linux/build_bug.h:39:58: note: expanded from macro 'BUILD_BUG_ON_MSG'
> >> #define BUILD_BUG_ON_MSG(cond, msg) compiletime_assert(!(cond), msg)
> >> ~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~
> >> include/linux/compiler_types.h:397:22: note: expanded from macro 'compiletime_assert'
> >> _compiletime_assert(condition, msg, __compiletime_assert_, __COUNTER__)
> >> ~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> >> include/linux/compiler_types.h:385:23: note: expanded from macro '_compiletime_assert'
> >> __compiletime_assert(condition, msg, prefix, suffix)
> >> ~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> >> include/linux/compiler_types.h:377:9: note: expanded from macro '__compiletime_assert'
> >> if (!(condition)) \
> >> ^~~~~~~~~
> >> 1 warning generated.
>
> It looks like the problem is the use of FIELD_PREP() with a variable
> 'val' instead of a constant. I tried marking the function __always_inline
> so the compiler can see the actual value ('1') that gets passed in
> as a constant, but that did not change anything.
>
>
> It also looks suspicious that the value first gets read from the
> register and then replaced with the FIELD_PREP() output, while the
> original value gets discarded. Is this intentional?
There are a lot of other fields in that register, so unlikely this was the intent.
A number of them default to non 0 as well.
>
> ret = max14001_read(st, reg_addr, ®_data);
> if (ret)
> return ret;
> reg_data = FIELD_PREP(mask, val);
> ret = max14001_write(st, reg_addr, reg_data);
>
>
> I have managed to shut up the warning by rearranging the code like:
>
> diff --git a/drivers/iio/adc/max14001.c b/drivers/iio/adc/max14001.c
> index 18ace09601985..f2ce8f8947982 100644
> --- a/drivers/iio/adc/max14001.c
> +++ b/drivers/iio/adc/max14001.c
> @@ -117,11 +117,9 @@ static int max14001_write_verification_reg(struct max14001_state *st,
>
> static int max14001_reg_update(struct max14001_state *st,
> unsigned int reg_addr,
> - unsigned int mask,
> - unsigned int val)
> + unsigned int reg_data)
> {
> int ret;
> - unsigned int reg_data;
>
> /* Enable SPI Registers Write */
> ret = max14001_write(st, MAX14001_WEN, MAX14001_WRITE_WEN);
> @@ -132,8 +130,6 @@ static int max14001_reg_update(struct max14001_state *st,
> if (ret)
> return ret;
>
> - reg_data = FIELD_PREP(mask, val);
> -
> ret = max14001_write(st, reg_addr, reg_data);
> if (ret)
> return ret;
> @@ -299,7 +295,7 @@ static int max14001_probe(struct spi_device *spi)
>
> /* select external voltage reference source for the ADC */
> ret = max14001_reg_update(st, MAX14001_CFG,
> - MAX14001_CFG_EXRF, 1);
> + FIELD_PREP(MAX14001_CFG_EXRF, 1));
>
> if (ret < 0)
> return ret;
I'd prefer to just drop this reg_update function entirely. Put the call inline
so that we can use FIELD_PREP() directly rather than (after fixing the probably bug)
passing in both the value and the mask.
>
> but it looks like there is still a bug in max14001_reg_update(),
> so I'd prefer Kim Seer Paller to revisit this issue and submit
> a properly tested patch.
Absolutely agree. If it's outstanding in few weeks though we can go
with an educated 'guess' for the fix but I'd really rather not if Kim
can post a fix in the meantime.
Jonathan
>
> Arnd
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [jic23-iio:testing 6/10] drivers/iio/adc/max14001.c:135:13: warning: result of comparison of constant 18446744073709551615 with expression of type 'typeof (_Generic((mask), char: (unsigned char)0, unsigned char: (unsigned char)0, signed char: (unsigned char)0, unsigned short: (un...
2023-07-20 18:18 ` Jonathan Cameron
@ 2023-07-20 18:22 ` Jonathan Cameron
2023-07-21 7:36 ` [jic23-iio:testing 6/10] drivers/iio/adc/max14001.c:135:13: warning: result of comparison of constant 18446744073709551615 with expression of type 'typeof (_Generic((mask), char: (unsigned char)0, unsigned char: (unsigned char)0, signed char: (unsi Paller, Kim Seer
1 sibling, 0 replies; 10+ messages in thread
From: Jonathan Cameron @ 2023-07-20 18:22 UTC (permalink / raw)
To: Arnd Bergmann
Cc: Andy Shevchenko, kernel test robot, Kim Seer Paller, llvm,
oe-kbuild-all, Jonathan Cameron, linux-iio
On Thu, 20 Jul 2023 19:18:38 +0100
Jonathan Cameron <jic23@kernel.org> wrote:
> On Thu, 20 Jul 2023 11:29:55 +0200
> "Arnd Bergmann" <arnd@arndb.de> wrote:
>
> > On Wed, Jun 21, 2023, at 10:25, Andy Shevchenko wrote:
> > > On Wed, Jun 21, 2023 at 10:19 AM kernel test robot <lkp@intel.com> wrote:
> > >>
> > >> tree: https://git.kernel.org/pub/scm/linux/kernel/git/jic23/iio.git testing
> > >> head: 25e201cc6ff270abc062e13ff912292097cb2827
> > >> commit: d3e93b67f934a477c5851d575a2278f07c6242fb [6/10] iio: adc: max14001: New driver
> > >> config: x86_64-allyesconfig (https://download.01.org/0day-ci/archive/20230621/202306211545.7b6CdqsL-lkp@intel.com/config)
> > >> compiler: clang version 15.0.7 (https://github.com/llvm/llvm-project.git 8dfdcc7b7bf66834a761bd8de445840ef68e4d1a)
> > >> reproduce: (https://download.01.org/0day-ci/archive/20230621/202306211545.7b6CdqsL-lkp@intel.com/reproduce)
> > >>
> > >> If you fix the issue in a separate patch/commit (i.e. not just a new version of
> > >> the same patch/commit), kindly add following tags
> > >> | Reported-by: kernel test robot <lkp@intel.com>
> > >> | Closes: https://lore.kernel.org/oe-kbuild-all/202306211545.7b6CdqsL-lkp@intel.com/
> > >>
> > >> All warnings (new ones prefixed by >>):
> > >
> > > Okay, you even haven't compiled your code :-(
> > > This should probably use one of the functions from bitfield.h.
> > > Like u32_encode_bits().
> >
> > I see the warning is now in linux-next. I see it only shows up with
> > clang and not gcc, but it would be nice to address it.
>
> Sorry, I managed to forget this one was still outstanding and picked up the driver.
>
> >
> > >
> > >> >> drivers/iio/adc/max14001.c:135:13: warning: result of comparison of constant 18446744073709551615 with expression of type 'typeof (_Generic((mask), char: (unsigned char)0, unsigned char: (unsigned char)0, signed char: (unsigned char)0, unsigned short: (unsigned short)0, short: (unsigned short)0, unsigned int: (unsigned int)0, int: (unsigned int)0, unsigned long: (unsigned long)0, long: (unsigned long)0, unsigned long long: (unsigned long long)0, long long: (unsigned long long)0, default: (mask)))' (aka 'unsigned int') is always false [-Wtautological-constant-out-of-range-compare]
> > >> reg_data = FIELD_PREP(mask, val);
> > >> ^~~~~~~~~~~~~~~~~~~~~
> > >> include/linux/bitfield.h:114:3: note: expanded from macro 'FIELD_PREP'
> > >> __BF_FIELD_CHECK(_mask, 0ULL, _val, "FIELD_PREP: "); \
> > >> ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> > >> include/linux/bitfield.h:71:53: note: expanded from macro '__BF_FIELD_CHECK'
> > >> BUILD_BUG_ON_MSG(__bf_cast_unsigned(_mask, _mask) > \
> > >> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~
> > >> include/linux/build_bug.h:39:58: note: expanded from macro 'BUILD_BUG_ON_MSG'
> > >> #define BUILD_BUG_ON_MSG(cond, msg) compiletime_assert(!(cond), msg)
> > >> ~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~
> > >> include/linux/compiler_types.h:397:22: note: expanded from macro 'compiletime_assert'
> > >> _compiletime_assert(condition, msg, __compiletime_assert_, __COUNTER__)
> > >> ~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> > >> include/linux/compiler_types.h:385:23: note: expanded from macro '_compiletime_assert'
> > >> __compiletime_assert(condition, msg, prefix, suffix)
> > >> ~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> > >> include/linux/compiler_types.h:377:9: note: expanded from macro '__compiletime_assert'
> > >> if (!(condition)) \
> > >> ^~~~~~~~~
> > >> 1 warning generated.
> >
> > It looks like the problem is the use of FIELD_PREP() with a variable
> > 'val' instead of a constant. I tried marking the function __always_inline
> > so the compiler can see the actual value ('1') that gets passed in
> > as a constant, but that did not change anything.
> >
> >
> > It also looks suspicious that the value first gets read from the
> > register and then replaced with the FIELD_PREP() output, while the
> > original value gets discarded. Is this intentional?
>
> There are a lot of other fields in that register, so unlikely this was the intent.
> A number of them default to non 0 as well.
>
> >
> > ret = max14001_read(st, reg_addr, ®_data);
> > if (ret)
> > return ret;
> > reg_data = FIELD_PREP(mask, val);
> > ret = max14001_write(st, reg_addr, reg_data);
> >
> >
> > I have managed to shut up the warning by rearranging the code like:
> >
> > diff --git a/drivers/iio/adc/max14001.c b/drivers/iio/adc/max14001.c
> > index 18ace09601985..f2ce8f8947982 100644
> > --- a/drivers/iio/adc/max14001.c
> > +++ b/drivers/iio/adc/max14001.c
> > @@ -117,11 +117,9 @@ static int max14001_write_verification_reg(struct max14001_state *st,
> >
> > static int max14001_reg_update(struct max14001_state *st,
> > unsigned int reg_addr,
> > - unsigned int mask,
> > - unsigned int val)
> > + unsigned int reg_data)
> > {
> > int ret;
> > - unsigned int reg_data;
> >
> > /* Enable SPI Registers Write */
> > ret = max14001_write(st, MAX14001_WEN, MAX14001_WRITE_WEN);
> > @@ -132,8 +130,6 @@ static int max14001_reg_update(struct max14001_state *st,
> > if (ret)
> > return ret;
> >
> > - reg_data = FIELD_PREP(mask, val);
> > -
> > ret = max14001_write(st, reg_addr, reg_data);
> > if (ret)
> > return ret;
> > @@ -299,7 +295,7 @@ static int max14001_probe(struct spi_device *spi)
> >
> > /* select external voltage reference source for the ADC */
> > ret = max14001_reg_update(st, MAX14001_CFG,
> > - MAX14001_CFG_EXRF, 1);
> > + FIELD_PREP(MAX14001_CFG_EXRF, 1));
> >
> > if (ret < 0)
> > return ret;
>
> I'd prefer to just drop this reg_update function entirely. Put the call inline
> so that we can use FIELD_PREP() directly rather than (after fixing the probably bug)
> passing in both the value and the mask.
>
> >
> > but it looks like there is still a bug in max14001_reg_update(),
> > so I'd prefer Kim Seer Paller to revisit this issue and submit
> > a properly tested patch.
>
> Absolutely agree. If it's outstanding in few weeks though we can go
> with an educated 'guess' for the fix but I'd really rather not if Kim
> can post a fix in the meantime.
>
On closer inspection of my inbox, there are other reported problems that
need resolving so I'll do a rebase and drop the driver until this stuff is resolved.
Jonathan
> Jonathan
>
> >
> > Arnd
>
^ permalink raw reply [flat|nested] 10+ messages in thread
* RE: [jic23-iio:testing 6/10] drivers/iio/adc/max14001.c:135:13: warning: result of comparison of constant 18446744073709551615 with expression of type 'typeof (_Generic((mask), char: (unsigned char)0, unsigned char: (unsigned char)0, signed char: (unsi...
2023-07-20 18:18 ` Jonathan Cameron
2023-07-20 18:22 ` Jonathan Cameron
@ 2023-07-21 7:36 ` Paller, Kim Seer
1 sibling, 0 replies; 10+ messages in thread
From: Paller, Kim Seer @ 2023-07-21 7:36 UTC (permalink / raw)
To: Jonathan Cameron, Arnd Bergmann
Cc: Andy Shevchenko, kernel test robot, llvm@lists.linux.dev,
oe-kbuild-all@lists.linux.dev, Jonathan Cameron,
linux-iio@vger.kernel.org
>
> I'd prefer to just drop this reg_update function entirely. Put the call inline so
> that we can use FIELD_PREP() directly rather than (after fixing the probably
> bug) passing in both the value and the mask.
>
> >
> > but it looks like there is still a bug in max14001_reg_update(), so
> > I'd prefer Kim Seer Paller to revisit this issue and submit a properly
> > tested patch.
>
> Absolutely agree. If it's outstanding in few weeks though we can go
> with an educated 'guess' for the fix but I'd really rather not if Kim can post a fix
> in the meantime.
Thank you all for your input and feedback. I'm currently working on the fix and
will test it as soon as I have access to the eval boards again. I'll reach out if
something needs to be clarified.
Thanks,
Kim
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [jic23-iio:testing 6/10] drivers/iio/adc/max14001.c:135:13: warning: result of comparison of constant 18446744073709551615 with expression of type 'typeof (_Generic((mask), char: (unsigned char)0, unsigned char: (unsigned char)0, signed char: (unsi...
2023-06-21 12:05 ` Jonathan Cameron
2023-06-22 12:52 ` Paller, Kim Seer
@ 2023-07-21 8:38 ` Arnd Bergmann
1 sibling, 0 replies; 10+ messages in thread
From: Arnd Bergmann @ 2023-07-21 8:38 UTC (permalink / raw)
To: Jonathan Cameron, Kim Seer Paller
Cc: Andy Shevchenko, llvm@lists.linux.dev,
oe-kbuild-all@lists.linux.dev, kernel test robot
On Wed, Jun 21, 2023, at 14:05, Jonathan Cameron wrote:
> It's only called from one place, I'd just put the code inline so that the
> constant nature of that variable is explicit. Or pass in the FIELD_PREP()
> value rather than computing it in the function.
As far as I understand it, clang warnings are intentionally generated
without taking constant-folding across inline functions into account,
in order to be completely reproducible regardless of optimization level,
while gcc generates most warnings after inlining and constant folding
in order to better analyze what actually happens.
Arnd
^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2023-07-21 8:38 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-06-21 7:18 [jic23-iio:testing 6/10] drivers/iio/adc/max14001.c:135:13: warning: result of comparison of constant 18446744073709551615 with expression of type 'typeof (_Generic((mask), char: (unsigned char)0, unsigned char: (unsigned char)0, signed char: (unsigned char)0, unsigned short: (un kernel test robot
2023-06-21 8:25 ` Andy Shevchenko
2023-06-21 8:58 ` [jic23-iio:testing 6/10] drivers/iio/adc/max14001.c:135:13: warning: result of comparison of constant 18446744073709551615 with expression of type 'typeof (_Generic((mask), char: (unsigned char)0, unsigned char: (unsigned char)0, signed char: (unsi Paller, Kim Seer
2023-06-21 12:05 ` Jonathan Cameron
2023-06-22 12:52 ` Paller, Kim Seer
2023-07-21 8:38 ` Arnd Bergmann
2023-07-20 9:29 ` [jic23-iio:testing 6/10] drivers/iio/adc/max14001.c:135:13: warning: result of comparison of constant 18446744073709551615 with expression of type 'typeof (_Generic((mask), char: (unsigned char)0, unsigned char: (unsigned char)0, signed char: (unsigned char)0, unsigned short: (un Arnd Bergmann
2023-07-20 18:18 ` Jonathan Cameron
2023-07-20 18:22 ` Jonathan Cameron
2023-07-21 7:36 ` [jic23-iio:testing 6/10] drivers/iio/adc/max14001.c:135:13: warning: result of comparison of constant 18446744073709551615 with expression of type 'typeof (_Generic((mask), char: (unsigned char)0, unsigned char: (unsigned char)0, signed char: (unsi Paller, Kim Seer
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox