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=-12.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,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 25E41C433E6 for ; Sat, 29 Aug 2020 15:19:06 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E2BF7208A9 for ; Sat, 29 Aug 2020 15:19:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1598714346; bh=W2rbE6VHPAeW5y9cyufi3o4ecuRWRqU4vfDN60Cd1Eo=; h=Date:From:To:Cc:Subject:In-Reply-To:References:List-ID:From; b=gd5OF8/VPtP/Kff47ztGgvS2f5ruHF3s2yQVlt/FSQm8ECBNDNfaTmJNXNiZDiIPl CTxpj1OaK2Nc+6SLJevaZJyeRUy6Nulkd1URJoL68yu622xy7fDYOL0MDe4L9WJB2p YjrRxhCjzUFsBXIf0bI3ElgRZ2c4YmR+iklrP1nQ= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728237AbgH2PTF (ORCPT ); Sat, 29 Aug 2020 11:19:05 -0400 Received: from mail.kernel.org ([198.145.29.99]:34026 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728146AbgH2PTF (ORCPT ); Sat, 29 Aug 2020 11:19:05 -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 D4C9420707; Sat, 29 Aug 2020 15:19:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1598714344; bh=W2rbE6VHPAeW5y9cyufi3o4ecuRWRqU4vfDN60Cd1Eo=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=MuV4H3U+lnd2WVXNlFvCKb8DKDawjKxe9L6RwkYvW1ZUtj17fBsN8ccbZi9ZVG7d+ TRqJwFs7rPJdH61gDZ24LsLqoYsRwByiwurE4K4FoDt72iRKyQE2zIjabwyJYuKxFS N2NnYchYulNC6q6C8/MM0D6ygN9l+NcI9y204Xew= Date: Sat, 29 Aug 2020 16:19:00 +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: [PATCH v2] iio: core: Fix IIO_VAL_FRACTIONAL calculation for negative values Message-ID: <20200829161900.713541cd@archlinux> In-Reply-To: <1598465676-28912-1-git-send-email-anand.ashok.dumbre@xilinx.com> References: <1598465676-28912-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 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-iio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org On Wed, 26 Aug 2020 11:14:36 -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 Looks good. Just one last thing. Is this actually hit in an existing driver? I'm just wondering how far back we need to push it in stable etc. Thanks, Jonathan > --- > changes since v1: > Changed -%d to -0 to make the fix clearer. > Removed the email footer. > Updated the commit description with an example > -- > drivers/iio/industrialio-core.c | 8 ++++++-- > 1 file changed, 6 insertions(+), 2 deletions(-) > > diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c > index cdcd16f1..a239fa2 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)); > + 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); 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=-12.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,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 B67CDC433E2 for ; Sat, 29 Aug 2020 15:21:07 +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 82DF0208A9 for ; Sat, 29 Aug 2020 15:21:07 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="c6JzpkWi"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=kernel.org header.i=@kernel.org header.b="MuV4H3U+" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 82DF0208A9 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=+oMVoR5TF0s46tFoKrxl3ps/WBpGaJnpAJR/xDrlWHc=; b=c6JzpkWiHxG16oMuyJIkkgCaF dgB1rDYjDgnRCa+yqvDxVcr+JAvMLGDHurGYP0nnch/1JlR0wSKX4mn+g85UsWIaxeIzkRG/lV1t7 M30eGloFN10hBbMXpcQfAIzctXKsrUky6ZcHDazrGXApA81Yb1eElz2pgtI+SyaQID9TljPjsHSnG pEkRKYo8STNMSd1Nf/siX1kMwR0QsBBpt/CjDhniR5TtjEhVVe080Nzopk9zGybaPCavjPWKMh0b2 WyApT/Bsr2Ml/hGr7c/6+CzyoM/be/q8ELD2PZ5dZHQpQkjMlNiypbep1vDbuCWYoy+8A3jClXOA6 30hCYa3aA==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kC2dJ-0001CI-Hr; Sat, 29 Aug 2020 15:19:09 +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 1kC2dF-0001BR-Cr for linux-arm-kernel@lists.infradead.org; Sat, 29 Aug 2020 15:19:06 +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 D4C9420707; Sat, 29 Aug 2020 15:19:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1598714344; bh=W2rbE6VHPAeW5y9cyufi3o4ecuRWRqU4vfDN60Cd1Eo=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=MuV4H3U+lnd2WVXNlFvCKb8DKDawjKxe9L6RwkYvW1ZUtj17fBsN8ccbZi9ZVG7d+ TRqJwFs7rPJdH61gDZ24LsLqoYsRwByiwurE4K4FoDt72iRKyQE2zIjabwyJYuKxFS N2NnYchYulNC6q6C8/MM0D6ygN9l+NcI9y204Xew= Date: Sat, 29 Aug 2020 16:19:00 +0100 From: Jonathan Cameron To: Anand Ashok Dumbre Subject: Re: [PATCH v2] iio: core: Fix IIO_VAL_FRACTIONAL calculation for negative values Message-ID: <20200829161900.713541cd@archlinux> In-Reply-To: <1598465676-28912-1-git-send-email-anand.ashok.dumbre@xilinx.com> References: <1598465676-28912-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-20200829_111905_547825_12C012CF X-CRM114-Status: GOOD ( 24.04 ) 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 Wed, 26 Aug 2020 11:14:36 -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 Looks good. Just one last thing. Is this actually hit in an existing driver? I'm just wondering how far back we need to push it in stable etc. Thanks, Jonathan > --- > changes since v1: > Changed -%d to -0 to make the fix clearer. > Removed the email footer. > Updated the commit description with an example > -- > drivers/iio/industrialio-core.c | 8 ++++++-- > 1 file changed, 6 insertions(+), 2 deletions(-) > > diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c > index cdcd16f1..a239fa2 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)); > + 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