mirror of
https://github.com/torvalds/linux.git
synced 2026-06-07 14:04:54 +02:00
iio: afe: rescale: use s64 for temporary scale calculations
commit51593106b6upstream. 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. Fixes:8b74816b5a("iio: afe: rescale: new driver") Signed-off-by: Liam Beguin <liambeguin@gmail.com> Reviewed-by: Peter Rosin <peda@axentia.se> Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com> Link: https://lore.kernel.org/r/20220108205319.2046348-5-liambeguin@gmail.com Cc: <Stable@vger.kernel.org> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
parent
9cd1b02655
commit
9f4fffc2ab
|
|
@ -38,7 +38,7 @@ static int rescale_read_raw(struct iio_dev *indio_dev,
|
||||||
int *val, int *val2, long mask)
|
int *val, int *val2, long mask)
|
||||||
{
|
{
|
||||||
struct rescale *rescale = iio_priv(indio_dev);
|
struct rescale *rescale = iio_priv(indio_dev);
|
||||||
unsigned long long tmp;
|
s64 tmp;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
switch (mask) {
|
switch (mask) {
|
||||||
|
|
@ -59,10 +59,10 @@ static int rescale_read_raw(struct iio_dev *indio_dev,
|
||||||
*val2 = rescale->denominator;
|
*val2 = rescale->denominator;
|
||||||
return IIO_VAL_FRACTIONAL;
|
return IIO_VAL_FRACTIONAL;
|
||||||
case IIO_VAL_FRACTIONAL_LOG2:
|
case IIO_VAL_FRACTIONAL_LOG2:
|
||||||
tmp = *val * 1000000000LL;
|
tmp = (s64)*val * 1000000000LL;
|
||||||
do_div(tmp, rescale->denominator);
|
tmp = div_s64(tmp, rescale->denominator);
|
||||||
tmp *= rescale->numerator;
|
tmp *= rescale->numerator;
|
||||||
do_div(tmp, 1000000000LL);
|
tmp = div_s64(tmp, 1000000000LL);
|
||||||
*val = tmp;
|
*val = tmp;
|
||||||
return ret;
|
return ret;
|
||||||
default:
|
default:
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user