Skip to contentSkip to conversation

drivers: power: supply: Compress return logic into one line.

PATCH In review Gustavo A. R. Silva 3 participants 3 messages Jan 12, 2017 – Jan 19, 2017

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 drivers: power: supply: Compress return logic into one line.

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;

---
 drivers/power/supply/ab8500_btemp.c | 10 +++-------
 1 file changed, 3 insertions(+), 7 deletions(-)
drivers/power/supply/ab8500_btemp.c +3 -7
index 6ffdc18..9b01b52 100644
@@ -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;
 }
 
 /**
Signature · 1 line
2.5.0
#1 lore raw

Hi,

Quoted 44 lines · Gustavo A. R. Silva

Simplify return logic to avoid unnecessary variable assignments. These issues were detected using Coccinelle and the following semantic patch:

@@
local idexpression ret;
expression e;
@@

(quoted diff) +1 -2
-ret =
+return
     e;
-return ret;
---
 drivers/power/supply/ab8500_btemp.c | 10 +++-------
 1 file changed, 3 insertions(+), 7 deletions(-)
drivers/power/supply/ab8500_btemp.c +2 -5
index 6ffdc18..9b01b52 100644
@@ -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

drivers/power/supply/ab8500_btemp.c static int ab8500_btemp_res_to_temp(struct ab8500_btemp *di, · line 492

Quoted 10 lines
drivers/power/supply/ab8500_btemp.c +1 -2
@@ -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

#2 lore raw

Hey hello,

Quoting Sebastian Reichel <[email protected]>:

Quoted 58 lines

Hi,

Quoted 55 lines · Gustavo A. R. Silva

Simplify return logic to avoid unnecessary variable assignments. These issues were detected using Coccinelle and the following semantic patch:

@@
local idexpression ret;
expression e;
@@

(quoted diff) +1 -2
-ret =
+return
     e;
-return ret;
---
 drivers/power/supply/ab8500_btemp.c | 10 +++-------
 1 file changed, 3 insertions(+), 7 deletions(-)
drivers/power/supply/ab8500_btemp.c +2 -5
index 6ffdc18..9b01b52 100644
@@ -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
drivers/power/supply/ab8500_btemp.c +1 -2
 	 * 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;
 }
 
Quoted 4 lines
Quoted 1 line

/**

Thanks, queued.

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