Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1560170 > unrolled thread

Re: [PATCH] drivers: power: supply: Compress return logic into one line.

Started bySebastian Reichel <sre@kernel.org>
First post2017-01-17 00:50 +0100
Last post2017-01-20 00:30 +0100
Articles 2 — 2 participants

Back to article view | Back to linux.kernel

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: [PATCH] drivers: power: supply: Compress return logic into one  line. Sebastian Reichel <sre@kernel.org> - 2017-01-17 00:50 +0100
    Re: [PATCH] drivers: power: supply: Compress return logic into one  line. "Gustavo A. R. Silva" <garsilva@embeddedor.com> - 2017-01-20 00:30 +0100

#1560170 — Re: [PATCH] drivers: power: supply: Compress return logic into one line.

FromSebastian Reichel <sre@kernel.org>
Date2017-01-17 00:50 +0100
SubjectRe: [PATCH] drivers: power: supply: Compress return logic into one line.
Message-ID<t0pcd-7IE-1@gated-at.bofh.it>

[Multipart message — attachments visible in raw view] — view raw

Hi,

On Wed, Jan 11, 2017 at 08:29:35PM -0600, Gustavo A. R. Silva wrote:
> Simplify return logic to avoid unnecessary variable assignments.
> These issues were detected using Coccinelle and the following semantic patch:
> 
> @@
> local idexpression ret;
> expression e;
> @@
> 
> -ret =
> +return
>      e;
> -return ret;
> 
> Signed-off-by: Gustavo A. R. Silva <garsilva@embeddedor.com>
> ---
>  drivers/power/supply/ab8500_btemp.c | 10 +++-------
>  1 file changed, 3 insertions(+), 7 deletions(-)
> 
> diff --git a/drivers/power/supply/ab8500_btemp.c b/drivers/power/supply/ab8500_btemp.c
> index 6ffdc18..9b01b52 100644
> --- a/drivers/power/supply/ab8500_btemp.c
> +++ b/drivers/power/supply/ab8500_btemp.c
> @@ -123,10 +123,7 @@ static LIST_HEAD(ab8500_btemp_list);
>   */
>  struct ab8500_btemp *ab8500_btemp_get(void)
>  {
> -	struct ab8500_btemp *btemp;
> -	btemp = list_first_entry(&ab8500_btemp_list, struct ab8500_btemp, node);
> -
> -	return btemp;
> +	return list_first_entry(&ab8500_btemp_list, struct ab8500_btemp, node);
>  }
>  EXPORT_SYMBOL(ab8500_btemp_get);
>  
> @@ -470,7 +467,7 @@ static int ab8500_btemp_get_batctrl_res(struct ab8500_btemp *di)
>  static int ab8500_btemp_res_to_temp(struct ab8500_btemp *di,
>  	const struct abx500_res_to_temp *tbl, int tbl_size, int res)
>  {
> -	int i, temp;
> +	int i;
>  	/*
>  	 * Calculate the formula for the straight line
>  	 * Simple interpolation if we are within
> @@ -488,9 +485,8 @@ static int ab8500_btemp_res_to_temp(struct ab8500_btemp *di,
>  			i++;
>  	}
>  
> -	temp = tbl[i].temp + ((tbl[i + 1].temp - tbl[i].temp) *
> +	return tbl[i].temp + ((tbl[i + 1].temp - tbl[i].temp) *
>  		(res - tbl[i].resist)) / (tbl[i + 1].resist - tbl[i].resist);
> -	return temp;
>  }
>  
>  /**

Thanks, queued.

-- Sebastian

[toc] | [next] | [standalone]


#1563196

From"Gustavo A. R. Silva" <garsilva@embeddedor.com>
Date2017-01-20 00:30 +0100
Message-ID<t1ujv-80E-17@gated-at.bofh.it>
In reply to#1560170
Hey hello,

Quoting Sebastian Reichel <sre@kernel.org>:

> Hi,
>
> On Wed, Jan 11, 2017 at 08:29:35PM -0600, Gustavo A. R. Silva wrote:
>> Simplify return logic to avoid unnecessary variable assignments.
>> These issues were detected using Coccinelle and the following  
>> semantic patch:
>>
>> @@
>> local idexpression ret;
>> expression e;
>> @@
>>
>> -ret =
>> +return
>>      e;
>> -return ret;
>>
>> Signed-off-by: Gustavo A. R. Silva <garsilva@embeddedor.com>
>> ---
>>  drivers/power/supply/ab8500_btemp.c | 10 +++-------
>>  1 file changed, 3 insertions(+), 7 deletions(-)
>>
>> diff --git a/drivers/power/supply/ab8500_btemp.c  
>> b/drivers/power/supply/ab8500_btemp.c
>> index 6ffdc18..9b01b52 100644
>> --- a/drivers/power/supply/ab8500_btemp.c
>> +++ b/drivers/power/supply/ab8500_btemp.c
>> @@ -123,10 +123,7 @@ static LIST_HEAD(ab8500_btemp_list);
>>   */
>>  struct ab8500_btemp *ab8500_btemp_get(void)
>>  {
>> -	struct ab8500_btemp *btemp;
>> -	btemp = list_first_entry(&ab8500_btemp_list, struct ab8500_btemp, node);
>> -
>> -	return btemp;
>> +	return list_first_entry(&ab8500_btemp_list, struct ab8500_btemp, node);
>>  }
>>  EXPORT_SYMBOL(ab8500_btemp_get);
>>
>> @@ -470,7 +467,7 @@ static int ab8500_btemp_get_batctrl_res(struct  
>> ab8500_btemp *di)
>>  static int ab8500_btemp_res_to_temp(struct ab8500_btemp *di,
>>  	const struct abx500_res_to_temp *tbl, int tbl_size, int res)
>>  {
>> -	int i, temp;
>> +	int i;
>>  	/*
>>  	 * Calculate the formula for the straight line
>>  	 * Simple interpolation if we are within
>> @@ -488,9 +485,8 @@ static int ab8500_btemp_res_to_temp(struct  
>> ab8500_btemp *di,
>>  			i++;
>>  	}
>>
>> -	temp = tbl[i].temp + ((tbl[i + 1].temp - tbl[i].temp) *
>> +	return tbl[i].temp + ((tbl[i + 1].temp - tbl[i].temp) *
>>  		(res - tbl[i].resist)) / (tbl[i + 1].resist - tbl[i].resist);
>> -	return temp;
>>  }
>>
>>  /**
>
> Thanks, queued.
>

Awesome, thanks!
--
Gustavo A. R. Silva

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web