All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/3] iio: Do not accept multiple '.' in fixed point numbers
@ 2012-10-22 11:15 Lars-Peter Clausen
  2012-10-22 11:15 ` [PATCH 2/3] iio: Reject trailing garbage when parsing " Lars-Peter Clausen
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Lars-Peter Clausen @ 2012-10-22 11:15 UTC (permalink / raw)
  To: Jonathan Cameron; +Cc: linux-iio, Lars-Peter Clausen

Currently when parsing a fix-point number we silently skip any additional '.'
found in the string.  E.g. '1.2.3.4' gets parsed as '1.234'. This patch
disallows this and returns an error if more than one '.' is encountered.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
---
 drivers/iio/industrialio-core.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c
index 6eb24db..a2e9953 100644
--- a/drivers/iio/industrialio-core.c
+++ b/drivers/iio/industrialio-core.c
@@ -449,7 +449,7 @@ static ssize_t iio_write_channel_info(struct device *dev,
 				break;
 			else
 				return -EINVAL;
-		} else if (*buf == '.') {
+		} else if (*buf == '.' && integer_part) {
 			integer_part = false;
 		} else {
 			return -EINVAL;
-- 
1.7.10.4


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

* [PATCH 2/3] iio: Reject trailing garbage when parsing fixed point numbers
  2012-10-22 11:15 [PATCH 1/3] iio: Do not accept multiple '.' in fixed point numbers Lars-Peter Clausen
@ 2012-10-22 11:15 ` Lars-Peter Clausen
  2012-11-02  9:45   ` Jonathan Cameron
  2012-10-22 11:15 ` [PATCH 3/3] iio: Accept a leading '+' sign " Lars-Peter Clausen
  2012-11-02  9:44 ` [PATCH 1/3] iio: Do not accept multiple '.' in " Jonathan Cameron
  2 siblings, 1 reply; 6+ messages in thread
From: Lars-Peter Clausen @ 2012-10-22 11:15 UTC (permalink / raw)
  To: Jonathan Cameron; +Cc: linux-iio, Lars-Peter Clausen

When parsing a fixed point number IIO stops parsing the string once it has
reached the last requested decimal place. This means that the remainder of the
string is silently accepted regardless, of whether it is part of a valid number
or not. This patch modifies the code to scan the whole string and only accept
valid numbers. Since fract_mult is 0 after the last decimal place any digit that
may follows won't affect the result.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
---
 drivers/iio/industrialio-core.c |    2 --
 1 file changed, 2 deletions(-)

diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c
index a2e9953..fe593bf 100644
--- a/drivers/iio/industrialio-core.c
+++ b/drivers/iio/industrialio-core.c
@@ -440,8 +440,6 @@ static ssize_t iio_write_channel_info(struct device *dev,
 				integer = integer*10 + *buf - '0';
 			else {
 				fract += fract_mult*(*buf - '0');
-				if (fract_mult == 1)
-					break;
 				fract_mult /= 10;
 			}
 		} else if (*buf == '\n') {
-- 
1.7.10.4


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

* [PATCH 3/3] iio: Accept a leading '+' sign when parsing fixed point numbers
  2012-10-22 11:15 [PATCH 1/3] iio: Do not accept multiple '.' in fixed point numbers Lars-Peter Clausen
  2012-10-22 11:15 ` [PATCH 2/3] iio: Reject trailing garbage when parsing " Lars-Peter Clausen
@ 2012-10-22 11:15 ` Lars-Peter Clausen
  2012-11-02  9:46   ` Jonathan Cameron
  2012-11-02  9:44 ` [PATCH 1/3] iio: Do not accept multiple '.' in " Jonathan Cameron
  2 siblings, 1 reply; 6+ messages in thread
From: Lars-Peter Clausen @ 2012-10-22 11:15 UTC (permalink / raw)
  To: Jonathan Cameron; +Cc: linux-iio, Lars-Peter Clausen

If we encounter a leading '+' sign just skip over it.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
---
 drivers/iio/industrialio-core.c |    2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c
index fe593bf..5f8ff0d 100644
--- a/drivers/iio/industrialio-core.c
+++ b/drivers/iio/industrialio-core.c
@@ -432,6 +432,8 @@ static ssize_t iio_write_channel_info(struct device *dev,
 	if (buf[0] == '-') {
 		negative = true;
 		buf++;
+	} else if (buf[0] == '+') {
+		buf++;
 	}
 
 	while (*buf) {
-- 
1.7.10.4


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

* Re: [PATCH 1/3] iio: Do not accept multiple '.' in fixed point numbers
  2012-10-22 11:15 [PATCH 1/3] iio: Do not accept multiple '.' in fixed point numbers Lars-Peter Clausen
  2012-10-22 11:15 ` [PATCH 2/3] iio: Reject trailing garbage when parsing " Lars-Peter Clausen
  2012-10-22 11:15 ` [PATCH 3/3] iio: Accept a leading '+' sign " Lars-Peter Clausen
@ 2012-11-02  9:44 ` Jonathan Cameron
  2 siblings, 0 replies; 6+ messages in thread
