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 <gregor.boirie@xxxxxxxxxx> > > 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 <lars@xxxxxxxxxx> [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@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html