[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20211115034334.1713050-8-liambeguin@gmail.com>
Date: Sun, 14 Nov 2021 22:43:27 -0500
From: Liam Beguin <liambeguin@...il.com>
To: liambeguin@...il.com, peda@...ntia.se, jic23@...nel.org,
lars@...afoo.de
Cc: linux-kernel@...r.kernel.org, linux-iio@...r.kernel.org,
devicetree@...r.kernel.org, robh+dt@...nel.org
Subject: [PATCH v9 07/14] iio: afe: rescale: use s64 for temporary scale calculations
From: Liam Beguin <lvb@...hos.com>
All four scaling coefficients can take signed values.
Make tmp a signed 64-bit integer and switch to div_s64() to preserve
signs during 64-bit divisions.
Signed-off-by: Liam Beguin <lvb@...hos.com>
---
drivers/iio/afe/iio-rescale.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/drivers/iio/afe/iio-rescale.c b/drivers/iio/afe/iio-rescale.c
index da462e0910ff..394f8b16b29c 100644
--- a/drivers/iio/afe/iio-rescale.c
+++ b/drivers/iio/afe/iio-rescale.c
@@ -21,7 +21,7 @@
int rescale_process_scale(struct rescale *rescale, int scale_type,
int *val, int *val2)
{
- unsigned long long tmp;
+ s64 tmp;
s32 rem;
u32 mult;
u32 neg;
@@ -38,10 +38,10 @@ int rescale_process_scale(struct rescale *rescale, int scale_type,
*val2 = rescale->denominator;
return IIO_VAL_FRACTIONAL;
case IIO_VAL_FRACTIONAL_LOG2:
- tmp = *val * 1000000000LL;
- do_div(tmp, rescale->denominator);
+ tmp = (s64)*val * 1000000000LL;
+ tmp = div_s64(tmp, rescale->denominator);
tmp *= rescale->numerator;
- do_div(tmp, 1000000000LL);
+ tmp = div_s64(tmp, 1000000000LL);
*val = tmp;
return scale_type;
case IIO_VAL_INT_PLUS_NANO:
--
2.32.0.452.g940fe202adcb
Powered by blists - more mailing lists