From: Jonathan Cameron @ 2012-11-02  9:44 UTC (permalink / raw)
  To: Lars-Peter Clausen; +Cc: Jonathan Cameron, linux-iio

On 10/22/2012 12:15 PM, Lars-Peter Clausen wrote:
> Currently when parsing a fix-point number we silently skip any additional '.'
> found in the string.  E.g. '1.2.3.4' gets parsed as '1.234'. This patch
> disallows this and returns an error if more than one '.' is encountered.
> 
> Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
Added to togreg branch of iio.git

> ---
>  drivers/iio/industrialio-core.c |    2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c
> index 6eb24db..a2e9953 100644
> --- a/drivers/iio/industrialio-core.c
> +++ b/drivers/iio/industrialio-core.c
> @@ -449,7 +449,7 @@ static ssize_t iio_write_channel_info(struct device *dev,
>  				break;
>  			else
>  				return -EINVAL;
> -		} else if (*buf == '.') {
> +		} else if (*buf == '.' && integer_part) {
>  			integer_part = false;
>  		} else {
>  			return -EINVAL;
> 

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

* Re: [PATCH 2/3] iio: Reject trailing garbage when parsing fixed point numbers
  2012-10-22 11:15 ` [PATCH 2/3] iio: Reject trailing garbage when parsing " Lars-Peter Clausen
@ 2012-11-02  9:45   ` Jonathan Cameron
  0 siblings, 0 replies; 6+ messages in thread
From: Jonathan Cameron @ 2012-11-02  9:45 UTC (permalink / raw)
  To: Lars-Peter Clausen; +Cc: Jonathan Cameron, linux-iio

On 10/22/2012 12:15 PM, Lars-Peter Clausen wrote:
> When parsing a fixed point number IIO stops parsing the string once it has
> reached the last requested decimal place. This means that the remainder of the
> string is silently accepted regardless, of whether it is part of a valid number
> or not. This patch modifies the code to scan the whole string and only accept
> valid numbers. Since fract_mult is 0 after the last decimal place any digit that
> may follows won't affect the result.
> 
> Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
Nice little trick.

Added to togreg branch of iio.git

> ---
>  drivers/iio/industrialio-core.c |    2 --
>  1 file changed, 2 deletions(-)
> 
> diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c
> index a2e9953..fe593bf 100644
> --- a/drivers/iio/industrialio-core.c
> +++ b/drivers/iio/industrialio-core.c
> @@ -440,8 +440,6 @@ static ssize_t iio_write_channel_info(struct device *dev,
>  				integer = integer*10 + *buf - '0';
>  			else {
>  				fract += fract_mult*(*buf - '0');
> -				if (fract_mult == 1)
> -					break;
>  				fract_mult /= 10;
>  			}
>  		} else if (*buf == '\n') {
> 

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

* Re: [PATCH 3/3] iio: Accept a leading '+' sign when parsing fixed point numbers
  2012-10-22 11:15 ` [PATCH 3/3] iio: Accept a leading '+' sign " Lars-Peter Clausen
@ 2012-11-02  9:46   ` Jonathan Cameron
  0 siblings, 0 replies; 6+ messages in thread
From: Jonathan Cameron @ 2012-11-02  9:46 UTC (permalink / raw)
  To: Lars-Peter Clausen; +Cc: Jonathan Cameron, linux-iio

On 10/22/2012 12:15 PM, Lars-Peter Clausen wrote:
> If we encounter a leading '+' sign just skip over it.
> 
> Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
Can't say I care either way on this, but it's helpful to you why not...

Added to togreg branch of iio.git

> ---
>  drivers/iio/industrialio-core.c |    2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c
> index fe593bf..5f8ff0d 100644
> --- a/drivers/iio/industrialio-core.c
> +++ b/drivers/iio/industrialio-core.c
> @@ -432,6 +432,8 @@ static ssize_t iio_write_channel_info(struct device *dev,
>  	if (buf[0] == '-') {
>  		negative = true;
>  		buf++;
> +	} else if (buf[0] == '+') {
> +		buf++;
>  	}
>  
>  	while (*buf) {
> 

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

end of thread, other threads:[~2012-11-02  9:46 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-10-22 11:15 [PATCH 1/3] iio: Do not accept multiple '.' in fixed point numbers Lars-Peter Clausen
2012-10-22 11:15 ` [PATCH 2/3] iio: Reject trailing garbage when parsing " Lars-Peter Clausen
2012-11-02  9:45   ` Jonathan Cameron
2012-10-22 11:15 ` [PATCH 3/3] iio: Accept a leading '+' sign " Lars-Peter Clausen
2012-11-02  9:46   ` Jonathan Cameron
2012-11-02  9:44 ` [PATCH 1/3] iio: Do not accept multiple '.' in " Jonathan Cameron

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.