* [PATCH] iio: core: Avoid double minus in sysfs output
@ 2013-07-22 10:57 Oleksandr Kravchenko
0 siblings, 0 replies; 8+ messages in thread
From: Oleksandr Kravchenko @ 2013-07-22 10:57 UTC (permalink / raw)
To: jic23; +Cc: linux-iio, linux-kernel, Oleksandr Kravchenko
From: Oleksandr Kravchenko <o.v.kravchenko@globallogic.com>
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>
---
drivers/iio/industrialio-core.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c
index d56d122..455c24b 100644
--- a/drivers/iio/industrialio-core.c
+++ b/drivers/iio/industrialio-core.c
@@ -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,
- scale_db ? " dB" : "");
+ return sprintf(buf, "-%d.%06u%s\n", (int)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, "-%d.%09u\n", (int)abs(val), -val2);
else
return sprintf(buf, "%d.%09u\n", val, val2);
case IIO_VAL_FRACTIONAL:
--
1.7.9.5
^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH] iio: core: Avoid double minus in sysfs output
2013-07-22 11:16 Oleksandr Kravchenko
@ 2013-07-27 11:51 ` Jonathan Cameron
0 siblings, 0 replies; 8+ messages in thread
From: Jonathan Cameron @ 2013-07-27 11:51 UTC (permalink / raw)
To: Oleksandr Kravchenko; +Cc: jic23, linux-iio, linux-kernel, Oleksandr Kravchenko
On 07/22/13 12:16, Oleksandr Kravchenko wrote:
> From: Oleksandr Kravchenko <o.v.kravchenko@globallogic.com>
>
> 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>
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.
> ---
> drivers/iio/industrialio-core.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c
> index d56d122..97f0297 100644
> --- a/drivers/iio/industrialio-core.c
> +++ b/drivers/iio/industrialio-core.c
> @@ -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:
>
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH] iio: core: Avoid double minus in sysfs output
@ 2013-07-22 11:16 Oleksandr Kravchenko
2013-07-27 11:51 ` Jonathan Cameron
0 siblings, 1 reply; 8+ messages in thread
From: Oleksandr Kravchenko @ 2013-07-22 11:16 UTC (permalink / raw)
To: jic23; +Cc: linux-iio, linux-kernel, Oleksandr Kravchenko
From: Oleksandr Kravchenko <o.v.kravchenko@globallogic.com>
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>
---
drivers/iio/industrialio-core.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c
index d56d122..97f0297 100644
--- a/drivers/iio/industrialio-core.c
+++ b/drivers/iio/industrialio-core.c
@@ -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:
--
1.7.9.5
^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH] iio: core: Avoid double minus in sysfs output
2013-07-19 21:06 ` Jonathan Cameron
@ 2013-07-22 10:51 ` Oleksandr Kravchenko
0 siblings, 0 replies; 8+ messages in thread
From: Oleksandr Kravchenko @ 2013-07-22 10:51 UTC (permalink / raw)
To: Jonathan Cameron
Cc: Lars-Peter Clausen, Oleksandr Kravchenko, jic23, linux-iio, linux-kernel
Please ignore this patch for now. I'll rework it soon. It issues
warnings when compiling.
On Sat, Jul 20, 2013 at 12:06 AM, Jonathan Cameron <jic23@kernel.org> wrote:
> On 07/19/2013 07:15 AM, Oleksandr Kravchenko wrote:
>> On Thu, Jul 18, 2013 at 7:24 PM, Lars-Peter Clausen <lars@metafoo.de> wrote:
>>> On 07/18/2013 05:47 PM, Oleksandr Kravchenko wrote:
>>>> From: Oleksandr Kravchenko <o.v.kravchenko@globallogic.com>
>>>>
>>>> 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.
>>>>
>>>
>>> Hm, this might be a bug in a driver that is triggering this. The idea is
>>> that val2 is only allowed to be negative if val is 0.
>>>
>>> - Lars
>>>
>> If I calculate val and val2 in next way:
>> *val = adc / 1000000;
>> *val2 = adc % 1000000;
>> both val and val2 could by negative. Do I have to check it in my driver?
>>
> I guess it is will happen occasionally. In the c89 standard, module for a negative
> is implementation specific. Anyone know if we can assume this will work in all cases
> within the kernel?
--
Oleksandr Kravchenko
GlobalLogic
P +380633213187
P +380994930248
www.globallogic.com
http://www.globallogic.com/email_disclaimer.txt
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] iio: core: Avoid double minus in sysfs output
2013-07-19 6:15 ` Oleksandr Kravchenko
@ 2013-07-19 21:06 ` Jonathan Cameron
2013-07-22 10:51 ` Oleksandr Kravchenko
0 siblings, 1 reply; 8+ messages in thread
From: Jonathan Cameron @ 2013-07-19 21:06 UTC (permalink / raw)
To: Oleksandr Kravchenko
Cc: Lars-Peter Clausen, Oleksandr Kravchenko, jic23, linux-iio, linux-kernel
On 07/19/2013 07:15 AM, Oleksandr Kravchenko wrote:
> On Thu, Jul 18, 2013 at 7:24 PM, Lars-Peter Clausen <lars@metafoo.de> wrote:
>> On 07/18/2013 05:47 PM, Oleksandr Kravchenko wrote:
>>> From: Oleksandr Kravchenko <o.v.kravchenko@globallogic.com>
>>>
>>> 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.
>>>
>>
>> Hm, this might be a bug in a driver that is triggering this. The idea is
>> that val2 is only allowed to be negative if val is 0.
>>
>> - Lars
>>
> If I calculate val and val2 in next way:
> *val = adc / 1000000;
> *val2 = adc % 1000000;
> both val and val2 could by negative. Do I have to check it in my driver?
>
I guess it is will happen occasionally. In the c89 standard, module for a negative
is implementation specific. Anyone know if we can assume this will work in all cases
within the kernel?
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] iio: core: Avoid double minus in sysfs output
2013-07-18 16:24 ` Lars-Peter Clausen
@ 2013-07-19 6:15 ` Oleksandr Kravchenko
2013-07-19 21:06 ` Jonathan Cameron
0 siblings, 1 reply; 8+ messages in thread
From: Oleksandr Kravchenko @ 2013-07-19 6:15 UTC (permalink / raw)
To: Lars-Peter Clausen; +Cc: Oleksandr Kravchenko, jic23, linux-iio, linux-kernel
On Thu, Jul 18, 2013 at 7:24 PM, Lars-Peter Clausen <lars@metafoo.de> wrote:
> On 07/18/2013 05:47 PM, Oleksandr Kravchenko wrote:
>> From: Oleksandr Kravchenko <o.v.kravchenko@globallogic.com>
>>
>> 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.
>>
>
> Hm, this might be a bug in a driver that is triggering this. The idea is
> that val2 is only allowed to be negative if val is 0.
>
> - Lars
>
If I calculate val and val2 in next way:
*val = adc / 1000000;
*val2 = adc % 1000000;
both val and val2 could by negative. Do I have to check it in my driver?
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] iio: core: Avoid double minus in sysfs output
2013-07-18 15:47 Oleksandr Kravchenko
@ 2013-07-18 16:24 ` Lars-Peter Clausen
2013-07-19 6:15 ` Oleksandr Kravchenko
0 siblings, 1 reply; 8+ messages in thread
From: Lars-Peter Clausen @ 2013-07-18 16:24 UTC (permalink / raw)
To: Oleksandr Kravchenko; +Cc: jic23, linux-iio, linux-kernel, Oleksandr Kravchenko
On 07/18/2013 05:47 PM, Oleksandr Kravchenko wrote:
> From: Oleksandr Kravchenko <o.v.kravchenko@globallogic.com>
>
> 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.
>
Hm, this might be a bug in a driver that is triggering this. The idea is
that val2 is only allowed to be negative if val is 0.
- Lars
> Signed-off-by: Oleksandr Kravchenko <o.v.kravchenko@globallogic.com>
> ---
> drivers/iio/industrialio-core.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c
> index d56d122..b3d3959 100644
> --- a/drivers/iio/industrialio-core.c
> +++ b/drivers/iio/industrialio-core.c
> @@ -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, "-%d.%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, "-%d.%09u\n", abs(val), -val2);
> else
> return sprintf(buf, "%d.%09u\n", val, val2);
> case IIO_VAL_FRACTIONAL:
>
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH] iio: core: Avoid double minus in sysfs output
@ 2013-07-18 15:47 Oleksandr Kravchenko
2013-07-18 16:24 ` Lars-Peter Clausen
0 siblings, 1 reply; 8+ messages in thread
From: Oleksandr Kravchenko @ 2013-07-18 15:47 UTC (permalink / raw)
To: jic23; +Cc: linux-iio, linux-kernel, Oleksandr Kravchenko
From: Oleksandr Kravchenko <o.v.kravchenko@globallogic.com>
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>
---
drivers/iio/industrialio-core.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c
index d56d122..b3d3959 100644
--- a/drivers/iio/industrialio-core.c
+++ b/drivers/iio/industrialio-core.c
@@ -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, "-%d.%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, "-%d.%09u\n", abs(val), -val2);
else
return sprintf(buf, "%d.%09u\n", val, val2);
case IIO_VAL_FRACTIONAL:
--
1.7.9.5
^ permalink raw reply related [flat|nested] 8+ messages in thread
end of thread, other threads:[~2013-07-27 10:51 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-07-22 10:57 [PATCH] iio: core: Avoid double minus in sysfs output Oleksandr Kravchenko
-- strict thread matches above, loose matches on Subject: below --
2013-07-22 11:16 Oleksandr Kravchenko
2013-07-27 11:51 ` Jonathan Cameron
2013-07-18 15:47 Oleksandr Kravchenko
2013-07-18 16:24 ` Lars-Peter Clausen
2013-07-19 6:15 ` Oleksandr Kravchenko
2013-07-19 21:06 ` Jonathan Cameron
2013-07-22 10:51 ` Oleksandr Kravchenko
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.