Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753569AbdGPOSt (ORCPT ); Sun, 16 Jul 2017 10:18:49 -0400 Received: from shadbolt.e.decadent.org.uk ([88.96.1.126]:44400 "EHLO shadbolt.e.decadent.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751328AbdGPOSR (ORCPT ); Sun, 16 Jul 2017 10:18:17 -0400 Content-Type: text/plain; charset="UTF-8" Content-Disposition: inline Content-Transfer-Encoding: 8bit MIME-Version: 1.0 From: Ben Hutchings To: linux-kernel@vger.kernel.org, stable@vger.kernel.org CC: akpm@linux-foundation.org, "Nikolaus Schulz" , "Lars-Peter Clausen" , "Jonathan Cameron" Date: Sun, 16 Jul 2017 14:56:46 +0100 Message-ID: X-Mailer: LinuxStableQueue (scripts by bwh) Subject: [PATCH 3.16 117/178] iio: core: Fix IIO_VAL_FRACTIONAL_LOG2 for negative values In-Reply-To: X-SA-Exim-Connect-IP: 2a02:8011:400e:2:6f00:88c8:c921:d332 X-SA-Exim-Mail-From: ben@decadent.org.uk X-SA-Exim-Scanned: No (on shadbolt.decadent.org.uk); SAEximRunCond expanded to false Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1514 Lines: 40 3.16.46-rc1 review patch. If anyone has any objections, please let me know. ------------------ From: Nikolaus Schulz commit 7fd6592d1287046f61bfd3cda3c03cd35be490f7 upstream. 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 Reviewed-by: Lars-Peter Clausen Signed-off-by: Jonathan Cameron [bwh: Backported to 3.16: - Use vals[] instead of tmp{0,1} - Keep using sprintf()] Signed-off-by: Ben Hutchings --- drivers/iio/industrialio-core.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) --- a/drivers/iio/industrialio-core.c +++ b/drivers/iio/industrialio-core.c @@ -406,10 +406,9 @@ ssize_t iio_format_value(char *buf, unsi 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); - vals[0] = tmp; - return sprintf(buf, "%d.%09u\n", vals[0], vals[1]); + tmp = shift_right((s64)vals[0] * 1000000000LL, vals[1]); + vals[0] = (int)div_s64_rem(tmp, 1000000000LL, &vals[1]); + return sprintf(buf, "%d.%09u\n", vals[0], abs(vals[1])); case IIO_VAL_INT_MULTIPLE: { int i;