linux-iio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jonathan Cameron <jic23@kernel.org>
To: Nikolaus Schulz <nikolaus.schulz@avionic-design.de>,
	Hartmut Knaack <knaack.h@gmx.de>,
	Lars-Peter Clausen <lars@metafoo.de>,
	Peter Meerwald-Stadler <pmeerw@pmeerw.net>,
	"open list:IIO SUBSYSTEM AND DRIVERS" <linux-iio@vger.kernel.org>,
	open list <linux-kernel@vger.kernel.org>
Cc: stable@vger.kernel.org
Subject: Re: [PATCH] iio: core: Fix IIO_VAL_FRACTIONAL_LOG2 for negative values
Date: Sun, 2 Apr 2017 10:26:29 +0100	[thread overview]
Message-ID: <0cec95d3-0520-998e-fba2-de237659f3a1@kernel.org> (raw)
In-Reply-To: <c2b4855d-f7cb-2dd8-39ed-0cf8e6a21428@kernel.org>

On 25/03/17 18:03, Jonathan Cameron wrote:
> 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.
Lars, I think this might have been your magic in the first place.

Could you sanity check this one please. It's in the category of very
risky of both Nikolaus and I have missed something!

Thanks,

Jonathan
> 
> 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;
>>
> 
> --
> To unsubscribe from this list: send the line "unsubscribe linux-iio" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> 


  reply	other threads:[~2017-04-02  9:26 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-03-24 12:41 [PATCH] iio: core: Fix IIO_VAL_FRACTIONAL_LOG2 for negative values Nikolaus Schulz
2017-03-25 18:03 ` Jonathan Cameron
2017-04-02  9:26   ` Jonathan Cameron [this message]
2017-04-02 10:09     ` Lars-Peter Clausen
2017-04-02 10:15       ` 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=0cec95d3-0520-998e-fba2-de237659f3a1@kernel.org \
    --to=jic23@kernel.org \
    --cc=knaack.h@gmx.de \
    --cc=lars@metafoo.de \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=nikolaus.schulz@avionic-design.de \
    --cc=pmeerw@pmeerw.net \
    --cc=stable@vger.kernel.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).