iio:core: fix IIO_VAL_FRACTIONAL sign handling
authorGregor Boirie <gregor.boirie@parrot.com>
Fri, 2 Sep 2016 18:27:46 +0000 (20:27 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sat, 24 Sep 2016 08:07:38 +0000 (10:07 +0200)
commitdd1e7b2406492f2fc833a148d470fbc4abb5b45e
tree1bfc5f7ad541c1806a3d4d4fba0fcf1e67c63bb5
parent2157e3380858613d70037b0d4c3448a694a7e458
iio:core: fix IIO_VAL_FRACTIONAL sign handling

commit 171c0091837c81ed5c949fec6966bb5afff2d1cf upstream.

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 <gregor.boirie@parrot.com>
Reviewed-by: Lars-Peter Clausen <lars@metafoo.de>
Signed-off-by: Jonathan Cameron <jic23@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/iio/industrialio-core.c