All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] iio/pressure/hp206c: Use common error handling code in hp206c_conv_and_read()
@ 2017-10-26 13:45 ` SF Markus Elfring
  0 siblings, 0 replies; 8+ messages in thread
From: SF Markus Elfring @ 2017-10-26 13:45 UTC (permalink / raw)
  To: linux-iio, Crestez Dan Leonard, Hartmut Knaack, Jonathan Cameron,
	Lars-Peter Clausen, Peter Meerwald-Stadler
  Cc: LKML, kernel-janitors

From: Markus Elfring <elfring@users.sourceforge.net>
Date: Thu, 26 Oct 2017 15:34:46 +0200

Add a jump target so that a specific error message is stored only once
at the end of this function implementation.
Replace two calls of the function "dev_err" by goto statements.

This issue was detected by using the Coccinelle software.

Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
 drivers/iio/pressure/hp206c.c | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/drivers/iio/pressure/hp206c.c b/drivers/iio/pressure/hp206c.c
index c38c19678cf6..978338f2a6e5 100644
--- a/drivers/iio/pressure/hp206c.c
+++ b/drivers/iio/pressure/hp206c.c
@@ -176,10 +176,8 @@ static int hp206c_conv_and_read(struct iio_dev *indio_dev,
 	struct i2c_client *client = data->client;
 
 	ret = hp206c_wait_dev_rdy(indio_dev);
-	if (ret < 0) {
-		dev_err(&indio_dev->dev, "Device not ready: %d\n", ret);
-		return ret;
-	}
+	if (ret < 0)
+		goto report_failure;
 
 	ret = i2c_smbus_write_byte(client, conv_cmd);
 	if (ret < 0) {
@@ -190,16 +188,18 @@ static int hp206c_conv_and_read(struct iio_dev *indio_dev,
 	usleep_range(sleep_us, sleep_us * 3 / 2);
 
 	ret = hp206c_wait_dev_rdy(indio_dev);
-	if (ret < 0) {
-		dev_err(&indio_dev->dev, "Device not ready: %d\n", ret);
-		return ret;
-	}
+	if (ret < 0)
+		goto report_failure;
 
 	ret = hp206c_read_20bit(client, read_cmd);
 	if (ret < 0)
 		dev_err(&indio_dev->dev, "Failed read: %d\n", ret);
 
 	return ret;
+
+report_failure:
+	dev_err(&indio_dev->dev, "Device not ready: %d\n", ret);
+	return ret;
 }
 
 static int hp206c_read_raw(struct iio_dev *indio_dev,
-- 
2.14.3

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

* [PATCH] iio/pressure/hp206c: Use common error handling code in hp206c_conv_and_read()
@ 2017-10-26 13:45 ` SF Markus Elfring
  0 siblings, 0 replies; 8+ messages in thread
From: SF Markus Elfring @ 2017-10-26 13:45 UTC (permalink / raw)
  To: linux-iio, Crestez Dan Leonard, Hartmut Knaack, Jonathan Cameron,
	Lars-Peter Clausen, Peter Meerwald-Stadler
  Cc: LKML, kernel-janitors

From: Markus Elfring <elfring@users.sourceforge.net>
Date: Thu, 26 Oct 2017 15:34:46 +0200

Add a jump target so that a specific error message is stored only once
at the end of this function implementation.
Replace two calls of the function "dev_err" by goto statements.

This issue was detected by using the Coccinelle software.

Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
 drivers/iio/pressure/hp206c.c | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/drivers/iio/pressure/hp206c.c b/drivers/iio/pressure/hp206c.c
