mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Andy Shevchenko <andriy.shevchenko@intel.com>
To: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>
Cc: jic23@kernel.org, andy@kernel.org, linux-iio@vger.kernel.org,
	linux-kernel@vger.kernel.org, stable@vger.kernel.org
Subject: Re: [PATCH] iio: hid-sensors: fix fractional part for unit exponents -7 and -8
Date: Tue, 3 Nov 2026 12:39:43 +0200	[thread overview]
Message-ID: <aum57zKQwN2nJCAg@ashevche-desk.local> (raw)
In-Reply-To: <20261102222309.439895-1-srinivas.pandruvada@linux.intel.com>

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



  reply	other threads:[~2026-11-03 10:39 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-02 22:23 Srinivas Pandruvada
2026-11-03 10:39 ` Andy Shevchenko [this message]
2026-11-04  0:17 ` kernel test robot
2026-11-04  0:46 ` kernel test robot

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=aum57zKQwN2nJCAg@ashevche-desk.local \
    --to=andriy.shevchenko@intel.com \
    --cc=andy@kernel.org \
    --cc=jic23@kernel.org \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=srinivas.pandruvada@linux.intel.com \
    --cc=stable@vger.kernel.org \
    /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

all inboxes | Powered by JetHome®