]> git.baikalelectronics.ru Git - kernel.git/commit
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)
committerJonathan Cameron <jic23@kernel.org>
Mon, 5 Sep 2016 20:21:32 +0000 (21:21 +0100)
commitd95ea0469d16da5851f17231994273f5b583cdcd
treea1d5f5ac471ef9c9a224632479e00623fd4c4a7e
parent0e259194969e52c6594dee9e6a451a4d1ebf568c
iio:core: fix IIO_VAL_FRACTIONAL sign handling

0e3e484e82 ("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: 0e3e484e82 ("iio: Introduce a new fractional value type")
Signed-off-by: Gregor Boirie <gregor.boirie@parrot.com>
Reviewed-by: Lars-Peter Clausen <lars@metafoo.de>
Cc: <Stable@vger.kernel.org>
Signed-off-by: Jonathan Cameron <jic23@kernel.org>
drivers/iio/industrialio-core.c