Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1608384 > unrolled thread

[PATCH] iio: core: Fix IIO_VAL_FRACTIONAL_LOG2 for negative values

Started byNikolaus Schulz <nikolaus.schulz@avionic-design.de>
First post2017-03-24 14:00 +0100
Last post2017-03-25 19:10 +0100
Articles 2 — 2 participants

Back to article view | Back to linux.kernel


Contents

  [PATCH] iio: core: Fix IIO_VAL_FRACTIONAL_LOG2 for negative values Nikolaus Schulz <nikolaus.schulz@avionic-design.de> - 2017-03-24 14:00 +0100
    Re: [PATCH] iio: core: Fix IIO_VAL_FRACTIONAL_LOG2 for negative  values Jonathan Cameron <jic23@kernel.org> - 2017-03-25 19:10 +0100

#1608384 — [PATCH] iio: core: Fix IIO_VAL_FRACTIONAL_LOG2 for negative values

FromNikolaus Schulz <nikolaus.schulz@avionic-design.de>
Date2017-03-24 14:00 +0100
Subject[PATCH] iio: core: Fix IIO_VAL_FRACTIONAL_LOG2 for negative values
Message-ID<towYW-1Hf-15@gated-at.bofh.it>
Fix formatting of negative values of type IIO_VAL_FRACTIONAL_LOG2 by
switching from do_div(), which can't handle negative numbers, to
div_s64_rem().  Also use shift_right for shifting, which is safe with
negative values.

Signed-off-by: Nikolaus Schulz <nikolaus.schulz@avionic-design.de>
Cc: stable@vger.kernel.org
---
 drivers/iio/industrialio-core.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c
index d18ded4..3ff91e0 100644
--- a/drivers/iio/industrialio-core.c
+++ b/drivers/iio/industrialio-core.c
@@ -610,10 +610,9 @@ static ssize_t __iio_format_value(char *buf, size_t len, unsigned int type,
 		tmp0 = (int)div_s64_rem(tmp, 1000000000, &tmp1);
 		return snprintf(buf, len, "%d.%09u", tmp0, abs(tmp1));
 	case IIO_VAL_FRACTIONAL_LOG2:
-		tmp = (s64)vals[0] * 1000000000LL >> vals[1];
-		tmp1 = do_div(tmp, 1000000000LL);
-		tmp0 = tmp;
-		return snprintf(buf, len, "%d.%09u", tmp0, tmp1);
+		tmp = shift_right((s64)vals[0] * 1000000000LL, vals[1]);
+		tmp0 = (int)div_s64_rem(tmp, 1000000000LL, &tmp1);
+		return snprintf(buf, len, "%d.%09u", tmp0, abs(tmp1));
 	case IIO_VAL_INT_MULTIPLE:
 	{
 		int i;
-- 
2.1.4

[toc] | [next] | [standalone]


#1609199 — Re: [PATCH] iio: core: Fix IIO_VAL_FRACTIONAL_LOG2 for negative values

FromJonathan Cameron <jic23@kernel.org>
Date2017-03-25 19:10 +0100
SubjectRe: [PATCH] iio: core: Fix IIO_VAL_FRACTIONAL_LOG2 for negative values
Message-ID<toYiu-4wW-3@gated-at.bofh.it>
In reply to#1608384
On 24/03/17 12:41, Nikolaus Schulz wrote:
> Fix formatting of negative values of type IIO_VAL_FRACTIONAL_LOG2 by
> switching from do_div(), which can't handle negative numbers, to
> div_s64_rem().  Also use shift_right for shifting, which is safe with
> negative values.
> 
> Signed-off-by: Nikolaus Schulz <nikolaus.schulz@avionic-design.de>
> Cc: stable@vger.kernel.org
Looks sane to me, but I'd like to give others time to comment on this
just in case there is some odd condition neither of us has thought of!

Give me a poke if we get nothing else for a few weeks.

Jonathan
> ---
>  drivers/iio/industrialio-core.c | 7 +++----
>  1 file changed, 3 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c
> index d18ded4..3ff91e0 100644
> --- a/drivers/iio/industrialio-core.c
> +++ b/drivers/iio/industrialio-core.c
> @@ -610,10 +610,9 @@ static ssize_t __iio_format_value(char *buf, size_t len, unsigned int type,
>  		tmp0 = (int)div_s64_rem(tmp, 1000000000, &tmp1);
>  		return snprintf(buf, len, "%d.%09u", tmp0, abs(tmp1));
>  	case IIO_VAL_FRACTIONAL_LOG2:
> -		tmp = (s64)vals[0] * 1000000000LL >> vals[1];
> -		tmp1 = do_div(tmp, 1000000000LL);
> -		tmp0 = tmp;
> -		return snprintf(buf, len, "%d.%09u", tmp0, tmp1);
> +		tmp = shift_right((s64)vals[0] * 1000000000LL, vals[1]);
> +		tmp0 = (int)div_s64_rem(tmp, 1000000000LL, &tmp1);
> +		return snprintf(buf, len, "%d.%09u", tmp0, abs(tmp1));
>  	case IIO_VAL_INT_MULTIPLE:
>  	{
>  		int i;
> 

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web