* [PATCH] iio: hid-sensors: fix fractional part for unit exponents -7 and -8
@ 2026-11-02 22:23 Srinivas Pandruvada
2026-11-03 10:39 ` Andy Shevchenko
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Srinivas Pandruvada @ 2026-11-02 22:23 UTC (permalink / raw)
To: jic23, andy; +Cc: linux-iio, linux-kernel, Srinivas Pandruvada, stable
split_micro_fraction() scales the remainder to micro units by
multiplying it by 10^(6 - exp). The unit exponent of a HID field goes
down to -8, so exp can be 7 or 8 here. Then the argument of int_pow()
is negative, which the unsigned parameter turns into a huge power of
ten: 0 modulo 2^64. As a result, the fractional part of a value read
from the hysteresis attributes is always reported as 0.
Divide by 10^(exp - 6) in these two cases. This matches the reverse
conversion in convert_to_vtf_format().
Fixes: 73c6768b710a ("iio: hid-sensors: Common attribute and trigger")
Cc: stable@vger.kernel.org
Signed-off-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>
---
drivers/iio/common/hid-sensors/hid-sensor-attributes.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/drivers/iio/common/hid-sensors/hid-sensor-attributes.c b/drivers/iio/common/hid-sensors/hid-sensor-attributes.c
index 9e7c26e37880..0e6ea5373434 100644
--- a/drivers/iio/common/hid-sensors/hid-sensor-attributes.c
+++ b/drivers/iio/common/hid-sensors/hid-sensor-attributes.c
@@ -98,7 +98,10 @@ static void split_micro_fraction(unsigned int no, int exp, int *val1, int *val2)
int divisor = int_pow(10, exp);
*val1 = no / divisor;
- *val2 = no % divisor * int_pow(10, 6 - exp);
+ if (exp > 6)
+ *val2 = no % divisor / int_pow(10, exp - 6);
+ else
+ *val2 = no % divisor * int_pow(10, 6 - exp);
}
/*
--
2.56.0
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [PATCH] iio: hid-sensors: fix fractional part for unit exponents -7 and -8
2026-11-02 22:23 [PATCH] iio: hid-sensors: fix fractional part for unit exponents -7 and -8 Srinivas Pandruvada
@ 2026-11-03 10:39 ` Andy Shevchenko
2026-11-04 0:17 ` kernel test robot
2026-11-04 0:46 ` kernel test robot
2 siblings, 0 replies; 4+ messages in thread
From: Andy Shevchenko @ 2026-11-03 10:39 UTC (permalink / raw)
To: Srinivas Pandruvada; +Cc: jic23, andy, linux-iio, linux-kernel, stable
On Mon, Nov 02, 2026 at 02:23:08PM -0800, Srinivas Pandruvada wrote:
> split_micro_fraction() scales the remainder to micro units by
> multiplying it by 10^(6 - exp). The unit exponent of a HID field goes
> down to -8, so exp can be 7 or 8 here. Then the argument of int_pow()
> is negative, which the unsigned parameter turns into a huge power of
> ten: 0 modulo 2^64. As a result, the fractional part of a value read
> from the hysteresis attributes is always reported as 0.
>
> Divide by 10^(exp - 6) in these two cases. This matches the reverse
> conversion in convert_to_vtf_format().
...
> *val1 = no / divisor;
> - *val2 = no % divisor * int_pow(10, 6 - exp);
> + if (exp > 6)
> + *val2 = no % divisor / int_pow(10, exp - 6);
> + else
> + *val2 = no % divisor * int_pow(10, 6 - exp);
Please, make no % divisor to be in a temporary variable. It may lead to
foo = var / div;
bar = var % div;
compiled to the single assembly instruction (on x86, for example).
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] iio: hid-sensors: fix fractional part for unit exponents -7 and -8
2026-11-02 22:23 [PATCH] iio: hid-sensors: fix fractional part for unit exponents -7 and -8 Srinivas Pandruvada
2026-11-03 10:39 ` Andy Shevchenko
@ 2026-11-04 0:17 ` kernel test robot
2026-11-04 0:46 ` kernel test robot
2 siblings, 0 replies; 4+ messages in thread
From: kernel test robot @ 2026-11-04 0:17 UTC (permalink / raw)
To: Srinivas Pandruvada, jic23, andy
Cc: oe-kbuild-all, linux-iio, linux-kernel, Srinivas Pandruvada, stable
Hi Srinivas,
kernel test robot noticed the following build errors:
[auto build test ERROR on jic23-iio/togreg]
[also build test ERROR on linus/master v7.3 next-20261030]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Srinivas-Pandruvada/iio-hid-sensors-fix-fractional-part-for-unit-exponents-7-and-8/20261102-142308
base: https://git.kernel.org/pub/scm/linux/kernel/git/jic23/iio.git togreg
patch link: https://lore.kernel.org/r/20261102222309.439895-1-srinivas.pandruvada%40linux.intel.com
patch subject: [PATCH] iio: hid-sensors: fix fractional part for unit exponents -7 and -8
config: parisc-randconfig-1000-20261104 (https://download.01.org/0day-ci/archive/20261104/202611040803.1mUBmX0y-lkp@intel.com/config)
compiler: hppa-linux-gcc (GCC) 8.5.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20261104/202611040803.1mUBmX0y-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/202611040803.1mUBmX0y-lkp@intel.com/
All errors (new ones prefixed by >>, old ones prefixed by <<):
>> ERROR: modpost: drivers/iio/common/hid-sensors/hid-sensor-iio-common.ko: symbol '__udivdi3' undefined!
--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] iio: hid-sensors: fix fractional part for unit exponents -7 and -8
2026-11-02 22:23 [PATCH] iio: hid-sensors: fix fractional part for unit exponents -7 and -8 Srinivas Pandruvada
2026-11-03 10:39 ` Andy Shevchenko
2026-11-04 0:17 ` kernel test robot
@ 2026-11-04 0:46 ` kernel test robot
2 siblings, 0 replies; 4+ messages in thread
From: kernel test robot @ 2026-11-04 0:46 UTC (permalink / raw)
To: Srinivas Pandruvada, jic23, andy
Cc: oe-kbuild-all, linux-iio, linux-kernel, Srinivas Pandruvada, stable
Hi Srinivas,
kernel test robot noticed the following build errors:
[auto build test ERROR on jic23-iio/togreg]
[also build test ERROR on linus/master v7.3 next-20261030]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Srinivas-Pandruvada/iio-hid-sensors-fix-fractional-part-for-unit-exponents-7-and-8/20261102-142308
base: https://git.kernel.org/pub/scm/linux/kernel/git/jic23/iio.git togreg
patch link: https://lore.kernel.org/r/20261102222309.439895-1-srinivas.pandruvada%40linux.intel.com
patch subject: [PATCH] iio: hid-sensors: fix fractional part for unit exponents -7 and -8
config: i386-randconfig-1001-20261103 (https://download.01.org/0day-ci/archive/20261104/202611040826.T95bI1SU-lkp@intel.com/config)
compiler: gcc-12 (Debian 12.4.0-5) 12.4.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20261104/202611040826.T95bI1SU-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/202611040826.T95bI1SU-lkp@intel.com/
All errors (new ones prefixed by >>):
ld: drivers/iio/common/hid-sensors/hid-sensor-attributes.o: in function `split_micro_fraction':
>> drivers/iio/common/hid-sensors/hid-sensor-attributes.c:102:(.text+0x573): undefined reference to `__udivdi3'
vim +102 drivers/iio/common/hid-sensors/hid-sensor-attributes.c
95
96 static void split_micro_fraction(unsigned int no, int exp, int *val1, int *val2)
97 {
98 int divisor = int_pow(10, exp);
99
100 *val1 = no / divisor;
101 if (exp > 6)
> 102 *val2 = no % divisor / int_pow(10, exp - 6);
103 else
104 *val2 = no % divisor * int_pow(10, 6 - exp);
105 }
106
--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-11-04 0:47 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-02 22:23 [PATCH] iio: hid-sensors: fix fractional part for unit exponents -7 and -8 Srinivas Pandruvada
2026-11-03 10:39 ` Andy Shevchenko
2026-11-04 0:17 ` kernel test robot
2026-11-04 0:46 ` kernel test robot
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®