* [PATCH] iio: ltr501: Use a signed return type for ltr501_match_samp_freq
@ 2016-01-26 12:06 Lucas Tanure
2016-01-26 12:10 ` Peter Meerwald-Stadler
0 siblings, 1 reply; 4+ messages in thread
From: Lucas Tanure @ 2016-01-26 12:06 UTC (permalink / raw)
To: Jonathan Cameron, Hartmut Knaack
Cc: linux-kernel, Lars-Peter Clausen, linux-iio, Peter Meerwald
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.
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);
--
2.7.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] iio: ltr501: Use a signed return type for ltr501_match_samp_freq
2016-01-26 12:06 [PATCH] iio: ltr501: Use a signed return type for ltr501_match_samp_freq Lucas Tanure
@ 2016-01-26 12:10 ` Peter Meerwald-Stadler
2016-01-26 12:12 ` Lucas Tanure
0 siblings, 1 reply; 4+ messages in thread
From: Peter Meerwald-Stadler @ 2016-01-26 12:10 UTC (permalink / raw)
To: Lucas Tanure
Cc: Jonathan Cameron, Hartmut Knaack, linux-kernel,
Lars-Peter Clausen, linux-iio
> 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)
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] iio: ltr501: Use a signed return type for ltr501_match_samp_freq
2016-01-26 12:10 ` Peter Meerwald-Stadler
@ 2016-01-26 12:12 ` Lucas Tanure
2016-01-30 16:06 ` Jonathan Cameron
0 siblings, 1 reply; 4+ messages in thread
From: Lucas Tanure @ 2016-01-26 12:12 UTC (permalink / raw)
To: Peter Meerwald-Stadler
Cc: Jonathan Cameron, Hartmut Knaack, linux-kernel,
Lars-Peter Clausen, linux-iio
Hi,
On Tue, Jan 26, 2016 at 10:10 AM, Peter Meerwald-Stadler
<pmeerw@pmeerw.net> wrote:
>
>> 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?
Yeah, you explained better. =p
Do you need me to resend ?
Thanks!
>
>> 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)
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] iio: ltr501: Use a signed return type for ltr501_match_samp_freq
2016-01-26 12:12 ` Lucas Tanure
@ 2016-01-30 16:06 ` Jonathan Cameron
0 siblings, 0 replies; 4+ messages in thread
From: Jonathan Cameron @ 2016-01-30 16:06 UTC (permalink / raw)
To: Lucas Tanure, Peter Meerwald-Stadler
Cc: Hartmut Knaack, linux-kernel, Lars-Peter Clausen, linux-iio
On 26/01/16 12:12, Lucas Tanure wrote:
> Hi,
>
> On Tue, Jan 26, 2016 at 10:10 AM, Peter Meerwald-Stadler
> <pmeerw@pmeerw.net> wrote:
>>
>>> 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?
> Yeah, you explained better. =p
> Do you need me to resend ?
>
Nope, I just dropped the controversial line as it was clear in the patch title.
Applied to the fixes-togreg-post4.5rc1 branch.
Thanks,
Jonathan
> Thanks!
>
>>
>>> 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)
> --
> To unsubscribe from this list: send the line "unsubscribe linux-iio" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
>
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2016-01-30 16:06 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-01-26 12:06 [PATCH] iio: ltr501: Use a signed return type for ltr501_match_samp_freq Lucas Tanure
2016-01-26 12:10 ` Peter Meerwald-Stadler
2016-01-26 12:12 ` Lucas Tanure
2016-01-30 16:06 ` 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.