Commit d9a0134e authored by Oleksandr Kravchenko's avatar Oleksandr Kravchenko Committed by Jonathan Cameron

iio: core: Avoid double minus in sysfs output

This patch fixes the issue with double minus in output when
reading channels from sysfs for IIO_VAL_INT_PLUS_MICRO and
IIO_VAL_INT_PLUS_NANO cases. Until this patch if val and val2
both are negatives output string contains "--" before
digits. It is result of "-%d..." in sprintf() format.
Signed-off-by: default avatarOleksandr Kravchenko <o.v.kravchenko@globallogic.com>
Signed-off-by: default avatarJonathan Cameron <jic23@kernel.org>
parent be85697b
...@@ -383,14 +383,14 @@ static ssize_t iio_read_channel_info(struct device *dev, ...@@ -383,14 +383,14 @@ static ssize_t iio_read_channel_info(struct device *dev,
scale_db = true; scale_db = true;
case IIO_VAL_INT_PLUS_MICRO: case IIO_VAL_INT_PLUS_MICRO:
if (val2 < 0) if (val2 < 0)
return sprintf(buf, "-%d.%06u%s\n", val, -val2, return sprintf(buf, "-%ld.%06u%s\n", abs(val), -val2,
scale_db ? " dB" : ""); scale_db ? " dB" : "");
else else
return sprintf(buf, "%d.%06u%s\n", val, val2, return sprintf(buf, "%d.%06u%s\n", val, val2,
scale_db ? " dB" : ""); scale_db ? " dB" : "");
case IIO_VAL_INT_PLUS_NANO: case IIO_VAL_INT_PLUS_NANO:
if (val2 < 0) if (val2 < 0)
return sprintf(buf, "-%d.%09u\n", val, -val2); return sprintf(buf, "-%ld.%09u\n", abs(val), -val2);
else else
return sprintf(buf, "%d.%09u\n", val, val2); return sprintf(buf, "%d.%09u\n", val, val2);
case IIO_VAL_FRACTIONAL: case IIO_VAL_FRACTIONAL:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment