From: Jonathan Cameron <jic23@kernel.org>
To: Anand Ashok Dumbre <anand.ashok.dumbre@xilinx.com>
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
Date: Sat, 10 Oct 2020 17:54:15 +0100 [thread overview]
Message-ID: <20201010175415.6e51d873@archlinux> (raw)
In-Reply-To: <1601910316-24111-1-git-send-email-anand.ashok.dumbre@xilinx.com>
On Mon, 5 Oct 2020 08:05:16 -0700
Anand Ashok Dumbre <anand.ashok.dumbre@xilinx.com> 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 <anand.ashok.dumbre@xilinx.com>
> Reported-by: kernel test robot <lkp@intel.com> #error: uninitialized symbol tmp
> Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
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);
WARNING: multiple messages have this Message-ID (diff)
From: Jonathan Cameron <jic23@kernel.org>
To: Anand Ashok Dumbre <anand.ashok.dumbre@xilinx.com>
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
Subject: Re: [LINUX PATCH v3] iio: core: Fix IIO_VAL_FRACTIONAL calculation for negative values
Date: Sat, 10 Oct 2020 17:54:15 +0100 [thread overview]
Message-ID: <20201010175415.6e51d873@archlinux> (raw)
In-Reply-To: <1601910316-24111-1-git-send-email-anand.ashok.dumbre@xilinx.com>
On Mon, 5 Oct 2020 08:05:16 -0700
Anand Ashok Dumbre <anand.ashok.dumbre@xilinx.com> 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 <anand.ashok.dumbre@xilinx.com>
> Reported-by: kernel test robot <lkp@intel.com> #error: uninitialized symbol tmp
> Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
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
next prev parent reply other threads:[~2020-10-10 22:57 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-10-05 15:05 [LINUX PATCH v3] iio: core: Fix IIO_VAL_FRACTIONAL calculation for negative values Anand Ashok Dumbre
2020-10-05 15:05 ` Anand Ashok Dumbre
2020-10-10 16:54 ` Jonathan Cameron [this message]
2020-10-10 16:54 ` Jonathan Cameron
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20201010175415.6e51d873@archlinux \
--to=jic23@kernel.org \
--cc=anand.ashok.dumbre@xilinx.com \
--cc=anandash@xilinx.com \
--cc=git@xilinx.com \
--cc=knaack.h@gmx.de \
--cc=lars@metafoo.de \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=michal.simek@xilinx.com \
--cc=pmeerw@pmeerw.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.