From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from saturn.retrosnub.co.uk ([178.18.118.26]:58135 "EHLO saturn.retrosnub.co.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933520AbcIEUYS (ORCPT ); Mon, 5 Sep 2016 16:24:18 -0400 Subject: Re: [PATCH v1 1/1] iio:core: fix IIO_VAL_FRACTIONAL sign handling To: Lars-Peter Clausen , Gregor Boirie , linux-iio@vger.kernel.org References: <32c015f4-bbd7-e2f4-3b4c-f7799ea95360@metafoo.de> Cc: Hartmut Knaack , Peter Meerwald-Stadler From: Jonathan Cameron Message-ID: <419daee6-1e68-dba4-3e04-3c13d58eea44@kernel.org> Date: Mon, 5 Sep 2016 21:24:16 +0100 MIME-Version: 1.0 In-Reply-To: <32c015f4-bbd7-e2f4-3b4c-f7799ea95360@metafoo.de> Content-Type: text/plain; charset=windows-1252 Sender: linux-iio-owner@vger.kernel.org List-Id: linux-iio@vger.kernel.org On 05/09/16 08:59, Lars-Peter Clausen wrote: > On 09/03/2016 05:13 PM, Jonathan Cameron wrote: >> On 02/09/16 19:27, Gregor Boirie wrote: >>> 7985e7c100 ("iio: Introduce a new fractional value type") introduced a >>> new IIO_VAL_FRACTIONAL value type meant to represent rational type numbers >>> expressed by a numerator and denominator combination. >>> >>> Formating of IIO_VAL_FRACTIONAL values relies upon do_div() usage. This >>> fails handling negative values properly since parameters are reevaluated >>> as unsigned values. >>> Fix this by using div_s64_rem() instead. Computed integer part will carry >>> properly signed value. Formatted fractional part will always be positive. >>> >>> Fixes: 7985e7c100 ("iio: Introduce a new fractional value type") >>> Signed-off-by: Gregor Boirie >> >> Hi Gregor, >> >> While this looks sensible to me, I always gain an almighty headache when >> I hit the various divide functions. >> >> Lars, the fractional code was yours in the first place. >> If you have time can you sanity check this please. > > Looks good. While looking into this I noticed that we have a very similar > patch[1] in our tree, seems like somebody forgot to send that upstream. > > Reviewed-by: Lars-Peter Clausen Applied to the fixes-togreg branch of iio.git and marked for stable. Good to know about the previous patch - if there was anything hiding around this I would assume that would have shaken it out by now! Thanks Jonathan > > > [1] > https://github.com/analogdevicesinc/linux/commit/1dbcdcfd0c8d3f5513572697685d9f30ba49d851 > > -- > 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 >