2015-07-24 13:28:43

by Tirdea, Irina

[permalink] [raw]
Subject: [PATCH v2 0/2] tools: iio: generic_buffer fixes

Fixes for a couple of small issues found while testing the
bmc150_magn driver.

Changes in v2:
- use ret instead of errno to print error message
- add Hartmut's Ack for the first patch

Irina Tirdea (2):
tools: iio: fix mask for 32 bit sensor data
tools: iio: print error message when buffer enable fails

tools/iio/generic_buffer.c | 5 ++++-
tools/iio/iio_utils.c | 2 +-
2 files changed, 5 insertions(+), 2 deletions(-)

--
1.9.1


2015-07-24 13:29:30

by Tirdea, Irina

[permalink] [raw]
Subject: [PATCH v2 1/2] tools: iio: fix mask for 32 bit sensor data

When the the sensor data uses 32 bits out of 32, generic_buffer prints
the value 0 for all data read.

In this case, the mask is shifted 32 bits, which is beyond the size of
an integer. This will lead to the mask always being 0. Before printing,
the mask is applied to the raw value, thus generating a final value of 0.

Fix the mask by shifting a 64 bit value instead of an integer.

Signed-off-by: Irina Tirdea <[email protected]>
Acked-by: Hartmut Knaack <[email protected]>
---
tools/iio/iio_utils.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/iio/iio_utils.c b/tools/iio/iio_utils.c
index 1dcdf03..a95270f 100644
--- a/tools/iio/iio_utils.c
+++ b/tools/iio/iio_utils.c
@@ -168,7 +168,7 @@ int iioutils_get_type(unsigned *is_signed, unsigned *bytes, unsigned *bits_used,
if (*bits_used == 64)
*mask = ~0;
else
- *mask = (1 << *bits_used) - 1;
+ *mask = (1ULL << *bits_used) - 1;

*is_signed = (signchar == 's');
if (fclose(sysfsfp)) {
--
1.9.1

2015-07-24 13:29:12

by Tirdea, Irina

[permalink] [raw]
Subject: [PATCH v2 2/2] tools: iio: print error message when buffer enable fails

Running generic_buffer without enabling any channel of the
sensor will fail without printing any error message.

Add an error message that indicates buffer enable failed.

Signed-off-by: Irina Tirdea <[email protected]>
---
tools/iio/generic_buffer.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/tools/iio/generic_buffer.c b/tools/iio/generic_buffer.c
index 32f389eb..9f7b85b 100644
--- a/tools/iio/generic_buffer.c
+++ b/tools/iio/generic_buffer.c
@@ -364,8 +364,11 @@ int main(int argc, char **argv)

/* Enable the buffer */
ret = write_sysfs_int("enable", buf_dir_name, 1);
- if (ret < 0)
+ if (ret < 0) {
+ fprintf(stderr,
+ "Failed to enable buffer: %s\n", strerror(-ret));
goto error_free_buf_dir_name;
+ }

scan_size = size_from_channelarray(channels, num_channels);
data = malloc(scan_size * buf_len);
--
1.9.1

2015-07-24 18:23:49

by Hartmut Knaack

[permalink] [raw]
Subject: Re: [PATCH v2 2/2] tools: iio: print error message when buffer enable fails

Irina Tirdea schrieb am 24.07.2015 um 15:28:
> Running generic_buffer without enabling any channel of the
> sensor will fail without printing any error message.
>
> Add an error message that indicates buffer enable failed.
>
> Signed-off-by: Irina Tirdea <[email protected]>
Acked-by: Hartmut Knaack <[email protected]>
> ---
> tools/iio/generic_buffer.c | 5 ++++-
> 1 file changed, 4 insertions(+), 1 deletion(-)
>
> diff --git a/tools/iio/generic_buffer.c b/tools/iio/generic_buffer.c
> index 32f389eb..9f7b85b 100644
> --- a/tools/iio/generic_buffer.c
> +++ b/tools/iio/generic_buffer.c
> @@ -364,8 +364,11 @@ int main(int argc, char **argv)
>
> /* Enable the buffer */
> ret = write_sysfs_int("enable", buf_dir_name, 1);
> - if (ret < 0)
> + if (ret < 0) {
> + fprintf(stderr,
> + "Failed to enable buffer: %s\n", strerror(-ret));
> goto error_free_buf_dir_name;
> + }
>
> scan_size = size_from_channelarray(channels, num_channels);
> data = malloc(scan_size * buf_len);
>

2015-08-02 17:38:57

by Jonathan Cameron

[permalink] [raw]
Subject: Re: [PATCH v2 1/2] tools: iio: fix mask for 32 bit sensor data

On 24/07/15 14:28, Irina Tirdea wrote:
> When the the sensor data uses 32 bits out of 32, generic_buffer prints
> the value 0 for all data read.
>
> In this case, the mask is shifted 32 bits, which is beyond the size of
> an integer. This will lead to the mask always being 0. Before printing,
> the mask is applied to the raw value, thus generating a final value of 0.
>
> Fix the mask by shifting a 64 bit value instead of an integer.
>
> Signed-off-by: Irina Tirdea <[email protected]>
> Acked-by: Hartmut Knaack <[email protected]>
Applied to the togreg branch of iio.git
Pushed out as testing for the autobuilders to completely
ignore this patch :)

Jonathan
> ---
> tools/iio/iio_utils.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/tools/iio/iio_utils.c b/tools/iio/iio_utils.c
> index 1dcdf03..a95270f 100644
> --- a/tools/iio/iio_utils.c
> +++ b/tools/iio/iio_utils.c
> @@ -168,7 +168,7 @@ int iioutils_get_type(unsigned *is_signed, unsigned *bytes, unsigned *bits_used,
> if (*bits_used == 64)
> *mask = ~0;
> else
> - *mask = (1 << *bits_used) - 1;
> + *mask = (1ULL << *bits_used) - 1;
>
> *is_signed = (signchar == 's');
> if (fclose(sysfsfp)) {
>

2015-08-02 17:39:59

by Jonathan Cameron

[permalink] [raw]
Subject: Re: [PATCH v2 2/2] tools: iio: print error message when buffer enable fails

On 24/07/15 19:23, Hartmut Knaack wrote:
> Irina Tirdea schrieb am 24.07.2015 um 15:28:
>> Running generic_buffer without enabling any channel of the
>> sensor will fail without printing any error message.
>>
>> Add an error message that indicates buffer enable failed.
>>
>> Signed-off-by: Irina Tirdea <[email protected]>
> Acked-by: Hartmut Knaack <[email protected]>
Applied.

Thanks

Jonathan
>> ---
>> tools/iio/generic_buffer.c | 5 ++++-
>> 1 file changed, 4 insertions(+), 1 deletion(-)
>>
>> diff --git a/tools/iio/generic_buffer.c b/tools/iio/generic_buffer.c
>> index 32f389eb..9f7b85b 100644
>> --- a/tools/iio/generic_buffer.c
>> +++ b/tools/iio/generic_buffer.c
>> @@ -364,8 +364,11 @@ int main(int argc, char **argv)
>>
>> /* Enable the buffer */
>> ret = write_sysfs_int("enable", buf_dir_name, 1);
>> - if (ret < 0)
>> + if (ret < 0) {
>> + fprintf(stderr,
>> + "Failed to enable buffer: %s\n", strerror(-ret));
>> goto error_free_buf_dir_name;
>> + }
>>
>> scan_size = size_from_channelarray(channels, num_channels);
>> data = malloc(scan_size * buf_len);
>>
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-iio" in
> the body of a message to [email protected]
> More majordomo info at http://vger.kernel.org/majordomo-info.html
>