Re: [PATCH] iio: core: Avoid double minus in sysfs output

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 07/18/2013 05:47 PM, Oleksandr Kravchenko wrote:
> From: Oleksandr Kravchenko <o.v.kravchenko@xxxxxxxxxxxxxxx>
> 
> 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@xxxxxxxxxxxxxxx>
> ---
>  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:
> 

--
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




[Index of Archives]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Input]     [Linux Kernel]     [Linux SCSI]     [X.org]

  Powered by Linux