Skip to content

Commit

Permalink
iio: fix iio_format_avail_range() printing for none IIO_VAL_INT
Browse files Browse the repository at this point in the history
commit 5e1f918 upstream.

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: eda20ba ("iio: core: Consolidate iio_format_avail_{list,range}()")
Link: https://lore.kernel.org/r/20220718130706.32571-1-jmaneyrol@invensense.com
Cc: <Stable@vger.kernel.org>
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
  • Loading branch information
fkhaber-invn authored and gregkh committed Aug 17, 2022
1 parent cac7ead commit a76771d
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion drivers/iio/industrialio-core.c
Original file line number Diff line number Diff line change
Expand Up @@ -818,7 +818,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,
Expand Down

0 comments on commit a76771d

Please sign in to comment.