linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/2] tools: iio: generic_buffer fixes
@ 2015-07-23 17:22 Irina Tirdea
  2015-07-23 17:22 ` [PATCH 1/2] tools: iio: fix mask for 32 bit sensor data Irina Tirdea
  2015-07-23 17:22 ` [PATCH 2/2] tools: iio: print error message when buffer enable fails Irina Tirdea
  0 siblings, 2 replies; 6+ messages in thread
From: Irina Tirdea @ 2015-07-23 17:22 UTC (permalink / raw)
  To: Jonathan Cameron, linux-iio; +Cc: linux-kernel, Hartmut Knaack, Irina Tirdea

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(-)

-- 
1.9.1


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH 1/2] tools: iio: fix mask for 32 bit sensor data
  2015-07-23 17:22 [PATCH 0/2] tools: iio: generic_buffer fixes Irina Tirdea
@ 2015-07-23 17:22 ` Irina Tirdea
  2015-07-23 23:06   ` Hartmut Knaack
  2015-07-23 17:22 ` [PATCH 2/2] tools: iio: print error message when buffer enable fails Irina Tirdea
  1 sibling, 1 reply; 6+ messages in thread
From: Irina Tirdea @ 2015-07-23 17:22 UTC (permalink / raw)
  To: Jonathan Cameron, linux-iio; +Cc: linux-kernel, Hartmut Knaack, Irina Tirdea

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 <irina.tirdea@intel.com>
---
 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


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 2/2] tools: iio: print error message when buffer enable fails
  2015-07-23 17:22 [PATCH 0/2] tools: iio: generic_buffer fixes Irina Tirdea
  2015-07-23 17:22 ` [PATCH 1/2] tools: iio: fix mask for 32 bit sensor data Irina Tirdea
@ 2015-07-23 17:22 ` Irina Tirdea
  2015-07-23 23:13   ` Hartmut Knaack
  1 sibling, 1 reply; 6+ messages in thread
From: Irina Tirdea @ 2015-07-23 17:22 UTC (permalink / raw)
  To: Jonathan Cameron, linux-iio; +Cc: linux-kernel, Hartmut Knaack, 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.

Signed-off-by: Irina Tirdea <irina.tirdea@intel.com>
---
 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..936469c 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(errno));
 		goto error_free_buf_dir_name;
+	}
 
 	scan_size = size_from_channelarray(channels, num_channels);
 	data = malloc(scan_size * buf_len);
-- 
1.9.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH 1/2] tools: iio: fix mask for 32 bit sensor data
  2015-07-23 17:22 ` [PATCH 1/2] tools: iio: fix mask for 32 bit sensor data Irina Tirdea
@ 2015-07-23 23:06   ` Hartmut Knaack
  0 siblings, 0 replies; 6+ messages in thread
From: Hartmut Knaack @ 2015-07-23 23:06 UTC (permalink / raw)
  To: Irina Tirdea, Jonathan Cameron, linux-iio; +Cc: linux-kernel

Irina Tirdea schrieb am 23.07.2015 um 19:22:
> 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 <irina.tirdea@intel.com>
Acked-by: Hartmut Knaack <knaack.h@gmx.de>
> ---
>  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)) {
> 


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 2/2] tools: iio: print error message when buffer enable fails
  2015-07-23 17:22 ` [PATCH 2/2] tools: iio: print error message when buffer enable fails Irina Tirdea
@ 2015-07-23 23:13   ` Hartmut Knaack
  2015-07-24 13:27     ` Tirdea, Irina
  0 siblings, 1 reply; 6+ messages in thread
From: Hartmut Knaack @ 2015-07-23 23:13 UTC (permalink / raw)
  To: Irina Tirdea, Jonathan Cameron, linux-iio; +Cc: linux-kernel

Irina Tirdea schrieb am 23.07.2015 um 19:22:
> 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

> 
> Signed-off-by: Irina Tirdea <irina.tirdea@intel.com>
> ---
>  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..936469c 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(errno));
>  		goto error_free_buf_dir_name;
> +	}
>  
>  	scan_size = size_from_channelarray(channels, num_channels);
>  	data = malloc(scan_size * buf_len);
> 


^ permalink raw reply	[flat|nested] 6+ messages in thread

* RE: [PATCH 2/2] tools: iio: print error message when buffer enable fails
  2015-07-23 23:13   ` Hartmut Knaack
@ 2015-07-24 13:27     ` Tirdea, Irina
  0 siblings, 0 replies; 6+ messages in thread
From: Tirdea, Irina @ 2015-07-24 13:27 UTC (permalink / raw)
  To: Hartmut Knaack, Jonathan Cameron, linux-iio; +Cc: linux-kernel



> -----Original Message-----
> From: Hartmut Knaack [mailto:knaack.h@gmx.de]
> Sent: 24 July, 2015 2:13
> To: Tirdea, Irina; Jonathan Cameron; linux-iio@vger.kernel.org
> Cc: linux-kernel@vger.kernel.org
> Subject: Re: [PATCH 2/2] tools: iio: print error message when buffer enable fails
> 
> Irina Tirdea schrieb am 23.07.2015 um 19:22:
> > 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,
> 

Hi Hartmut,

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

Thanks,
Irina

> Hartmut
> 
> >
> > Signed-off-by: Irina Tirdea <irina.tirdea@intel.com>
> > ---
> >  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..936469c 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(errno));
> >  		goto error_free_buf_dir_name;
> > +	}
> >
> >  	scan_size = size_from_channelarray(channels, num_channels);
> >  	data = malloc(scan_size * buf_len);
> >


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2015-07-24 13:28 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-07-23 17:22 [PATCH 0/2] tools: iio: generic_buffer fixes Irina Tirdea
2015-07-23 17:22 ` [PATCH 1/2] tools: iio: fix mask for 32 bit sensor data Irina Tirdea
2015-07-23 23:06   ` Hartmut Knaack
2015-07-23 17:22 ` [PATCH 2/2] tools: iio: print error message when buffer enable fails Irina Tirdea
2015-07-23 23:13   ` Hartmut Knaack
2015-07-24 13:27     ` Tirdea, Irina

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