mirror of
https://github.com/BobTheBlinker/android_kernel_motorola_sm6375.git
synced 2026-10-28 10:41:38 -04:00
iio:core: fix IIO_VAL_FRACTIONAL sign handling
7985e7c100("iio: Introduce a new fractional value type") introduced a new IIO_VAL_FRACTIONAL value type meant to represent rational type numbers expressed by a numerator and denominator combination. Formating of IIO_VAL_FRACTIONAL values relies upon do_div() usage. This fails handling negative values properly since parameters are reevaluated as unsigned values. Fix this by using div_s64_rem() instead. Computed integer part will carry properly signed value. Formatted fractional part will always be positive. Fixes:7985e7c100("iio: Introduce a new fractional value type") Signed-off-by: Gregor Boirie <[email protected]> Reviewed-by: Lars-Peter Clausen <[email protected]> Cc: <[email protected]> Signed-off-by: Jonathan Cameron <[email protected]>
This commit is contained in:
parent
5dba4b14ba
commit
171c009183
1 changed files with 2 additions and 3 deletions
|
|
@ -613,9 +613,8 @@ ssize_t iio_format_value(char *buf, unsigned int type, int size, int *vals)
|
|||
return sprintf(buf, "%d.%09u\n", vals[0], vals[1]);
|
||||
case IIO_VAL_FRACTIONAL:
|
||||
tmp = div_s64((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]);
|
||||
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);
|
||||
|
|
|
|||
Loading…
Reference in a new issue