iio: core: Fix IIO_VAL_FRACTIONAL_LOG2 for negative values

Fix formatting of negative values of type IIO_VAL_FRACTIONAL_LOG2 by
switching from do_div(), which can't handle negative numbers, to
div_s64_rem(). Also use shift_right for shifting, which is safe with
negative values.

Signed-off-by: Nikolaus Schulz <nikolaus.schulz@avionic-design.de>
Reviewed-by: Lars-Peter Clausen <lars@metafoo.de>
Cc: stable@vger.kernel.org
Signed-off-by: Jonathan Cameron <jic23@kernel.org>

authored by Nikolaus Schulz and committed by Jonathan Cameron 7fd6592d 51f528a1

+3 -4
+3 -4
drivers/iio/industrialio-core.c
··· 610 610 tmp0 = (int)div_s64_rem(tmp, 1000000000, &tmp1); 611 611 return snprintf(buf, len, "%d.%09u", tmp0, abs(tmp1)); 612 612 case IIO_VAL_FRACTIONAL_LOG2: 613 - tmp = (s64)vals[0] * 1000000000LL >> vals[1]; 614 - tmp1 = do_div(tmp, 1000000000LL); 615 - tmp0 = tmp; 616 - return snprintf(buf, len, "%d.%09u", tmp0, tmp1); 613 + tmp = shift_right((s64)vals[0] * 1000000000LL, vals[1]); 614 + tmp0 = (int)div_s64_rem(tmp, 1000000000LL, &tmp1); 615 + return snprintf(buf, len, "%d.%09u", tmp0, abs(tmp1)); 617 616 case IIO_VAL_INT_MULTIPLE: 618 617 { 619 618 int i;