From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-11.6 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_SANE_2 autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 72AA4C35266 for ; Sat, 10 Oct 2020 22:57:05 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3E17320829 for ; Sat, 10 Oct 2020 22:57:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1602370625; bh=Yd+Ts5zV4Imhr2dlD4CN2STzRAnre/8W1ZiC+y6m/NU=; h=Date:From:To:Cc:Subject:In-Reply-To:References:List-ID:From; b=1+qKFWPFEEddngEmCPuu4M1T9aOjNI9LfMUqLiMpdZNzpmPfk6sLaljC4DonSW3IJ N3OgZvGX9wHdG4QV33in7XWfWWQIsdo4wuYusvrjEx0KcksB9/D4arFZ1vr9LFsHiW TJO9nYWNtFu8HS+bxSx573oQRGC2ilRFiomwx9LQ= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388035AbgJJW5D (ORCPT ); Sat, 10 Oct 2020 18:57:03 -0400 Received: from mail.kernel.org ([198.145.29.99]:50688 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731361AbgJJTMW (ORCPT ); Sat, 10 Oct 2020 15:12:22 -0400 Received: from archlinux (cpc149474-cmbg20-2-0-cust94.5-4.cable.virginm.net [82.4.196.95]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id B695422400; Sat, 10 Oct 2020 16:54:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1602348861; bh=Yd+Ts5zV4Imhr2dlD4CN2STzRAnre/8W1ZiC+y6m/NU=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=kNWySn40Fc1xgX/LG2i+iwLibfi85Qh8i5IV/OCvtrv/F/ydOQitt1DlIBy4zHPVZ iNLKuXTBkFLTB6E2vpilcsc5UZj6jGXofy0/Cmw1S0yDCmt+7rJpMKTQ2j1CnixEA7 67m5Z0bhjNvdDa78h/RXjXj4uJCNsnc3SzG/jcME= Date: Sat, 10 Oct 2020 17:54:15 +0100 From: Jonathan Cameron To: Anand Ashok Dumbre Cc: knaack.h@gmx.de, lars@metafoo.de, pmeerw@pmeerw.net, michal.simek@xilinx.com, git@xilinx.com, linux-iio@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, anandash@xilinx.com Subject: Re: [LINUX PATCH v3] iio: core: Fix IIO_VAL_FRACTIONAL calculation for negative values Message-ID: <20201010175415.6e51d873@archlinux> In-Reply-To: <1601910316-24111-1-git-send-email-anand.ashok.dumbre@xilinx.com> References: <1601910316-24111-1-git-send-email-anand.ashok.dumbre@xilinx.com> X-Mailer: Claws Mail 3.17.7 (GTK+ 2.24.32; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org On Mon, 5 Oct 2020 08:05:16 -0700 Anand Ashok Dumbre wrote: > Fixes IIO_VAL_FRACTIONAL for case when the result is negative and > exponent is 0. > > example: if the result is -0.75, tmp0 will be 0 and tmp1 = 75 > This causes the output to lose sign because of %d in snprintf > which works for tmp0 <= -1. > > Signed-off-by: Anand Ashok Dumbre > Reported-by: kernel test robot #error: uninitialized symbol tmp > Reported-by: Dan Carpenter As this doesn't have a fixes tag etc and from v2 discussion was only hit with a new driver, I'm not currently taking this a a fix. If people want me to rush it in / backport to stable then let me know Applied to the togreg branch of iio.git and pushed out as testing for the autobuilders to poke at it. Thanks, Jonathan > --- > > Changes in v3: > Fixed a bug caught by kernel test robot and used correct variable > > --- > drivers/iio/industrialio-core.c | 10 +++++++--- > 1 file changed, 7 insertions(+), 3 deletions(-) > > diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c > index cdcd16f1..ffd5176 100644 > --- a/drivers/iio/industrialio-core.c > +++ b/drivers/iio/industrialio-core.c > @@ -592,6 +592,7 @@ static ssize_t __iio_format_value(char *buf, size_t len, unsigned int type, > { > unsigned long long tmp; > int tmp0, tmp1; > + s64 tmp2; > bool scale_db = false; > > switch (type) { > @@ -614,10 +615,13 @@ static ssize_t __iio_format_value(char *buf, size_t len, unsigned int type, > else > return scnprintf(buf, len, "%d.%09u", vals[0], vals[1]); > case IIO_VAL_FRACTIONAL: > - tmp = div_s64((s64)vals[0] * 1000000000LL, vals[1]); > + tmp2 = div_s64((s64)vals[0] * 1000000000LL, vals[1]); > tmp1 = vals[1]; > - tmp0 = (int)div_s64_rem(tmp, 1000000000, &tmp1); > - return scnprintf(buf, len, "%d.%09u", tmp0, abs(tmp1)); > + tmp0 = (int)div_s64_rem(tmp2, 1000000000, &tmp1); > + if ((tmp2 < 0) && (tmp0 == 0)) > + return snprintf(buf, len, "-0.%09u", abs(tmp1)); > + else > + return snprintf(buf, len, "%d.%09u", tmp0, abs(tmp1)); > case IIO_VAL_FRACTIONAL_LOG2: > tmp = shift_right((s64)vals[0] * 1000000000LL, vals[1]); > tmp0 = (int)div_s64_rem(tmp, 1000000000LL, &tmp1);