index c38c19678cf6..978338f2a6e5 100644
--- a/drivers/iio/pressure/hp206c.c
+++ b/drivers/iio/pressure/hp206c.c
@@ -176,10 +176,8 @@ static int hp206c_conv_and_read(struct iio_dev *indio_dev,
 	struct i2c_client *client = data->client;
 
 	ret = hp206c_wait_dev_rdy(indio_dev);
-	if (ret < 0) {
-		dev_err(&indio_dev->dev, "Device not ready: %d\n", ret);
-		return ret;
-	}
+	if (ret < 0)
+		goto report_failure;
 
 	ret = i2c_smbus_write_byte(client, conv_cmd);
 	if (ret < 0) {
@@ -190,16 +188,18 @@ static int hp206c_conv_and_read(struct iio_dev *indio_dev,
 	usleep_range(sleep_us, sleep_us * 3 / 2);
 
 	ret = hp206c_wait_dev_rdy(indio_dev);
-	if (ret < 0) {
-		dev_err(&indio_dev->dev, "Device not ready: %d\n", ret);
-		return ret;
-	}
+	if (ret < 0)
+		goto report_failure;
 
 	ret = hp206c_read_20bit(client, read_cmd);
 	if (ret < 0)
 		dev_err(&indio_dev->dev, "Failed read: %d\n", ret);
 
 	return ret;
+
+report_failure:
+	dev_err(&indio_dev->dev, "Device not ready: %d\n", ret);
+	return ret;
 }
 
 static int hp206c_read_raw(struct iio_dev *indio_dev,
-- 
2.14.3


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

* Re: [PATCH] iio/pressure/hp206c: Use common error handling code in hp206c_conv_and_read()
  2017-10-26 13:45 ` SF Markus Elfring
@ 2017-10-26 16:23   ` Jonathan Cameron
  -1 siblings, 0 replies; 8+ messages in thread
From: Jonathan Cameron @ 2017-10-26 16:23 UTC (permalink / raw)
  To: SF Markus Elfring
  Cc: linux-iio, Crestez Dan Leonard, Hartmut Knaack,
	Lars-Peter Clausen, Peter Meerwald-Stadler, LKML,
	kernel-janitors

On Thu, 26 Oct 2017 15:45:43 +0200
SF Markus Elfring <elfring@users.sourceforge.net> wrote:

> From: Markus Elfring <elfring@users.sourceforge.net>
> Date: Thu, 26 Oct 2017 15:34:46 +0200
> 
> Add a jump target so that a specific error message is stored only once
> at the end of this function implementation.
> Replace two calls of the function "dev_err" by goto statements.
> 
> This issue was detected by using the Coccinelle software.
> 
> Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>

The advantages of this are very limited. Hence I am not going to
apply it.

There would be some argument (perhaps) for moving the error message
into the function being called but that would then make the driver
inconsistent on where it reports errors reducing overall readability.

Jonathan

> ---
>  drivers/iio/pressure/hp206c.c | 16 ++++++++--------
>  1 file changed, 8 insertions(+), 8 deletions(-)
> 
> diff --git a/drivers/iio/pressure/hp206c.c b/drivers/iio/pressure/hp206c.c
> index c38c19678cf6..978338f2a6e5 100644
> --- a/drivers/iio/pressure/hp206c.c
> +++ b/drivers/iio/pressure/hp206c.c
> @@ -176,10 +176,8 @@ static int hp206c_conv_and_read(struct iio_dev *indio_dev,
>  	struct i2c_client *client = data->client;
>  
>  	ret = hp206c_wait_dev_rdy(indio_dev);
> -	if (ret < 0) {
> -		dev_err(&indio_dev->dev, "Device not ready: %d\n", ret);
> -		return ret;
> -	}
> +	if (ret < 0)
> +		goto report_failure;
>  
>  	ret = i2c_smbus_write_byte(client, conv_cmd);
>  	if (ret < 0) {
> @@ -190,16 +188,18 @@ static int hp206c_conv_and_read(struct iio_dev *indio_dev,
>  	usleep_range(sleep_us, sleep_us * 3 / 2);
>  
>  	ret = hp206c_wait_dev_rdy(indio_dev);
> -	if (ret < 0) {
> -		dev_err(&indio_dev->dev, "Device not ready: %d\n", ret);
> -		return ret;
> -	}
> +	if (ret < 0)
> +		goto report_failure;
>  
>  	ret = hp206c_read_20bit(client, read_cmd);
>  	if (ret < 0)
>  		dev_err(&indio_dev->dev, "Failed read: %d\n", ret);
>  
>  	return ret;
> +
> +report_failure:
> +	dev_err(&indio_dev->dev, "Device not ready: %d\n", ret);
> +	return ret;
>  }
>  
>  static int hp206c_read_raw(struct iio_dev *indio_dev,

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

* Re: [PATCH] iio/pressure/hp206c: Use common error handling code in hp206c_conv_and_read()
@ 2017-10-26 16:23   ` Jonathan Cameron
  0 siblings, 0 replies; 8+ messages in thread
From: Jonathan Cameron @ 2017-10-26 16:23 UTC (permalink / raw)
  To: SF Markus Elfring
  Cc: linux-iio, Crestez Dan Leonard, Hartmut Knaack,
	Lars-Peter Clausen, Peter Meerwald-Stadler, LKML,
	kernel-janitors

On Thu, 26 Oct 2017 15:45:43 +0200
SF Markus Elfring <elfring@users.sourceforge.net> wrote:

> From: Markus Elfring <elfring@users.sourceforge.net>
> Date: Thu, 26 Oct 2017 15:34:46 +0200
> 
> Add a jump target so that a specific error message is stored only once
> at the end of this function implementation.
> Replace two calls of the function "dev_err" by goto statements.
> 
> This issue was detected by using the Coccinelle software.
> 
> Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>

The advantages of this are very limited. Hence I am not going to
apply it.

There would be some argument (perhaps) for moving the error message
into the function being called but that would then make the driver
inconsistent on where it reports errors reducing overall readability.

Jonathan

> ---
>  drivers/iio/pressure/hp206c.c | 16 ++++++++--------
>  1 file changed, 8 insertions(+), 8 deletions(-)
> 
> diff --git a/drivers/iio/pressure/hp206c.c b/drivers/iio/pressure/hp206c.c
> index c38c19678cf6..978338f2a6e5 100644
> --- a/drivers/iio/pressure/hp206c.c
> +++ b/drivers/iio/pressure/hp206c.c
> @@ -176,10 +176,8 @@ static int hp206c_conv_and_read(struct iio_dev *indio_dev,
>  	struct i2c_client *client = data->client;
>  
>  	ret = hp206c_wait_dev_rdy(indio_dev);
> -	if (ret < 0) {
> -		dev_err(&indio_dev->dev, "Device not ready: %d\n", ret);
> -		return ret;
> -	}
> +	if (ret < 0)
> +		goto report_failure;
>  
>  	ret = i2c_smbus_write_byte(client, conv_cmd);
>  	if (ret < 0) {
> @@ -190,16 +188,18 @@ static int hp206c_conv_and_read(struct iio_dev *indio_dev,
>  	usleep_range(sleep_us, sleep_us * 3 / 2);
>  
>  	ret = hp206c_wait_dev_rdy(indio_dev);
> -	if (ret < 0) {
> -		dev_err(&indio_dev->dev, "Device not ready: %d\n", ret);
> -		return ret;
> -	}
> +	if (ret < 0)
> +		goto report_failure;
>  
>  	ret = hp206c_read_20bit(client, read_cmd);
>  	if (ret < 0)
>  		dev_err(&indio_dev->dev, "Failed read: %d\n", ret);
>  
>  	return ret;
> +
> +report_failure:
> +	dev_err(&indio_dev->dev, "Device not ready: %d\n", ret);
> +	return ret;
>  }
>  
>  static int hp206c_read_raw(struct iio_dev *indio_dev,


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

* Re: iio/pressure/hp206c: Use common error handling code in hp206c_conv_and_read()
  2017-10-26 16:23   ` Jonathan Cameron
@ 2017-10-26 16:38     ` SF Markus Elfring
  -1 siblings, 0 replies; 8+ messages in thread
From: SF Markus Elfring @ 2017-10-26 16:38 UTC (permalink / raw)
  To: Jonathan Cameron, linux-iio
  Cc: Crestez Dan Leonard, Hartmut Knaack, Lars-Peter Clausen,
	Peter Meerwald-Stadler, LKML, kernel-janitors

> The advantages of this are very limited.

Would anybody like to check corresponding effects in more detail?


> Hence I am not going to apply it.

This is a pity that you like such a kind of source code adjustment
not so much so far.

Regards,
Markus

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

* Re: iio/pressure/hp206c: Use common error handling code in hp206c_conv_and_read()
@ 2017-10-26 16:38     ` SF Markus Elfring
  0 siblings, 0 replies; 8+ messages in thread
From: SF Markus Elfring @ 2017-10-26 16:38 UTC (permalink / raw)
  To: Jonathan Cameron, linux-iio
  Cc: Crestez Dan Leonard, Hartmut Knaack, Lars-Peter Clausen,
	Peter Meerwald-Stadler, LKML, kernel-janitors

> The advantages of this are very limited.

Would anybody like to check corresponding effects in more detail?


> Hence I am not going to apply it.

This is a pity that you like such a kind of source code adjustment
not so much so far.

Regards,
Markus

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

* Re: iio/pressure/hp206c: Use common error handling code in hp206c_conv_and_read()
  2017-10-26 16:38     ` SF Markus Elfring
@ 2017-10-26 16:44       ` Jonathan Cameron
  -1 siblings, 0 replies; 8+ messages in thread
From: Jonathan Cameron @ 2017-10-26 16:44 UTC (permalink / raw)
  To: SF Markus Elfring
  Cc: linux-iio, Crestez Dan Leonard, Hartmut Knaack,
	Lars-Peter Clausen, Peter Meerwald-Stadler, LKML,
	kernel-janitors

On Thu, 26 Oct 2017 18:38:14 +0200
SF Markus Elfring <elfring@users.sourceforge.net> wrote:

> > The advantages of this are very limited.  
> 
> Would anybody like to check corresponding effects in more detail?
No readabilty is reduced.  It is a very rare patch that is accepted
where that is the case and the reasons have to be extremely clear
and justified.
> 
> 
> > Hence I am not going to apply it.  
> 
> This is a pity that you like such a kind of source code adjustment
> not so much so far.
> 

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

* Re: iio/pressure/hp206c: Use common error handling code in hp206c_conv_and_read()
@ 2017-10-26 16:44       ` Jonathan Cameron
  0 siblings, 0 replies; 8+ messages in thread
From: Jonathan Cameron @ 2017-10-26 16:44 UTC (permalink / raw)
  To: SF Markus Elfring
  Cc: linux-iio, Crestez Dan Leonard, Hartmut Knaack,
	Lars-Peter Clausen, Peter Meerwald-Stadler, LKML,
	kernel-janitors

On Thu, 26 Oct 2017 18:38:14 +0200
SF Markus Elfring <elfring@users.sourceforge.net> wrote:

> > The advantages of this are very limited.  
> 
> Would anybody like to check corresponding effects in more detail?
No readabilty is reduced.  It is a very rare patch that is accepted
where that is the case and the reasons have to be extremely clear
and justified.
> 
> 
> > Hence I am not going to apply it.  
> 
> This is a pity that you like such a kind of source code adjustment
> not so much so far.
> 



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

end of thread, other threads:[~2017-10-26 16:44 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-10-26 13:45 [PATCH] iio/pressure/hp206c: Use common error handling code in hp206c_conv_and_read() SF Markus Elfring
2017-10-26 13:45 ` SF Markus Elfring
2017-10-26 16:23 ` Jonathan Cameron
2017-10-26 16:23   ` Jonathan Cameron
2017-10-26 16:38   ` SF Markus Elfring
2017-10-26 16:38     ` SF Markus Elfring
2017-10-26 16:44     ` Jonathan Cameron
2017-10-26 16:44       ` 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.