* [PATCH] iio: fix iio_format_avail_range() printing for none IIO_VAL_INT
@ 2022-06-27 19:34 Jean-Baptiste Maneyrol
2022-06-27 22:06 ` Lars-Peter Clausen
2022-07-16 16:09 ` Jonathan Cameron
0 siblings, 2 replies; 4+ messages in thread
From: Jean-Baptiste Maneyrol @ 2022-06-27 19:34 UTC (permalink / raw)
To: jic23, lars; +Cc: linux-iio, Fawzi Khaber, Jean-Baptiste Maneyrol
From: Fawzi Khaber <fawzi.khaber@tdk.com>
iio_format_avail_range() should print range as follow [min, step, max], so
the function was previously calling iio_format_list() with length = 3,
length variable refers to the array size of values not the number of
elements. In case of non IIO_VAL_INT values each element has integer part
and decimal part. With length = 3 this would cause premature end of loop
and result in printing only one element.
Signed-off-by: Fawzi Khaber <fawzi.khaber@tdk.com>
Signed-off-by: Jean-Baptiste Maneyrol <jean-baptiste.maneyrol@tdk.com>
---
drivers/iio/industrialio-core.c | 18 +++++++++++++++++-
1 file changed, 17 insertions(+), 1 deletion(-)
diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c
index 358b909298c0..0f4dbda3b9d3 100644
--- a/drivers/iio/industrialio-core.c
+++ b/drivers/iio/industrialio-core.c
@@ -812,7 +812,23 @@ static ssize_t iio_format_avail_list(char *buf, const int *vals,
static ssize_t iio_format_avail_range(char *buf, const int *vals, int type)
{
- return iio_format_list(buf, vals, type, 3, "[", "]");
+ int length;
+
+ /*
+ * length refers to the array size , not the number of elements.
+ * The purpose is to print the range [min , step ,max] so length should
+ * be 3 in case of int, and 6 for other types.
+ */
+ switch (type) {
+ case IIO_VAL_INT:
+ length = 3;
+ break;
+ default:
+ length = 6;
+ break;
+ }
+
+ return iio_format_list(buf, vals, type, length, "[", "]");
}
static ssize_t iio_read_channel_info_avail(struct device *dev,
--
2.17.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] iio: fix iio_format_avail_range() printing for none IIO_VAL_INT
2022-06-27 19:34 [PATCH] iio: fix iio_format_avail_range() printing for none IIO_VAL_INT Jean-Baptiste Maneyrol
@ 2022-06-27 22:06 ` Lars-Peter Clausen
2022-06-28 8:04 ` Jean-Baptiste Maneyrol
2022-07-16 16:09 ` Jonathan Cameron
1 sibling, 1 reply; 4+ messages in thread
From: Lars-Peter Clausen @ 2022-06-27 22:06 UTC (permalink / raw)
To: Jean-Baptiste Maneyrol, jic23
Cc: linux-iio, Fawzi Khaber, Jean-Baptiste Maneyrol
On 6/27/22 21:34, Jean-Baptiste Maneyrol wrote:
> From: Fawzi Khaber <fawzi.khaber@tdk.com>
>
> iio_format_avail_range() should print range as follow [min, step, max], so
> the function was previously calling iio_format_list() with length = 3,
> length variable refers to the array size of values not the number of
> elements. In case of non IIO_VAL_INT values each element has integer part
> and decimal part. With length = 3 this would cause premature end of loop
> and result in printing only one element.
>
> Signed-off-by: Fawzi Khaber <fawzi.khaber@tdk.com>
> Signed-off-by: Jean-Baptiste Maneyrol <jean-baptiste.maneyrol@tdk.com>
> ---
> drivers/iio/industrialio-core.c | 18 +++++++++++++++++-
> 1 file changed, 17 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c
> index 358b909298c0..0f4dbda3b9d3 100644
> --- a/drivers/iio/industrialio-core.c
> +++ b/drivers/iio/industrialio-core.c
> @@ -812,7 +812,23 @@ static ssize_t iio_format_avail_list(char *buf, const int *vals,
>
> static ssize_t iio_format_avail_range(char *buf, const int *vals, int type)
> {
> - return iio_format_list(buf, vals, type, 3, "[", "]");
> + int length;
> +
> + /*
> + * length refers to the array size , not the number of elements.
> + * The purpose is to print the range [min , step ,max] so length should
> + * be 3 in case of int, and 6 for other types.
> + */
> + switch (type) {
> + case IIO_VAL_INT:
> + length = 3;
> + break;
> + default:
> + length = 6;
> + break;
> + }
> +
> + return iio_format_list(buf, vals, type, length, "[", "]");
> }
>
> static ssize_t iio_read_channel_info_avail(struct device *dev,
Change looks good! Lets also add a unit test for this in iio-test-format.c
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] iio: fix iio_format_avail_range() printing for none IIO_VAL_INT
2022-06-27 22:06 ` Lars-Peter Clausen
@ 2022-06-28 8:04 ` Jean-Baptiste Maneyrol
0 siblings, 0 replies; 4+ messages in thread
From: Jean-Baptiste Maneyrol @ 2022-06-28 8:04 UTC (permalink / raw)
To: Lars-Peter Clausen, Jean-Baptiste Maneyrol, jic23; +Cc: linux-iio, Fawzi Khaber
Hello Lars,
iio-test-format.c is for testing iio_format_value() function, not iio_format_avail_range(). And the problem with this function is that it is only a static helper in industrialio_core.c. The main function is iio_read_channel_info_avail(), which doesn't look to be easily testable.
Thanks,
JB
From: Lars-Peter Clausen <lars@metafoo.de>
Sent: Tuesday, June 28, 2022 00:06
To: Jean-Baptiste Maneyrol <jmaneyrol@invensense.com>; jic23@kernel.org <jic23@kernel.org>
Cc: linux-iio@vger.kernel.org <linux-iio@vger.kernel.org>; Fawzi Khaber <Fawzi.Khaber@tdk.com>; Jean-Baptiste Maneyrol <Jean-Baptiste.Maneyrol@tdk.com>
Subject: Re: [PATCH] iio: fix iio_format_avail_range() printing for none IIO_VAL_INT
[CAUTION] This is EXTERNAL email. Do not click any links or open attachments unless you recognize the sender and know the content is safe.
======================================================================
On 6/27/22 21:34, Jean-Baptiste Maneyrol wrote:
> From: Fawzi Khaber <fawzi.khaber@tdk.com>
>
> iio_format_avail_range() should print range as follow [min, step, max], so
> the function was previously calling iio_format_list() with length = 3,
> length variable refers to the array size of values not the number of
> elements. In case of non IIO_VAL_INT values each element has integer part
> and decimal part. With length = 3 this would cause premature end of loop
> and result in printing only one element.
>
> Signed-off-by: Fawzi Khaber <fawzi.khaber@tdk.com>
> Signed-off-by: Jean-Baptiste Maneyrol <jean-baptiste.maneyrol@tdk.com>
> ---
> drivers/iio/industrialio-core.c | 18 +++++++++++++++++-
> 1 file changed, 17 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c
> index 358b909298c0..0f4dbda3b9d3 100644
> --- a/drivers/iio/industrialio-core.c
> +++ b/drivers/iio/industrialio-core.c
> @@ -812,7 +812,23 @@ static ssize_t iio_format_avail_list(char *buf, const int *vals,
>
> static ssize_t iio_format_avail_range(char *buf, const int *vals, int type)
> {
> - return iio_format_list(buf, vals, type, 3, "[", "]");
> + int length;
> +
> + /*
> + * length refers to the array size , not the number of elements.
> + * The purpose is to print the range [min , step ,max] so length should
> + * be 3 in case of int, and 6 for other types.
> + */
> + switch (type) {
> + case IIO_VAL_INT:
> + length = 3;
> + break;
> + default:
> + length = 6;
> + break;
> + }
> +
> + return iio_format_list(buf, vals, type, length, "[", "]");
> }
>
> static ssize_t iio_read_channel_info_avail(struct device *dev,
Change looks good! Lets also add a unit test for this in iio-test-format.c
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] iio: fix iio_format_avail_range() printing for none IIO_VAL_INT
2022-06-27 19:34 [PATCH] iio: fix iio_format_avail_range() printing for none IIO_VAL_INT Jean-Baptiste Maneyrol
2022-06-27 22:06 ` Lars-Peter Clausen
@ 2022-07-16 16:09 ` Jonathan Cameron
1 sibling, 0 replies; 4+ messages in thread
From: Jonathan Cameron @ 2022-07-16 16:09 UTC (permalink / raw)
To: Jean-Baptiste Maneyrol
Cc: lars, linux-iio, Fawzi Khaber, Jean-Baptiste Maneyrol
On Mon, 27 Jun 2022 21:34:02 +0200
Jean-Baptiste Maneyrol <jmaneyrol@invensense.com> wrote:
> From: Fawzi Khaber <fawzi.khaber@tdk.com>
>
> iio_format_avail_range() should print range as follow [min, step, max], so
> the function was previously calling iio_format_list() with length = 3,
> length variable refers to the array size of values not the number of
> elements. In case of non IIO_VAL_INT values each element has integer part
> and decimal part. With length = 3 this would cause premature end of loop
> and result in printing only one element.
>
> Signed-off-by: Fawzi Khaber <fawzi.khaber@tdk.com>
> Signed-off-by: Jean-Baptiste Maneyrol <jean-baptiste.maneyrol@tdk.com>
Fixes tag?
Otherwise looks good to me.
> ---
> drivers/iio/industrialio-core.c | 18 +++++++++++++++++-
> 1 file changed, 17 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c
> index 358b909298c0..0f4dbda3b9d3 100644
> --- a/drivers/iio/industrialio-core.c
> +++ b/drivers/iio/industrialio-core.c
> @@ -812,7 +812,23 @@ static ssize_t iio_format_avail_list(char *buf, const int *vals,
>
> static ssize_t iio_format_avail_range(char *buf, const int *vals, int type)
> {
> - return iio_format_list(buf, vals, type, 3, "[", "]");
> + int length;
> +
> + /*
> + * length refers to the array size , not the number of elements.
> + * The purpose is to print the range [min , step ,max] so length should
> + * be 3 in case of int, and 6 for other types.
> + */
> + switch (type) {
> + case IIO_VAL_INT:
> + length = 3;
> + break;
> + default:
> + length = 6;
> + break;
> + }
> +
> + return iio_format_list(buf, vals, type, length, "[", "]");
> }
>
> static ssize_t iio_read_channel_info_avail(struct device *dev,
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2022-07-16 15:59 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-27 19:34 [PATCH] iio: fix iio_format_avail_range() printing for none IIO_VAL_INT Jean-Baptiste Maneyrol
2022-06-27 22:06 ` Lars-Peter Clausen
2022-06-28 8:04 ` Jean-Baptiste Maneyrol
2022-07-16 16:09 ` Jonathan Cameron
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).