From: Lars-Peter Clausen <lars@metafoo.de>
To: Jean-Baptiste Maneyrol <jmaneyrol@invensense.com>, jic23@kernel.org
Cc: 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
Date: Tue, 28 Jun 2022 00:06:36 +0200 [thread overview]
Message-ID: <fde8b70b-a8c8-3e70-b55d-beede2bd7040@metafoo.de> (raw)
In-Reply-To: <20220627193402.21553-1-jmaneyrol@invensense.com>
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
next prev parent reply other threads:[~2022-06-27 22:08 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
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 [this message]
2022-06-28 8:04 ` Jean-Baptiste Maneyrol
2022-07-16 16:09 ` Jonathan Cameron
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=fde8b70b-a8c8-3e70-b55d-beede2bd7040@metafoo.de \
--to=lars@metafoo.de \
--cc=fawzi.khaber@tdk.com \
--cc=jean-baptiste.maneyrol@tdk.com \
--cc=jic23@kernel.org \
--cc=jmaneyrol@invensense.com \
--cc=linux-iio@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox