Skip to contentSkip to conversation

drivers/iio/imu/adis16475.c:363 adis16475_set_freq() warn: set_bit() takes a bit number

PATCH In review Dan Carpenter 3 participants 9 messages Nov 6, 2023 IIO

lore
Share & tools
lore
#0 lore raw

PATCH 5/20 drivers/iio/imu/adis16475.c:363 adis16475_set_freq() warn: set_bit() takes a bit number

tree:   https://github.com/alobakin/linux pfcp
head:   89565e300e3d4033b8bb568774804fdc09d4f3cc
commit: 945a0d6e86d97bf60f2fae88ee557ed3eae18b94 [5/20] bitops: let the compiler optimize {__,}assign_bit()
config: i386-randconfig-141-20231105 (https://download.01.org/0day-ci/archive/20231106/[email protected]/config)
compiler: gcc-12 (Debian 12.2.0-14) 12.2.0
reproduce: (https://download.01.org/0day-ci/archive/20231106/[email protected]/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 <[email protected]>
| Reported-by: Dan Carpenter <[email protected]>
| Closes: https://lore.kernel.org/r/[email protected]/

smatch warnings:
drivers/iio/imu/adis16475.c:363 adis16475_set_freq() warn: set_bit() takes a bit number drivers/iio/imu/adis16475.c:363 adis16475_set_freq() warn: clear_bit() takes a bit number drivers/iio/imu/adis16475.c:416 adis16475_set_filter() warn: set_bit() takes a bit number drivers/iio/imu/adis16475.c:416 adis16475_set_filter() warn: clear_bit() takes a bit number

vim +363 drivers/iio/imu/adis16475.c

fff7352bf7a3ce Nuno Sá 2020-04-13  357  
9da1b86865ab43 Nuno Sá 2021-09-20  358  	adis_dev_unlock(&st->adis);
fff7352bf7a3ce Nuno Sá 2020-04-13  359  	/*
fff7352bf7a3ce Nuno Sá 2020-04-13  360  	 * If decimation is used, then gyro and accel data will have meaningful
fff7352bf7a3ce Nuno Sá 2020-04-13  361  	 * bits on the LSB registers. This info is used on the trigger handler.
fff7352bf7a3ce Nuno Sá 2020-04-13  362  	 */

fff7352bf7a3ce Nuno Sá 2020-04-13 @363 assign_bit(ADIS16475_LSB_DEC_MASK, &st->lsb_flag, dec);

assign_bit() takes a bit number like 0. But this is passing BIT(0) so it's like BIT(BIT(0)). Which is fine until you get to 5.

fff7352bf7a3ce Nuno Sá 2020-04-13 364
fff7352bf7a3ce Nuno Sá 2020-04-13 365 return 0;

39c024b51b5607 Nuno Sa 2021-02-18  366  error:
15aacc980dcb32 Nuno Sa 2021-02-18  367  	adis_dev_unlock(&st->adis);
39c024b51b5607 Nuno Sa 2021-02-18  368  	return ret;
Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
#1 lore raw

From: Dan Carpenter <[email protected]>
Date: Mon, 6 Nov 2023 11:50:03 +0300

Hi,

Quoted 27 lines
tree:   https://github.com/alobakin/linux pfcp
head:   89565e300e3d4033b8bb568774804fdc09d4f3cc
commit: 945a0d6e86d97bf60f2fae88ee557ed3eae18b94 [5/20] bitops: let the compiler optimize {__,}assign_bit()
config: i386-randconfig-141-20231105 (https://download.01.org/0day-ci/archive/20231106/[email protected]/config)
compiler: gcc-12 (Debian 12.2.0-14) 12.2.0
reproduce: (https://download.01.org/0day-ci/archive/20231106/[email protected]/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 <[email protected]>
| Reported-by: Dan Carpenter <[email protected]>
| Closes: https://lore.kernel.org/r/[email protected]/

smatch warnings:
drivers/iio/imu/adis16475.c:363 adis16475_set_freq() warn: set_bit() takes a bit number drivers/iio/imu/adis16475.c:363 adis16475_set_freq() warn: clear_bit() takes a bit number drivers/iio/imu/adis16475.c:416 adis16475_set_filter() warn: set_bit() takes a bit number drivers/iio/imu/adis16475.c:416 adis16475_set_filter() warn: clear_bit() takes a bit number

vim +363 drivers/iio/imu/adis16475.c

fff7352bf7a3ce Nuno Sá 2020-04-13  357  
9da1b86865ab43 Nuno Sá 2021-09-20  358  	adis_dev_unlock(&st->adis);
fff7352bf7a3ce Nuno Sá 2020-04-13  359  	/*
fff7352bf7a3ce Nuno Sá 2020-04-13  360  	 * If decimation is used, then gyro and accel data will have meaningful
fff7352bf7a3ce Nuno Sá 2020-04-13  361  	 * bits on the LSB registers. This info is used on the trigger handler.
fff7352bf7a3ce Nuno Sá 2020-04-13  362  	 */
Quoted 4 lines

fff7352bf7a3ce Nuno Sá 2020-04-13 @363 assign_bit(ADIS16475_LSB_DEC_MASK, &st->lsb_flag, dec);

assign_bit() takes a bit number like 0. But this is passing BIT(0) so it's like BIT(BIT(0)). Which is fine until you get to 5.

Is this intended? There are 2 places where you pass %ADIS16475_LSB_DEC_MASK and %ADIS16475_LSB_FIR_MASK, which is BIT(0) and BIT(1) respectively, to assign_bit(), which takes 0, 1 etc.

Quoted 8 lines

fff7352bf7a3ce Nuno Sá 2020-04-13 364
fff7352bf7a3ce Nuno Sá 2020-04-13 365 return 0;

39c024b51b5607 Nuno Sa 2021-02-18  366  error:
15aacc980dcb32 Nuno Sa 2021-02-18  367  	adis_dev_unlock(&st->adis);
39c024b51b5607 Nuno Sa 2021-02-18  368  	return ret;

Thanks,
Olek

#2 lore raw

Hi Olek,

Quoted 46 lines · Alexander Lobakin

From: Dan Carpenter <[email protected]>
Date: Mon, 6 Nov 2023 11:50:03 +0300

Hi,

Quoted 41 lines

tree:   https://github.com/alobakin/linux pfcp
head:   89565e300e3d4033b8bb568774804fdc09d4f3cc
commit: 945a0d6e86d97bf60f2fae88ee557ed3eae18b94 [5/20] bitops: let the compiler optimize {__,}assign_bit()
config: i386-randconfig-141-20231105
(https://download.01.org/0day-ci/archive/20231106/202311060647.i9XyO4ej-lkp@intel
.com/config)
compiler: gcc-12 (Debian 12.2.0-14) 12.2.0
reproduce:
(https://download.01.org/0day-ci/archive/20231106/202311060647.i9XyO4ej-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

Quoted 3 lines

smatch warnings:
drivers/iio/imu/adis16475.c:363 adis16475_set_freq() warn: set_bit() takes a bit number
drivers/iio/imu/adis16475.c:363 adis16475_set_freq() warn: clear_bit() takes a bit number
drivers/iio/imu/adis16475.c:416 adis16475_set_filter() warn: set_bit() takes a bit number
drivers/iio/imu/adis16475.c:416 adis16475_set_filter() warn: clear_bit() takes a bit number

vim +363 drivers/iio/imu/adis16475.c

fff7352bf7a3ce Nuno Sá 2020-04-13  357
9da1b86865ab43 Nuno Sá 2021-09-20  358          adis_dev_unlock(&st->adis); fff7352bf7a3ce Nuno Sá 2020-04-13  359          /*
fff7352bf7a3ce Nuno Sá 2020-04-13  360           * If decimation is used, then gyro and accel data will have meaningful
fff7352bf7a3ce Nuno Sá 2020-04-13  361           * bits on the LSB registers. This info is used on the trigger handler.
fff7352bf7a3ce Nuno Sá 2020-04-13  362           */ fff7352bf7a3ce Nuno Sá 2020-04-13
@363          assign_bit(ADIS16475_LSB_DEC_MASK, &st->lsb_flag, dec);

Quoted 7 lines
Quoted 2 lines

assign_bit() takes a bit number like 0.  But this is passing BIT(0) so it's like BIT(BIT(0)).  Which is fine until you get to 5.

Is this intended? There are 2 places where you pass %ADIS16475_LSB_DEC_MASK and %ADIS16475_LSB_FIR_MASK, which is BIT(0) and BIT(1) respectively, to assign_bit(), which takes 0, 1 etc.

Sorry, I'm missing the point in here... This should be a simple mask as GENMASK(1, 0) setting/clearing the bits when appropriate. Obviously, ADIS16475_LSB_DEC_MASK and ADIS16475_LSB_FIR_MASK are not properly defined :sweat_smile:

- Nuno Sá

Quoted 2 lines
Quoted 2 lines
#3 lore raw

From: Nuno Sá <[email protected]>
Date: Mon, 06 Nov 2023 11:07:16 +0100

Quoted 52 lines

Hi Olek,

Quoted 49 lines · Alexander Lobakin

From: Dan Carpenter <[email protected]>
Date: Mon, 6 Nov 2023 11:50:03 +0300

Hi,

Quoted 43 lines

tree:   https://github.com/alobakin/linux pfcp
head:   89565e300e3d4033b8bb568774804fdc09d4f3cc
commit: 945a0d6e86d97bf60f2fae88ee557ed3eae18b94 [5/20] bitops: let the compiler optimize {__,}assign_bit()
config: i386-randconfig-141-20231105
(https://download.01.org/0day-ci/archive/20231106/202311060647.i9XyO4ej-lkp@intel
.com/config)
compiler: gcc-12 (Debian 12.2.0-14) 12.2.0
reproduce:
(https://download.01.org/0day-ci/archive/20231106/202311060647.i9XyO4ej-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

Quoted 3 lines

smatch warnings:
drivers/iio/imu/adis16475.c:363 adis16475_set_freq() warn: set_bit() takes a bit number
drivers/iio/imu/adis16475.c:363 adis16475_set_freq() warn: clear_bit() takes a bit number
drivers/iio/imu/adis16475.c:416 adis16475_set_filter() warn: set_bit() takes a bit number
drivers/iio/imu/adis16475.c:416 adis16475_set_filter() warn: clear_bit() takes a bit number

vim +363 drivers/iio/imu/adis16475.c

fff7352bf7a3ce Nuno Sá 2020-04-13  357
9da1b86865ab43 Nuno Sá 2021-09-20  358          adis_dev_unlock(&st->adis); fff7352bf7a3ce Nuno Sá 2020-04-13  359          /*
fff7352bf7a3ce Nuno Sá 2020-04-13  360           * If decimation is used, then gyro and accel data will have meaningful
fff7352bf7a3ce Nuno Sá 2020-04-13  361           * bits on the LSB registers. This info is used on the trigger handler.
fff7352bf7a3ce Nuno Sá 2020-04-13  362           */ fff7352bf7a3ce Nuno Sá 2020-04-13
@363          assign_bit(ADIS16475_LSB_DEC_MASK, &st->lsb_flag, dec);

assign_bit() takes a bit number like 0.  But this is passing BIT(0) so it's like BIT(BIT(0)).  Which is fine until you get to 5.

Quoted 7 lines
Quoted 4 lines

Is this intended? There are 2 places where you pass %ADIS16475_LSB_DEC_MASK and %ADIS16475_LSB_FIR_MASK, which is BIT(0) and BIT(1) respectively, to assign_bit(), which takes 0, 1 etc.

Sorry, I'm missing the point in here... This should be a simple mask as GENMASK(1, 0) setting/clearing the bits when appropriate. Obviously,

assign_bit() does not take a bitmask as a first argument, but a bit number.

I.e. if you want to switch BIT(0), you call it like assign_bit(0, ...), not assign_bit(BIT(0), ...). Same for the bit nr 1.

I can make and send a quick fix if you prefer.

Quoted 7 lines

ADIS16475_LSB_DEC_MASK and ADIS16475_LSB_FIR_MASK are not properly defined :sweat_smile:

- Nuno Sá

Quoted 2 lines
Quoted 2 lines

Thanks,
Olek

#4 lore raw
Quoted 71 lines · Alexander Lobakin

From: Nuno Sá <[email protected]>
Date: Mon, 06 Nov 2023 11:07:16 +0100

Quoted 68 lines

Hi Olek,

Quoted 64 lines · Alexander Lobakin

From: Dan Carpenter <[email protected]>
Date: Mon, 6 Nov 2023 11:50:03 +0300

Hi,

Quoted 52 lines

tree:   https://github.com/alobakin/linux pfcp
head:   89565e300e3d4033b8bb568774804fdc09d4f3cc
commit: 945a0d6e86d97bf60f2fae88ee557ed3eae18b94 [5/20] bitops: let the compiler
optimize {__,}assign_bit()
config: i386-randconfig-141-20231105
(
https://download.01.org/0day-ci/archive/20231106/202311060647.i9XyO4ej-lkp@int
el
.com/config)
compiler: gcc-12 (Debian 12.2.0-14) 12.2.0
reproduce:
(
https://download.01.org/0day-ci/archive/20231106/202311060647.i9XyO4ej-lkp@int
el
.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

Quoted 3 lines

smatch warnings:
drivers/iio/imu/adis16475.c:363 adis16475_set_freq() warn: set_bit() takes a bit
number
drivers/iio/imu/adis16475.c:363 adis16475_set_freq() warn: clear_bit() takes a
bit number
drivers/iio/imu/adis16475.c:416 adis16475_set_filter() warn: set_bit() takes a
bit number
drivers/iio/imu/adis16475.c:416 adis16475_set_filter() warn: clear_bit() takes a
bit number

vim +363 drivers/iio/imu/adis16475.c

fff7352bf7a3ce Nuno Sá 2020-04-13  357
9da1b86865ab43 Nuno Sá 2021-09-20  358          adis_dev_unlock(&st->adis); fff7352bf7a3ce Nuno Sá 2020-04-13  359          /*
fff7352bf7a3ce Nuno Sá 2020-04-13  360           * If decimation is used, then
gyro and accel data will have meaningful
fff7352bf7a3ce Nuno Sá 2020-04-13  361           * bits on the LSB registers. This info is used on the trigger handler.
fff7352bf7a3ce Nuno Sá 2020-04-13  362           */ fff7352bf7a3ce Nuno Sá 2020-04-13
@363          assign_bit(ADIS16475_LSB_DEC_MASK, &st->lsb_flag, dec);

Quoted 2 lines

assign_bit() takes a bit number like 0.  But this is passing BIT(0) so it's like BIT(BIT(0)).  Which is fine until you get to 5.

Is this intended? There are 2 places where you pass %ADIS16475_LSB_DEC_MASK and %ADIS16475_LSB_FIR_MASK, which is BIT(0) and BIT(1) respectively, to assign_bit(), which takes 0, 1 etc.

Quoted 8 lines
Quoted 2 lines

Sorry, I'm missing the point in here... This should be a simple mask as GENMASK(1, 0) setting/clearing the bits when appropriate. Obviously,

assign_bit() does not take a bitmask as a first argument, but a bit number.

I.e. if you want to switch BIT(0), you call it like assign_bit(0, ...), not assign_bit(BIT(0), ...). Same for the bit nr 1.

Yes, I know... if you look at my reply to Dan you can see I realized that already :)

I guess by the time I first sent this time I didn't knew or maybe just a dumb mistake...

I'll send a patch later today removing the BIT() from the #define, thx!

- Nuno Sá

#5 lore raw

From: Nuno Sá <[email protected]>
Date: Mon, 06 Nov 2023 13:02:58 +0100

Quoted 3 lines · Alexander Lobakin
Quoted 2 lines

From: Nuno Sá <[email protected]>
Date: Mon, 06 Nov 2023 11:07:16 +0100

[...]

Quoted 7 lines
Quoted 5 lines

assign_bit() does not take a bitmask as a first argument, but a bit number.

I.e. if you want to switch BIT(0), you call it like assign_bit(0, ...), not assign_bit(BIT(0), ...). Same for the bit nr 1.

Yes, I know... if you look at my reply to Dan you can see I realized that already :)

Oh okay :)

Quoted 5 lines

I guess by the time I first sent this time I didn't knew or maybe just a dumb mistake...

I'll send a patch later today removing the BIT() from the #define, thx!

Nice! Don't forget the tags the build bot asked for :p

BTW, I believe the reason why this warning triggered after my commit is that before it, assign_bit() is a static inline, but becomes a macro then. smatch becomes able to see through it that it indeed is a wrapper around set_bit()/clear_bit() and realizes the first argument is invalid.

Quoted 3 lines

- Nuno Sá

Thanks,
Olek

#6 lore raw
Quoted 21 lines · Alexander Lobakin

From: Nuno Sá <[email protected]>
Date: Mon, 06 Nov 2023 13:02:58 +0100

Quoted 3 lines · Alexander Lobakin
Quoted 2 lines

From: Nuno Sá <[email protected]>
Date: Mon, 06 Nov 2023 11:07:16 +0100

[...]

Quoted 8 lines
Quoted 5 lines

assign_bit() does not take a bitmask as a first argument, but a bit number.

I.e. if you want to switch BIT(0), you call it like assign_bit(0, ...), not assign_bit(BIT(0), ...). Same for the bit nr 1.

Yes, I know... if you look at my reply to Dan you can see I realized that already :)

Oh okay :)

Quoted 1 line
Quoted 7 lines
Quoted 4 lines

I guess by the time I first sent this time I didn't knew or maybe just a dumb mistake...

I'll send a patch later today removing the BIT() from the #define, thx!

Nice! Don't forget the tags the build bot asked for :p

Just sent it... Hopefully no tags were forgotten! I was not sure about the Fixes tag but added it anyways as this is indeed fixing something (even though the bug was never triggered).

- Nuno Sá

#7 lore raw
In reply to Dan Carpenter
Quoted 41 lines · Dan Carpenter

tree:   https://github.com/alobakin/linux pfcp
head:   89565e300e3d4033b8bb568774804fdc09d4f3cc
commit: 945a0d6e86d97bf60f2fae88ee557ed3eae18b94 [5/20] bitops: let the compiler optimize {__,}assign_bit()
config: i386-randconfig-141-20231105
(https://download.01.org/0day-ci/archive/20231106/[email protected]
om/config)
compiler: gcc-12 (Debian 12.2.0-14) 12.2.0
reproduce:
(https://download.01.org/0day-ci/archive/20231106/[email protected]
om/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

Quoted 3 lines

smatch warnings:
drivers/iio/imu/adis16475.c:363 adis16475_set_freq() warn: set_bit() takes a bit number
drivers/iio/imu/adis16475.c:363 adis16475_set_freq() warn: clear_bit() takes a bit number
drivers/iio/imu/adis16475.c:416 adis16475_set_filter() warn: set_bit() takes a bit number
drivers/iio/imu/adis16475.c:416 adis16475_set_filter() warn: clear_bit() takes a bit number

vim +363 drivers/iio/imu/adis16475.c

fff7352bf7a3ce Nuno Sá 2020-04-13  357
9da1b86865ab43 Nuno Sá 2021-09-20  358          adis_dev_unlock(&st->adis); fff7352bf7a3ce Nuno Sá 2020-04-13  359          /*
fff7352bf7a3ce Nuno Sá 2020-04-13  360           * If decimation is used, then gyro and accel data will have meaningful
fff7352bf7a3ce Nuno Sá 2020-04-13  361           * bits on the LSB registers. This info is used on the trigger handler.
fff7352bf7a3ce Nuno Sá 2020-04-13  362           */
fff7352bf7a3ce Nuno Sá 2020-04-13 @363          assign_bit(ADIS16475_LSB_DEC_MASK, &st->lsb_flag, dec);

Quoted 3 lines

assign_bit() takes a bit number like 0.  But this is passing BIT(0) so it's like BIT(BIT(0)).  Which is fine until you get to 5.

Yeah, on 32bit arch that would not be funny... This should not really ever be a problem for this driver as that mask should not get bigger. But, for correctness, I will send a patch removing BIT() from the #defines.

- Nuno Sá

#8 lore raw
Quoted 11 lines · Nuno Sá
Quoted 11 lines

fff7352bf7a3ce Nuno Sá 2020-04-13  357
9da1b86865ab43 Nuno Sá 2021-09-20  358          adis_dev_unlock(&st->adis); fff7352bf7a3ce Nuno Sá 2020-04-13  359          /*
fff7352bf7a3ce Nuno Sá 2020-04-13  360           * If decimation is used, then gyro and accel data will have meaningful
fff7352bf7a3ce Nuno Sá 2020-04-13  361           * bits on the LSB registers. This info is used on the trigger handler.
fff7352bf7a3ce Nuno Sá 2020-04-13  362           */
fff7352bf7a3ce Nuno Sá 2020-04-13 @363          assign_bit(ADIS16475_LSB_DEC_MASK, &st->lsb_flag, dec);

Quoted 5 lines
Quoted 3 lines

assign_bit() takes a bit number like 0.  But this is passing BIT(0) so it's like BIT(BIT(0)).  Which is fine until you get to 5.

Yeah, on 32bit arch that would not be funny...

Indeed. Btw, a lot of people don't realize that what actually happens is not shift wrapping but a buffer overflow. The test_bit() functions are designed to handle large bit masks so they can basically set or clear a bit anywhere in your RAM. This isn't so much an issue with this type of double shift bugs, but you need to be careful passing unvalidated user data to test_bit().

regards,
dan carpenter