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=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 E33C4C433E1 for ; Sat, 22 Aug 2020 10:58:14 +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 B1D112067C for ; Sat, 22 Aug 2020 10:58:14 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="Lt1iXBOG"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=kernel.org header.i=@kernel.org header.b="KCE5cT2m" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org B1D112067C 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=9Z/U74HnPkoAKnnSarpB7DvzIdHnG7ktXy39/EWCdP0=; b=Lt1iXBOGPm+MS07GHj1eB+PMI ec4Em+02dIMtKfED+8V32bS3vlZBvMhfvE310QYVM0ozmqrtnGHCRg6n4hCNcYrInASEzp8IIoEec xgEbGNMPM6vb2OVUfZ9YxcPUr3kzLKRzD/IXnfyxYY+n200TprCWUnb6JHFgVD772uwvC2C60hYgo tkzAhnZ2FybW4qPPbcoi7day4Y2aCVV3/43A27Dtf6eKqzAxtGbPqstJZiY6dLTrLjFY1fB4R5tR7 wajs8tOokM/5s1fE5T2jg2J7hT03hI+1ICECx9zpspCcU4W0K+ajKbxvJrBeTflyCRBl+ydbbPNN6 i/F9q62+A==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1k9RCq-00022D-Mp; Sat, 22 Aug 2020 10:57:04 +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 1k9RCo-00021o-5n for linux-arm-kernel@lists.infradead.org; Sat, 22 Aug 2020 10:57:02 +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 F13392067C; Sat, 22 Aug 2020 10:56:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1598093821; bh=BqxYd2pOokGPeK4LyapSM4x47jhdQWKuct76BNr8mIQ=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=KCE5cT2m3bt54RR8mfuyBOBzCYm9tlrUYymZbKgaCgKyPLtp3qhH4mZZFff1Xp61x QhGBRFCkeZLTy4UX/i+UuuzVGrrNuHKgo+lDWgxu2PJitsVvrp2EwmmU/c7Jlli82s zN9hWOcmruSVKMoE9P/3uGRmEsa++M2UnqAykypk= Date: Sat, 22 Aug 2020 11:56:54 +0100 From: Jonathan Cameron To: Anand Ashok Dumbre Subject: Re: [PATCH] iio: Fixed IIO_VAL_FRACTIONAL calcuation for negative values Message-ID: <20200822115654.0d7f716f@archlinux> In-Reply-To: <1597946984-25844-1-git-send-email-anand.ashok.dumbre@xilinx.com> References: <1597946984-25844-1-git-send-email-anand.ashok.dumbre@xilinx.com> X-Mailer: Claws Mail 3.17.6 (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-20200822_065702_356135_08C0AA56 X-CRM114-Status: GOOD ( 22.39 ) 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 Thu, 20 Aug 2020 11:09:44 -0700 Anand Ashok Dumbre wrote: > This patch fixes IIO_VAL_FRACTIONAL calculation for negative > values where the exponent is 0. > > Signed-off-by: Anand Ashok Dumbre Hi, I would thrown in an example for this description. Also useful to know if there is a existing driver that is broken and hence we need to backport this. If that is the case, please try to figure out an appropriate fixes tag. Comments inline + the email footer issue needs sorting out. Thanks, Jonathan > --- > 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 f72c2dc..cd43b17 100644 > --- a/drivers/iio/industrialio-core.c > +++ b/drivers/iio/industrialio-core.c > @@ -554,6 +554,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) { > @@ -576,10 +577,13 @@ static ssize_t __iio_format_value(char *buf, size_t len, unsigned int type, > else > return snprintf(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 snprintf(buf, len, "%d.%09u", tmp0, abs(tmp1)); > + tmp0 = (int)div_s64_rem(tmp2, 1000000000, &tmp1); > + if ((tmp2 < 0) && (tmp0 == 0)) > + return snprintf(buf, len, "-%d.%09u", tmp0, abs(tmp1)); Given tmp0 == 0, this might be clearer as 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); > -- > 2.7.4 > > This email and any attachments are intended for the sole use of the named recipient(s) and contain(s) confidential information that may be proprietary, privileged or copyrighted under applicable law. If you are not the intended recipient, do not read, copy, or forward this email message or any attachments. Delete this email message and any attachments immediately. As Andy said, this footer is a problem... _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel