* [PATCH] iio: fix warnings about passing signed values to %u
@ 2020-11-28 15:56 Jonathan Cameron
2021-02-21 16:26 ` Jonathan Cameron
0 siblings, 1 reply; 2+ messages in thread
From: Jonathan Cameron @ 2020-11-28 15:56 UTC (permalink / raw)
To: linux-iio; +Cc: Jonathan Cameron, kernel test robot
From: Jonathan Cameron <Jonathan.Cameron@huawei.com>
In reality, we already know both of these values are positive
but it is still better to make that explicit at the point of use
with abs().
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Reported-by: kernel test robot <lkp@intel.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 c2e4c267c36b..00644666f7fe 100644
--- a/drivers/iio/industrialio-core.c
+++ b/drivers/iio/industrialio-core.c
@@ -608,14 +608,14 @@ static ssize_t __iio_format_value(char *buf, size_t len, unsigned int type,
return scnprintf(buf, len, "-%d.%06u%s", abs(vals[0]),
-vals[1], scale_db ? " dB" : "");
else
- return scnprintf(buf, len, "%d.%06u%s", vals[0], vals[1],
+ return scnprintf(buf, len, "%d.%06u%s", vals[0], abs(vals[1]),
scale_db ? " dB" : "");
case IIO_VAL_INT_PLUS_NANO:
if (vals[1] < 0)
return scnprintf(buf, len, "-%d.%09u", abs(vals[0]),
-vals[1]);
else
- return scnprintf(buf, len, "%d.%09u", vals[0], vals[1]);
+ return scnprintf(buf, len, "%d.%09u", vals[0], abs(vals[1]));
case IIO_VAL_FRACTIONAL:
tmp2 = div_s64((s64)vals[0] * 1000000000LL, vals[1]);
tmp1 = vals[1];
--
2.29.2
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] iio: fix warnings about passing signed values to %u
2020-11-28 15:56 [PATCH] iio: fix warnings about passing signed values to %u Jonathan Cameron
@ 2021-02-21 16:26 ` Jonathan Cameron
0 siblings, 0 replies; 2+ messages in thread
From: Jonathan Cameron @ 2021-02-21 16:26 UTC (permalink / raw)
To: linux-iio; +Cc: Jonathan Cameron, kernel test robot, Lars-Peter Clausen
On Sat, 28 Nov 2020 15:56:48 +0000
Jonathan Cameron <jic23@kernel.org> wrote:
> From: Jonathan Cameron <Jonathan.Cameron@huawei.com>
>
> In reality, we already know both of these values are positive
> but it is still better to make that explicit at the point of use
> with abs().
>
> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
> Reported-by: kernel test robot <lkp@intel.com>
Maintainers curse. If someone could sanity check this that would be great.
I never trust myself not to do anything stupid :)
Jonathan
> ---
> 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 c2e4c267c36b..00644666f7fe 100644
> --- a/drivers/iio/industrialio-core.c
> +++ b/drivers/iio/industrialio-core.c
> @@ -608,14 +608,14 @@ static ssize_t __iio_format_value(char *buf, size_t len, unsigned int type,
> return scnprintf(buf, len, "-%d.%06u%s", abs(vals[0]),
> -vals[1], scale_db ? " dB" : "");
> else
> - return scnprintf(buf, len, "%d.%06u%s", vals[0], vals[1],
> + return scnprintf(buf, len, "%d.%06u%s", vals[0], abs(vals[1]),
> scale_db ? " dB" : "");
> case IIO_VAL_INT_PLUS_NANO:
> if (vals[1] < 0)
> return scnprintf(buf, len, "-%d.%09u", abs(vals[0]),
> -vals[1]);
> else
> - return scnprintf(buf, len, "%d.%09u", vals[0], vals[1]);
> + return scnprintf(buf, len, "%d.%09u", vals[0], abs(vals[1]));
> case IIO_VAL_FRACTIONAL:
> tmp2 = div_s64((s64)vals[0] * 1000000000LL, vals[1]);
> tmp1 = vals[1];
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2021-02-21 16:27 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-11-28 15:56 [PATCH] iio: fix warnings about passing signed values to %u Jonathan Cameron
2021-02-21 16:26 ` Jonathan Cameron
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox