iio: core: Avoid double minus in sysfs output
authorOleksandr Kravchenko <o.v.kravchenko@globallogic.com>
Mon, 22 Jul 2013 11:16:00 +0000 (12:16 +0100)
committerJonathan Cameron <jic23@kernel.org>
Sat, 3 Aug 2013 17:41:19 +0000 (18:41 +0100)
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: Oleksandr Kravchenko <o.v.kravchenko@globallogic.com>
Signed-off-by: Jonathan Cameron <jic23@kernel.org>
drivers/iio/industrialio-core.c

index d56d1229e2d6fe2dec77f42363798960ac66bffd..97f0297b120f41e7f73d9b5a5cf27887da146a92 100644 (file)
@@ -383,14 +383,14 @@ static ssize_t iio_read_channel_info(struct device *dev,
                scale_db = true;
        case IIO_VAL_INT_PLUS_MICRO:
                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" : "");
                else
                        return sprintf(buf, "%d.%06u%s\n", val, val2,
                                scale_db ? " dB" : "");
        case IIO_VAL_INT_PLUS_NANO:
                if (val2 < 0)
-                       return sprintf(buf, "-%d.%09u\n", val, -val2);
+                       return sprintf(buf, "-%ld.%09u\n", abs(val), -val2);
                else
                        return sprintf(buf, "%d.%09u\n", val, val2);
        case IIO_VAL_FRACTIONAL: