mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Peter Meerwald-Stadler <pmeerw@pmeerw.net>
To: Lucas Tanure <tanure@linux.com>
Cc: Jonathan Cameron <jic23@kernel.org>,
	Hartmut Knaack <knaack.h@gmx.de>,
	linux-kernel@vger.kernel.org,
	Lars-Peter Clausen <lars@metafoo.de>,
	linux-iio@vger.kernel.org
Subject: Re: [PATCH] iio: ltr501: Use a signed return type for ltr501_match_samp_freq
Date: Tue, 26 Jan 2016 13:10:34 +0100 (CET)	[thread overview]
Message-ID: <alpine.DEB.2.02.1601261309440.22166@pmeerw.net> (raw)
In-Reply-To: <1453809982-3548-1-git-send-email-tanure@linux.com>


> The return type "unsigned int" was used by the ltr501_match_samp_freq function
> despite of the aspect that it will eventually return a negative error code.
> So, change to signed int and get the value by reference in the parameters.

ok, or just change the return type to int w/o adding a new pointer 
argument?
 
> Done with the help of Coccinelle.
> 
> Signed-off-by: Lucas Tanure <tanure@linux.com>
> ---
>  drivers/iio/light/ltr501.c | 27 +++++++++++++++------------
>  1 file changed, 15 insertions(+), 12 deletions(-)
> 
> diff --git a/drivers/iio/light/ltr501.c b/drivers/iio/light/ltr501.c
> index 809a961..99e8b12 100644
> --- a/drivers/iio/light/ltr501.c
> +++ b/drivers/iio/light/ltr501.c
> @@ -180,16 +180,19 @@ static const struct ltr501_samp_table ltr501_ps_samp_table[] = {
>  			{500000, 2000000}
>  };
>  
> -static unsigned int ltr501_match_samp_freq(const struct ltr501_samp_table *tab,
> -					   int len, int val, int val2)
> +static int ltr501_match_samp_freq(const struct ltr501_samp_table *tab,
> +					   int len, int val, int val2,
> +					   int *ret)
>  {
>  	int i, freq;
>  
>  	freq = val * 1000000 + val2;
>  
>  	for (i = 0; i < len; i++) {
> -		if (tab[i].freq_val == freq)
> -			return i;
> +		if (tab[i].freq_val == freq) {
> +			*ret = i;
> +			return 0;
> +		}
>  	}
>  
>  	return -EINVAL;
> @@ -236,12 +239,12 @@ static int ltr501_als_write_samp_freq(struct ltr501_data *data,
>  {
>  	int i, ret;
>  
> -	i = ltr501_match_samp_freq(ltr501_als_samp_table,
> +	ret = ltr501_match_samp_freq(ltr501_als_samp_table,
>  				   ARRAY_SIZE(ltr501_als_samp_table),
> -				   val, val2);
> +				   val, val2, &i);
>  
> -	if (i < 0)
> -		return i;
> +	if (ret < 0)
> +		return ret;
>  
>  	mutex_lock(&data->lock_als);
>  	ret = regmap_field_write(data->reg_als_rate, i);
> @@ -255,12 +258,12 @@ static int ltr501_ps_write_samp_freq(struct ltr501_data *data,
>  {
>  	int i, ret;
>  
> -	i = ltr501_match_samp_freq(ltr501_ps_samp_table,
> +	ret = ltr501_match_samp_freq(ltr501_ps_samp_table,
>  				   ARRAY_SIZE(ltr501_ps_samp_table),
> -				   val, val2);
> +				   val, val2, &i);
>  
> -	if (i < 0)
> -		return i;
> +	if (ret < 0)
> +		return ret;
>  
>  	mutex_lock(&data->lock_ps);
>  	ret = regmap_field_write(data->reg_ps_rate, i);
> 

-- 

Peter Meerwald-Stadler
+43-664-2444418 (mobile)

  reply	other threads:[~2016-01-26 12:10 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-01-26 12:06 Lucas Tanure
2016-01-26 12:10 ` Peter Meerwald-Stadler [this message]
2016-01-26 12:12   ` Lucas Tanure
2016-01-30 16:06     ` Jonathan Cameron

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=alpine.DEB.2.02.1601261309440.22166@pmeerw.net \
    --to=pmeerw@pmeerw.net \
    --cc=jic23@kernel.org \
    --cc=knaack.h@gmx.de \
    --cc=lars@metafoo.de \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=tanure@linux.com \
    /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

all inboxes | Powered by JetHome®