[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <lsq.1500213406.948919902@decadent.org.uk>
Date: Sun, 16 Jul 2017 14:56:46 +0100
From: Ben Hutchings <ben@...adent.org.uk>
To: linux-kernel@...r.kernel.org, stable@...r.kernel.org
CC: akpm@...ux-foundation.org,
"Nikolaus Schulz" <nikolaus.schulz@...onic-design.de>,
"Lars-Peter Clausen" <lars@...afoo.de>,
"Jonathan Cameron" <jic23@...nel.org>
Subject: [PATCH 3.16 117/178] iio: core: Fix IIO_VAL_FRACTIONAL_LOG2 for
negative values
3.16.46-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Nikolaus Schulz <nikolaus.schulz@...onic-design.de>
commit 7fd6592d1287046f61bfd3cda3c03cd35be490f7 upstream.
Fix formatting of negative values of type IIO_VAL_FRACTIONAL_LOG2 by
switching from do_div(), which can't handle negative numbers, to
div_s64_rem(). Also use shift_right for shifting, which is safe with
negative values.
Signed-off-by: Nikolaus Schulz <nikolaus.schulz@...onic-design.de>
Reviewed-by: Lars-Peter Clausen <lars@...afoo.de>
Signed-off-by: Jonathan Cameron <jic23@...nel.org>
[bwh: Backported to 3.16:
- Use vals[] instead of tmp{0,1}
- Keep using sprintf()]
Signed-off-by: Ben Hutchings <ben@...adent.org.uk>
---
drivers/iio/industrialio-core.c | 7 +++----
1 file changed, 3 insertions(+), 4 deletions(-)
--- a/drivers/iio/industrialio-core.c
+++ b/drivers/iio/industrialio-core.c
@@ -406,10 +406,9 @@ ssize_t iio_format_value(char *buf, unsi
vals[0] = (int)div_s64_rem(tmp, 1000000000, &vals[1]);
return sprintf(buf, "%d.%09u\n", vals[0], abs(vals[1]));
case IIO_VAL_FRACTIONAL_LOG2:
- tmp = (s64)vals[0] * 1000000000LL >> vals[1];
- vals[1] = do_div(tmp, 1000000000LL);
- vals[0] = tmp;
- return sprintf(buf, "%d.%09u\n", vals[0], vals[1]);
+ tmp = shift_right((s64)vals[0] * 1000000000LL, vals[1]);
+ vals[0] = (int)div_s64_rem(tmp, 1000000000LL, &vals[1]);
+ return sprintf(buf, "%d.%09u\n", vals[0], abs(vals[1]));
case IIO_VAL_INT_MULTIPLE:
{
int i;
Powered by blists - more mailing lists