linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] i2c: taos-evm: replace simple_strtoul by kstrtou8
@ 2015-11-05  9:32 LABBE Corentin
  2015-11-05 17:24 ` Jean Delvare
  0 siblings, 1 reply; 5+ messages in thread
From: LABBE Corentin @ 2015-11-05  9:32 UTC (permalink / raw)
  To: jdelvare, wsa; +Cc: LABBE Corentin, linux-i2c, linux-kernel

The simple_strtoul function is marked as obsolete.
This patch replace it by kstrtou8.

Signed-off-by: LABBE Corentin <clabbe.montjoie@gmail.com>
---
 drivers/i2c/busses/i2c-taos-evm.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/i2c/busses/i2c-taos-evm.c b/drivers/i2c/busses/i2c-taos-evm.c
index 4c7fc2d..9dc6cff 100644
--- a/drivers/i2c/busses/i2c-taos-evm.c
+++ b/drivers/i2c/busses/i2c-taos-evm.c
@@ -70,6 +70,7 @@ static int taos_smbus_xfer(struct i2c_adapter *adapter, u16 addr,
 	struct serio *serio = adapter->algo_data;
 	struct taos_data *taos = serio_get_drvdata(serio);
 	char *p;
+	int err;
 
 	/* Encode our transaction. "@" is for the device address, "$" for the
 	   SMBus command and "#" for the data. */
@@ -130,7 +131,9 @@ static int taos_smbus_xfer(struct i2c_adapter *adapter, u16 addr,
 			return 0;
 	} else {
 		if (p[0] == 'x') {
-			data->byte = simple_strtol(p + 1, NULL, 16);
+			err = kstrtou8(p + 1, 16, &data->byte);
+			if (err)
+				return err;
 			return 0;
 		}
 	}
-- 
2.4.10


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

* Re: [PATCH] i2c: taos-evm: replace simple_strtoul by kstrtou8
  2015-11-05  9:32 [PATCH] i2c: taos-evm: replace simple_strtoul by kstrtou8 LABBE Corentin
@ 2015-11-05 17:24 ` Jean Delvare
  0 siblings, 0 replies; 5+ messages in thread
From: Jean Delvare @ 2015-11-05 17:24 UTC (permalink / raw)
  To: LABBE Corentin; +Cc: wsa, linux-i2c, linux-kernel

Hi Corentin,

On Thu,  5 Nov 2015 10:32:48 +0100, LABBE Corentin wrote:
> The simple_strtoul function is marked as obsolete.
> This patch replace it by kstrtou8.
> 
> Signed-off-by: LABBE Corentin <clabbe.montjoie@gmail.com>
> ---
>  drivers/i2c/busses/i2c-taos-evm.c | 5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)

Thanks for the cleanup. I tested it on the hardware I have, no problem.
One comment below.

