linux-iio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jonathan Cameron <jic23@kernel.org>
To: SF Markus Elfring <elfring@users.sourceforge.net>,
	linux-iio@vger.kernel.org, Hartmut Knaack <knaack.h@gmx.de>,
	Lars-Peter Clausen <lars@metafoo.de>,
	Peter Meerwald <pmeerw@pmeerw.net>
Cc: LKML <linux-kernel@vger.kernel.org>,
	kernel-janitors@vger.kernel.org,
	Julia Lawall <julia.lawall@lip6.fr>
Subject: Re: [PATCH] iio: qcom-spmi-vadc: One check less in vadc_measure_ref_points() after error detection
Date: Sat, 2 Jan 2016 18:28:04 +0000	[thread overview]
Message-ID: <568816B4.2090003@kernel.org> (raw)
In-Reply-To: <567E9059.30709@users.sourceforge.net>

On 26/12/15 13:04, SF Markus Elfring wrote:
> From: Markus Elfring <elfring@users.sourceforge.net>
> Date: Sat, 26 Dec 2015 13:53:15 +0100
> 
> This issue was detected by using the Coccinelle software.
> 
> Move the jump label directly before the desired log statement
> so that the variable "ret" does not need to be checked once more
> after it was determined that a function call failed.
> 
> Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
If we are going to change this, I would prefer to see more useful
local error messages and direct returns rather than jumping to
a very generic message at the end.

I'm also less than keen on jumping into conditionals as I find
it slightly less readable. 

We might technically be 'simplifying' the code, but in this case
the gain is very minor for a fair bit of code churn...

Thanks,

Jonathan
> ---
>  drivers/iio/adc/qcom-spmi-vadc.c | 17 +++++++++--------
>  1 file changed, 9 insertions(+), 8 deletions(-)
> 
> diff --git a/drivers/iio/adc/qcom-spmi-vadc.c b/drivers/iio/adc/qcom-spmi-vadc.c
> index c2babe5..391eefa 100644
> --- a/drivers/iio/adc/qcom-spmi-vadc.c
> +++ b/drivers/iio/adc/qcom-spmi-vadc.c
> @@ -424,7 +424,7 @@ static int vadc_measure_ref_points(struct vadc_priv *vadc)
>  	prop = vadc_get_channel(vadc, VADC_REF_1250MV);
>  	ret = vadc_do_conversion(vadc, prop, &read_1);
>  	if (ret)
> -		goto err;
> +		goto report_failure;
In this first case we have already had a report that a conversion failed.
I suppose adding that it was during reference point measurement 'might'
be useful additional information.  I'm not really convinced of it does
however... Hence I'd drop reporting it entirely in this function.
>  
>  	/* Try with buffered 625mV channel first */
>  	prop = vadc_get_channel(vadc, VADC_SPARE1);
> @@ -433,11 +433,11 @@ static int vadc_measure_ref_points(struct vadc_priv *vadc)
>  
>  	ret = vadc_do_conversion(vadc, prop, &read_2);
>  	if (ret)
> -		goto err;
> +		goto report_failure;
>  
>  	if (read_1 == read_2) {
>  		ret = -EINVAL;
I think this one indicates we can't actually read anything at all
for some reason...  It's the only form of error we won't have effectively
already reported so is worthy of some sort of debug message...
> -		goto err;
> +		goto report_failure;
>  	}
>  
>  	vadc->graph[VADC_CALIB_ABSOLUTE].dy = read_1 - read_2;
> @@ -447,23 +447,24 @@ static int vadc_measure_ref_points(struct vadc_priv *vadc)
>  	prop = vadc_get_channel(vadc, VADC_VDD_VADC);
>  	ret = vadc_do_conversion(vadc, prop, &read_1);
>  	if (ret)
> -		goto err;
> +		goto report_failure;
>  
>  	prop = vadc_get_channel(vadc, VADC_GND_REF);
>  	ret = vadc_do_conversion(vadc, prop, &read_2);
>  	if (ret)
> -		goto err;
> +		goto report_failure;
>  
>  	if (read_1 == read_2) {
>  		ret = -EINVAL;
> -		goto err;
> +		goto report_failure;
>  	}
>  
>  	vadc->graph[VADC_CALIB_RATIOMETRIC].dy = read_1 - read_2;
>  	vadc->graph[VADC_CALIB_RATIOMETRIC].gnd = read_2;
> -err:
> -	if (ret)
> +	if (ret) {
> +report_failure:
>  		dev_err(vadc->dev, "measure reference points failed\n");
> +	}
>  
>  	return ret;
>  }
> 


  reply	other threads:[~2016-01-02 18:28 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <566ABCD9.1060404@users.sourceforge.net>
2015-12-26 13:04 ` [PATCH] iio: qcom-spmi-vadc: One check less in vadc_measure_ref_points() after error detection SF Markus Elfring
2016-01-02 18:28   ` Jonathan Cameron [this message]
2016-09-24  6:22 ` [PATCH 0/7] iio: Fine-tuning for several function implementations SF Markus Elfring
2016-09-24  6:24   ` [PATCH 1/7] iio: Use kmalloc_array() in iio_scan_mask_set() SF Markus Elfring
2016-09-24 15:36     ` Jonathan Cameron
2016-09-24 16:18       ` SF Markus Elfring
2016-09-24 16:36         ` Jonathan Cameron
2016-09-24  6:25   ` [PATCH 2/7] iio: Rename a jump label in iio_buffer_store_watermark() SF Markus Elfring
2016-09-24 15:32     ` Jonathan Cameron
2016-09-24 19:21       ` SF Markus Elfring
2016-09-25  8:45         ` Jonathan Cameron
2016-09-25 13:00           ` SF Markus Elfring
2016-09-25 14:23             ` Jonathan Cameron
2016-09-25 15:17               ` SF Markus Elfring
2016-09-25 16:49                 ` Jonathan Cameron
2016-09-25 17:31                   ` SF Markus Elfring
2016-09-24  6:26   ` [PATCH 3/7] iio: Rename a jump label in iio_buffer_store_enable() SF Markus Elfring
2016-09-24  6:28   ` [PATCH 4/7] iio: Rename a jump label in iio_buffer_write_length() SF Markus Elfring
2016-09-24  6:29   ` [PATCH 5/7] iio: Rename a jump label in iio_scan_el_ts_store() SF Markus Elfring
2016-09-24  6:30   ` [PATCH 6/7] iio: Rename a jump label in iio_scan_el_store() SF Markus Elfring
2016-09-24  6:31   ` [PATCH 7/7] iio: Adjust checks for null pointers in six functions SF Markus Elfring
2016-09-25 14:24     ` Jonathan Cameron
2016-09-25 14:44       ` SF Markus Elfring
2016-09-25 16:51         ` Jonathan Cameron
2016-09-25 17:45           ` SF Markus Elfring
2016-09-25 18:15             ` Al Viro
2016-09-25 19:30               ` SF Markus Elfring

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=568816B4.2090003@kernel.org \
    --to=jic23@kernel.org \
    --cc=elfring@users.sourceforge.net \
    --cc=julia.lawall@lip6.fr \
    --cc=kernel-janitors@vger.kernel.org \
    --cc=knaack.h@gmx.de \
    --cc=lars@metafoo.de \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=pmeerw@pmeerw.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).