Skip to contentSkip to conversation

tools: iio: generic_buffer fixes

PATCH Superseded Irina Tirdea 2 participants 6 messages Jul 23, 2015 – Jul 24, 2015 IIO

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover tools: iio: generic_buffer fixes

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

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(-)
Signature · 1 line
1.9.1
#1 lore raw

PATCH 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.

---
 tools/iio/iio_utils.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/iio/iio_utils.c +1 -1
index 1dcdf03..a95270f 100644
@@ -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)) {
Signature · 1 line
1.9.1
Acked-by on v1 1/2
#2 lore raw

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

Irina Tirdea schrieb am 23.07.2015 um 19:22:

Quoted 10 lines

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.

Quoted 18 lines
---
 tools/iio/iio_utils.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/iio/iio_utils.c +1 -1
index 1dcdf03..a95270f 100644
@@ -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)) {
#3 lore raw

PATCH 2/2 tools: iio: print error message when buffer enable fails

In reply to Irina Tirdea

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.

---
 tools/iio/generic_buffer.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
tools/iio/generic_buffer.c +4 -1
index 32f389eb..936469c 100644
@@ -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(errno));
 		goto error_free_buf_dir_name;
+	}
 
 	scan_size = size_from_channelarray(channels, num_channels);
 	data = malloc(scan_size * buf_len);
Signature · 1 line
1.9.1
#4 lore raw

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

Irina Tirdea schrieb am 23.07.2015 um 19:22:

Quoted 4 lines

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.

Hi,
please make use of the error code stored in ret (with negative sign), as in most cases the value of errno has already changed since the original error has occurred.
Thanks,

Hartmut

Quoted 24 lines
---
 tools/iio/generic_buffer.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
tools/iio/generic_buffer.c +4 -1
index 32f389eb..936469c 100644
@@ -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(errno));
 		goto error_free_buf_dir_name;
+	}
 
 	scan_size = size_from_channelarray(channels, num_channels);
 	data = malloc(scan_size * buf_len);
#5 lore raw

RE: [PATCH 2/2] tools: iio: print error message when buffer enable fails

Quoted 8 lines

-----Original Message-----
From: Hartmut Knaack [mailto:[email protected]]
Sent: 24 July, 2015 2:13
To: Tirdea, Irina; Jonathan Cameron; [email protected]
Cc: [email protected]
Subject: Re: [PATCH 2/2] tools: iio: print error message when buffer enab=

le fails

Quoted 5 lines

=20
Irina Tirdea schrieb am 23.07.2015 um 19:22:

Quoted 3 lines

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

Quoted 8 lines
Quoted 1 line

Add an error message that indicates buffer enable failed.

=20
Hi,
please make use of the error code stored in ret (with negative sign), as in most cases the value of errno has already changed since the original error has occurred.
Thanks,
=20

Hi Hartmut,

Yes, you are right. Missed that. Will fix in v2.

Thanks,
Irina

Quoted 26 lines

Hartmut
=20

Quoted 24 lines
---
 tools/iio/generic_buffer.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
tools/iio/generic_buffer.c +4 -1
index 32f389eb..936469c 100644
@@ -364,8 +364,11 @@ int main(int argc, char **argv)
 
 	/* Enable the buffer */
 	ret =3D write_sysfs_int("enable", buf_dir_name, 1);
-	if (ret < 0)
+	if (ret < 0) {
+		fprintf(stderr,
+			"Failed to enable buffer: %s\n", strerror(errno));
 		goto error_free_buf_dir_name;
+	}
 
 	scan_size =3D size_from_channelarray(channels, num_channels);
 	data =3D malloc(scan_size * buf_len);