> 
> diff --git a/drivers/i2c/busses/i2c-taos-evm.c b/drivers/i2c/busses/i2c-taos-evm.c
> index 4c7fc2d..9dc6cff 100644
> --- a/drivers/i2c/busses/i2c-taos-evm.c
> +++ b/drivers/i2c/busses/i2c-taos-evm.c
> @@ -70,6 +70,7 @@ static int taos_smbus_xfer(struct i2c_adapter *adapter, u16 addr,
>  	struct serio *serio = adapter->algo_data;
>  	struct taos_data *taos = serio_get_drvdata(serio);
>  	char *p;
> +	int err;
>  
>  	/* Encode our transaction. "@" is for the device address, "$" for the
>  	   SMBus command and "#" for the data. */
> @@ -130,7 +131,9 @@ static int taos_smbus_xfer(struct i2c_adapter *adapter, u16 addr,
>  			return 0;
>  	} else {
>  		if (p[0] == 'x') {
> -			data->byte = simple_strtol(p + 1, NULL, 16);
> +			err = kstrtou8(p + 1, 16, &data->byte);
> +			if (err)
> +				return err;

While in general I am in favor of passing error values down the stack,
here I'm not sure. kstrtou8 could return -ERANGE or -EINVAL which makes
no sense as an i2c adapter fault code. According to
Documentation/i2c/fault-codes, -EPROTO or -EIO would be more
appropriate.

>  			return 0;
>  		}
>  	}


-- 
Jean Delvare
SUSE L3 Support

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

* Re: [PATCH] i2c: taos-evm: replace simple_strtoul by kstrtou8
  2015-11-12  7:46 ` Uwe Kleine-König
@ 2015-11-12  7:54   ` LABBE Corentin
  0 siblings, 0 replies; 5+ messages in thread
From: LABBE Corentin @ 2015-11-12  7:54 UTC (permalink / raw)
  To: Uwe Kleine-König
  Cc: LABBE Corentin, jdelvare, wsa, linux-i2c, linux-kernel

On Thu, Nov 12, 2015 at 08:46:43AM +0100, Uwe Kleine-König wrote:
> On Thu, Nov 12, 2015 at 08:26:33AM +0100, LABBE Corentin wrote:
> > The simple_strtoul function is marked as obsolete.
> > This patch replace it by kstrtou8.
> > 
> > Signed-off-by: LABBE Corentin <clabbe.montjoie@gmail.com>
> > ---
> >  drivers/i2c/busses/i2c-taos-evm.c | 5 ++++-
> >  1 file changed, 4 insertions(+), 1 deletion(-)
> > 
> > diff --git a/drivers/i2c/busses/i2c-taos-evm.c b/drivers/i2c/busses/i2c-taos-evm.c
> > index 4c7fc2d..fe2b705 100644
> > --- a/drivers/i2c/busses/i2c-taos-evm.c
> > +++ b/drivers/i2c/busses/i2c-taos-evm.c
> > @@ -70,6 +70,7 @@ static int taos_smbus_xfer(struct i2c_adapter *adapter, u16 addr,
> >  	struct serio *serio = adapter->algo_data;
> >  	struct taos_data *taos = serio_get_drvdata(serio);
> >  	char *p;
> > +	int err;
> >  
> >  	/* Encode our transaction. "@" is for the device address, "$" for the
> >  	   SMBus command and "#" for the data. */
> > @@ -130,7 +131,9 @@ static int taos_smbus_xfer(struct i2c_adapter *adapter, u16 addr,
> >  			return 0;
> >  	} else {
> >  		if (p[0] == 'x') {
> > -			data->byte = simple_strtol(p + 1, NULL, 16);
> > +			err = kstrtou8(p + 1, 16, &data->byte);
> > +			if (err)
> > +				return -EPROTO;
> >  			return 0;
> 
> This is nearly equivalent to the probably more correct:
> 
> 	return kstrtou8(p + 1, 16, &data->byte);
> 

As reported, by Jean Delvare, kstrtou8 could return -EINVAL.
It is why I "drop" the return code from kstrtou8 and return -EPROTO as suggested by Jean.

I have hesitate to put a comment for this, and it seems finaly necessary.

Regards


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

* Re: [PATCH] i2c: taos-evm: replace simple_strtoul by kstrtou8
  2015-11-12  7:26 LABBE Corentin
@ 2015-11-12  7:46 ` Uwe Kleine-König
  2015-11-12  7:54   ` LABBE Corentin
  0 siblings, 1 reply; 5+ messages in thread
From: Uwe Kleine-König @ 2015-11-12  7:46 UTC (permalink / raw)
  To: LABBE Corentin; +Cc: jdelvare, wsa, linux-i2c, linux-kernel

On Thu, Nov 12, 2015 at 08:26:33AM +0100, LABBE Corentin wrote:
> The simple_strtoul function is marked as obsolete.
> This patch replace it by kstrtou8.
> 
> Signed-off-by: LABBE Corentin <clabbe.montjoie@gmail.com>
> ---
>  drivers/i2c/busses/i2c-taos-evm.c | 5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/i2c/busses/i2c-taos-evm.c b/drivers/i2c/busses/i2c-taos-evm.c
> index 4c7fc2d..fe2b705 100644
> --- a/drivers/i2c/busses/i2c-taos-evm.c
> +++ b/drivers/i2c/busses/i2c-taos-evm.c
> @@ -70,6 +70,7 @@ static int taos_smbus_xfer(struct i2c_adapter *adapter, u16 addr,
>  	struct serio *serio = adapter->algo_data;
>  	struct taos_data *taos = serio_get_drvdata(serio);
>  	char *p;
> +	int err;
>  
>  	/* Encode our transaction. "@" is for the device address, "$" for the
>  	   SMBus command and "#" for the data. */
> @@ -130,7 +131,9 @@ static int taos_smbus_xfer(struct i2c_adapter *adapter, u16 addr,
>  			return 0;
>  	} else {
>  		if (p[0] == 'x') {
> -			data->byte = simple_strtol(p + 1, NULL, 16);
> +			err = kstrtou8(p + 1, 16, &data->byte);
> +			if (err)
> +				return -EPROTO;
>  			return 0;

This is nearly equivalent to the probably more correct:

	return kstrtou8(p + 1, 16, &data->byte);

Best regards
Uwe

-- 
Pengutronix e.K.                           | Uwe Kleine-König            |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |

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

* [PATCH] i2c: taos-evm: replace simple_strtoul by kstrtou8
@ 2015-11-12  7:26 LABBE Corentin
  2015-11-12  7:46 ` Uwe Kleine-König
  0 siblings, 1 reply; 5+ messages in thread
From: LABBE Corentin @ 2015-11-12  7:26 UTC (permalink / raw)
  To: jdelvare, wsa; +Cc: LABBE Corentin, linux-i2c, linux-kernel

The simple_strtoul function is marked as obsolete.
This patch replace it by kstrtou8.

Signed-off-by: LABBE Corentin <clabbe.montjoie@gmail.com>
---
 drivers/i2c/busses/i2c-taos-evm.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/i2c/busses/i2c-taos-evm.c b/drivers/i2c/busses/i2c-taos-evm.c
index 4c7fc2d..fe2b705 100644
--- a/drivers/i2c/busses/i2c-taos-evm.c
+++ b/drivers/i2c/busses/i2c-taos-evm.c
@@ -70,6 +70,7 @@ static int taos_smbus_xfer(struct i2c_adapter *adapter, u16 addr,
 	struct serio *serio = adapter->algo_data;
 	struct taos_data *taos = serio_get_drvdata(serio);
 	char *p;
+	int err;
 
 	/* Encode our transaction. "@" is for the device address, "$" for the
 	   SMBus command and "#" for the data. */
@@ -130,7 +131,9 @@ static int taos_smbus_xfer(struct i2c_adapter *adapter, u16 addr,
 			return 0;
 	} else {
 		if (p[0] == 'x') {
-			data->byte = simple_strtol(p + 1, NULL, 16);
+			err = kstrtou8(p + 1, 16, &data->byte);
+			if (err)
+				return -EPROTO;
 			return 0;
 		}
 	}
-- 
2.4.10


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

end of thread, other threads:[~2015-11-12  7:54 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-11-05  9:32 [PATCH] i2c: taos-evm: replace simple_strtoul by kstrtou8 LABBE Corentin
2015-11-05 17:24 ` Jean Delvare
2015-11-12  7:26 LABBE Corentin
2015-11-12  7:46 ` Uwe Kleine-König
2015-11-12  7:54   ` LABBE Corentin

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