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.5 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_SANE_2 autolearn=ham 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 0687EC433DF for ; Sat, 10 Oct 2020 16:55:55 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 8AE252242B for ; Sat, 10 Oct 2020 16:55:54 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="ODj3SFHi"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=kernel.org header.i=@kernel.org header.b="kNWySn40" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 8AE252242B Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To:Message-ID: Subject:To:From:Date:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=pE/ah+4Y4mozBXKYeitG9JYRKaIA+XemIalxXd88Izk=; b=ODj3SFHiCxqC68m0Iaml9J/Lu ScpQJt7d0bwTkaZ3hQ1Us+A75P4bCmmv5O2c1qlWewz+nkMWpiuFCYbhHedYvsMaz6GyK1kopa5A5 40AhqzzdiHjQNDoYEoE3EV1l0PXAwjafLQRqoY4YKP/Zc3cVc3FR/qTs/N+Moy0i37gC9OjESjbsl 5tPVLjoz4zByNYJxDEqfxN+/9axN/SFQ4vuO7C1m9RUo7eRnjCMiamTnmchTqocTOnJCleUN0B4cy x73QUFkUx/s50DG9TaklBC9iG7Myd45JmMp+E+75cYrJSyHJOx8rsh2VK6FEOam4o/uxWYbWVGoYA 3AXqH7nFQ==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kRI8X-0003FL-Ua; Sat, 10 Oct 2020 16:54:26 +0000 Received: from mail.kernel.org ([198.145.29.99]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kRI8U-0003F1-JV for linux-arm-kernel@lists.infradead.org; Sat, 10 Oct 2020 16:54:23 +0000 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 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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201010_125422_769224_9C15AC3E X-CRM114-Status: GOOD ( 22.93 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: lars@metafoo.de, linux-iio@vger.kernel.org, michal.simek@xilinx.com, linux-kernel@vger.kernel.org, anandash@xilinx.com, git@xilinx.com, pmeerw@pmeerw.net, knaack.h@gmx.de, linux-arm-kernel@lists.infradead.org Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.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); _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel