Message ID | 20211222034646.222189-8-liambeguin@gmail.com (mailing list archive) |
---|---|
State | Changes Requested |
Headers | show |
Series | iio: afe: add temperature rescaling support | expand |
On Wed, Dec 22, 2021 at 5:47 AM Liam Beguin <liambeguin@gmail.com> wrote: > > From: Liam Beguin <lvb@xiphos.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. Sounds to me like a fix with all necessary stuff needed about it: - Fixes tag - moving to the beginning of the series, where other fixes are
On Wed, Dec 22, 2021 at 02:25:31PM +0200, Andy Shevchenko wrote: > On Wed, Dec 22, 2021 at 5:47 AM Liam Beguin <liambeguin@gmail.com> wrote: > > > > From: Liam Beguin <lvb@xiphos.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. > > Sounds to me like a fix with all necessary stuff needed about it: > - Fixes tag > - moving to the beginning of the series, where other fixes are Will do > -- > With Best Regards, > Andy Shevchenko
diff --git a/drivers/iio/afe/iio-rescale.c b/drivers/iio/afe/iio-rescale.c index 6a2d4ae80652..a7297b4ba17e 100644 --- a/drivers/iio/afe/iio-rescale.c +++ b/drivers/iio/afe/iio-rescale.c @@ -22,7 +22,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; @@ -39,10 +39,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: