Skip to contentSkip to conversation

iio: core: Avoid double minus in sysfs output

PATCH Applied Oleksandr Kravchenko 2 participants 2 messages Jul 22, 2013 – Jul 27, 2013 IIO

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 iio: core: Avoid double minus in sysfs output

From: Oleksandr Kravchenko <[email protected]>

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.

---
 drivers/iio/industrialio-core.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/iio/industrialio-core.c +2 -2
index d56d122..97f0297 100644
@@ -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:
Signature · 1 line
1.7.9.5
maintainer Applied
#1 lore raw
Quoted 9 lines · Oleksandr Kravchenko

From: Oleksandr Kravchenko <[email protected]>

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.

Applied to the togreg branch of iio.git

Not taken this as a fix as I don't know of any current drivers where this will be a problem.

Thanks.

Quoted 26 lines
---
 drivers/iio/industrialio-core.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/iio/industrialio-core.c +2 -2
index d56d122..97f0297 100644
@@ -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: