linux-iio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Arnd Bergmann <arnd@arndb.de>
To: Jonathan Cameron <jic23@kernel.org>
Cc: Arnd Bergmann <arnd@arndb.de>,
	Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
	Jonathan Cameron <Jonathan.Cameron@huawei.com>,
	Hartmut Knaack <knaack.h@gmx.de>,
	Lars-Peter Clausen <lars@metafoo.de>,
	Peter Meerwald-Stadler <pmeerw@pmeerw.net>,
	Alexios Zavras <alexios.zavras@intel.com>,
	Colin Ian King <colin.king@canonical.com>,
	linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH] [RFC] Revert "iio: hid-sensor-attributes: Convert to use int_pow()"
Date: Fri,  6 Sep 2019 17:45:55 +0200	[thread overview]
Message-ID: <20190906154609.2421410-1-arnd@arndb.de> (raw)

The change to use the generic int_pow instead of the private version
caused a number of build issues on 32-bit architectures and makes
it generally less efficient because of the 64-bit math:

drivers/iio/common/hid-sensors/hid-sensor-attributes.o: In function `hid_sensor_write_samp_freq_value':
hid-sensor-attributes.c:(.text+0x29c): undefined reference to `__aeabi_uldivmod'
drivers/iio/common/hid-sensors/hid-sensor-attributes.o: In function `hid_sensor_read_raw_hyst_value':
hid-sensor-attributes.c:(.text+0x420): undefined reference to `__aeabi_uldivmod'
hid-sensor-attributes.c:(.text+0x448): undefined reference to `__aeabi_uldivmod'
drivers/iio/common/hid-sensors/hid-sensor-attributes.o: In function `hid_sensor_write_raw_hyst_value':
hid-sensor-attributes.c:(.text+0x570): undefined reference to `__aeabi_uldivmod'

There is probably a nicer solution to this, but for the moment,
the revert makes it compile again.

Fixes: 473d12f7638c ("iio: hid-sensor-attributes: Convert to use int_pow()")
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
 .../hid-sensors/hid-sensor-attributes.c       | 53 +++++++++++--------
 1 file changed, 31 insertions(+), 22 deletions(-)

diff --git a/drivers/iio/common/hid-sensors/hid-sensor-attributes.c b/drivers/iio/common/hid-sensors/hid-sensor-attributes.c
index b9dd19b34267..a8a3fe428d8d 100644
--- a/drivers/iio/common/hid-sensors/hid-sensor-attributes.c
+++ b/drivers/iio/common/hid-sensors/hid-sensor-attributes.c
@@ -8,7 +8,6 @@
 #include <linux/module.h>
 #include <linux/interrupt.h>
 #include <linux/irq.h>
-#include <linux/kernel.h>
 #include <linux/slab.h>
 #include <linux/hid-sensor-hub.h>
 #include <linux/iio/iio.h>
@@ -69,6 +68,16 @@ static struct {
 	{HID_USAGE_SENSOR_HUMIDITY, 0, 1000, 0},
 };
 
+static int pow_10(unsigned power)
+{
+	int i;
+	int ret = 1;
+	for (i = 0; i < power; ++i)
+		ret = ret * 10;
+
+	return ret;
+}
+
 static void simple_div(int dividend, int divisor, int *whole,
 				int *micro_frac)
 {
@@ -87,14 +96,14 @@ static void simple_div(int dividend, int divisor, int *whole,
 			rem *= 10;
 			exp++;
 		}
-		*micro_frac = (rem / divisor) * int_pow(10, 6 - exp);
+		*micro_frac = (rem / divisor) * pow_10(6-exp);
 	}
 }
 
 static void split_micro_fraction(unsigned int no, int exp, int *val1, int *val2)
 {
-	*val1 = no / int_pow(10, exp);
-	*val2 = no % int_pow(10, exp) * int_pow(10, 6 - exp);
+	*val1 = no/pow_10(exp);
+	*val2 = no%pow_10(exp) * pow_10(6-exp);
 }
 
 /*
@@ -116,7 +125,7 @@ static void convert_from_vtf_format(u32 value, int size, int exp,
 	}
 	exp = hid_sensor_convert_exponent(exp);
 	if (exp >= 0) {
-		*val1 = sign * value * int_pow(10, exp);
+		*val1 = sign * value * pow_10(exp);
 		*val2 = 0;
 	} else {
 		split_micro_fraction(value, -exp, val1, val2);
@@ -136,10 +145,10 @@ static u32 convert_to_vtf_format(int size, int exp, int val1, int val2)
 		sign = -1;
 	exp = hid_sensor_convert_exponent(exp);
 	if (exp < 0) {
-		value = abs(val1) * int_pow(10, -exp);
-		value += abs(val2) / int_pow(10, 6 + exp);
+		value = abs(val1) * pow_10(-exp);
+		value += abs(val2) / pow_10(6+exp);
 	} else
-		value = abs(val1) / int_pow(10, exp);
+		value = abs(val1) / pow_10(exp);
 	if (sign < 0)
 		value =  ((1LL << (size * 8)) - value);
 
@@ -202,12 +211,12 @@ int hid_sensor_write_samp_freq_value(struct hid_sensor_common *st,
 	if (val1 < 0 || val2 < 0)
 		return -EINVAL;
 
-	value = val1 * int_pow(10, 6) + val2;
+	value = val1 * pow_10(6) + val2;
 	if (value) {
 		if (st->poll.units == HID_USAGE_SENSOR_UNITS_MILLISECOND)
-			value = int_pow(10, 9) / value;
+			value = pow_10(9)/value;
 		else if (st->poll.units == HID_USAGE_SENSOR_UNITS_SECOND)
-			value = int_pow(10, 6) / value;
+			value = pow_10(6)/value;
 		else
 			value = 0;
 	}
@@ -302,34 +311,34 @@ static void adjust_exponent_nano(int *val0, int *val1, int scale0,
 	int rem;
 
 	if (exp > 0) {
-		*val0 = scale0 * int_pow(10, exp);
+		*val0 = scale0 * pow_10(exp);
 		res = 0;
 		if (exp > 9) {
 			*val1 = 0;
 			return;
 		}
 		for (i = 0; i < exp; ++i) {
-			x = scale1 / int_pow(10, 8 - i);
-			res += int_pow(10, exp - 1 - i) * x;
-			scale1 = scale1 % int_pow(10, 8 - i);
+			x = scale1 / pow_10(8 - i);
+			res += (pow_10(exp - 1 - i) * x);
+			scale1 = scale1 % pow_10(8 - i);
 		}
 		*val0 += res;
-		*val1 = scale1 * int_pow(10, exp);
+		*val1 = scale1 * pow_10(exp);
 	} else if (exp < 0) {
 		exp = abs(exp);
 		if (exp > 9) {
 			*val0 = *val1 = 0;
 			return;
 		}
-		*val0 = scale0 / int_pow(10, exp);
-		rem = scale0 % int_pow(10, exp);
+		*val0 = scale0 / pow_10(exp);
+		rem = scale0 % pow_10(exp);
 		res = 0;
 		for (i = 0; i < (9 - exp); ++i) {
-			x = scale1 / int_pow(10, 8 - i);
-			res += int_pow(10, 8 - exp - i) * x;
-			scale1 = scale1 % int_pow(10, 8 - i);
+			x = scale1 / pow_10(8 - i);
+			res += (pow_10(8 - exp - i) * x);
+			scale1 = scale1 % pow_10(8 - i);
 		}
-		*val1 = rem * int_pow(10, 9 - exp) + res;
+		*val1 = rem * pow_10(9 - exp) + res;
 	} else {
 		*val0 = scale0;
 		*val1 = scale1;
-- 
2.20.0


             reply	other threads:[~2019-09-06 15:47 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-09-06 15:45 Arnd Bergmann [this message]
2019-09-06 16:55 ` [PATCH] [RFC] Revert "iio: hid-sensor-attributes: Convert to use int_pow()" Andy Shevchenko
2019-09-06 18:46   ` Arnd Bergmann

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=20190906154609.2421410-1-arnd@arndb.de \
    --to=arnd@arndb.de \
    --cc=Jonathan.Cameron@huawei.com \
    --cc=alexios.zavras@intel.com \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=colin.king@canonical.com \
    --cc=jic23@kernel.org \
    --cc=knaack.h@gmx.de \
    --cc=lars@metafoo.de \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=pmeerw@pmeerw.net \
    /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;
as well as URLs for NNTP newsgroup(s).