[v2] i2c: recovery: rename variable for easier understanding

Message ID 20180710222722.7852-1-wsa+renesas@sang-engineering.com
State Accepted
Headers show
Series
  • [v2] i2c: recovery: rename variable for easier understanding
Related show

Commit Message

Wolfram Sang July 10, 2018, 10:27 p.m.
While refactoring the routine before, it occured to me that this will
make the code much easier to understand.

Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
---

Change since V1:
* rebased to the new recovery refactoring

Branch is here:
git://git.kernel.org/pub/scm/linux/kernel/git/wsa/linux.git renesas/i2c/recovery/write-byte-fix

 drivers/i2c/i2c-core-base.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

Comments

Peter Rosin July 11, 2018, 6:01 a.m. | #1
On 2018-07-11 00:27, Wolfram Sang wrote:
> While refactoring the routine before, it occured to me that this will
> make the code much easier to understand.

Acked-by: Peter Rosin <peda@axentia.se>
 
> Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
> ---
> 
> Change since V1:
> * rebased to the new recovery refactoring
> 
> Branch is here:
> git://git.kernel.org/pub/scm/linux/kernel/git/wsa/linux.git renesas/i2c/recovery/write-byte-fix
> 
>  drivers/i2c/i2c-core-base.c | 14 +++++++-------
>  1 file changed, 7 insertions(+), 7 deletions(-)
> 
> diff --git a/drivers/i2c/i2c-core-base.c b/drivers/i2c/i2c-core-base.c
> index 59f8dfc5be36..57538d72f2e5 100644
> --- a/drivers/i2c/i2c-core-base.c
> +++ b/drivers/i2c/i2c-core-base.c
> @@ -185,12 +185,12 @@ static int i2c_generic_bus_free(struct i2c_adapter *adap)
>  int i2c_generic_scl_recovery(struct i2c_adapter *adap)
>  {
>  	struct i2c_bus_recovery_info *bri = adap->bus_recovery_info;
> -	int i = 0, val = 1, ret;
> +	int i = 0, scl = 1, ret;
>  
>  	if (bri->prepare_recovery)
>  		bri->prepare_recovery(adap);
>  
> -	bri->set_scl(adap, val);
> +	bri->set_scl(adap, scl);
>  	if (bri->set_sda)
>  		bri->set_sda(adap, 1);
>  	ndelay(RECOVERY_NDELAY);
> @@ -199,7 +199,7 @@ int i2c_generic_scl_recovery(struct i2c_adapter *adap)
>  	 * By this time SCL is high, as we need to give 9 falling-rising edges
>  	 */
>  	while (i++ < RECOVERY_CLK_CNT * 2) {
> -		if (val) {
> +		if (scl) {
>  			/* SCL shouldn't be low here */
>  			if (!bri->get_scl(adap)) {
>  				dev_err(&adap->dev,
> @@ -209,8 +209,8 @@ int i2c_generic_scl_recovery(struct i2c_adapter *adap)
>  			}
>  		}
>  
> -		val = !val;
> -		bri->set_scl(adap, val);
> +		scl = !scl;
> +		bri->set_scl(adap, scl);
>  
>  		/*
>  		 * If we can set SDA, we will always create STOP here to ensure
> @@ -220,10 +220,10 @@ int i2c_generic_scl_recovery(struct i2c_adapter *adap)
>  		 */
>  		ndelay(RECOVERY_NDELAY / 2);
>  		if (bri->set_sda)
> -			bri->set_sda(adap, val);
> +			bri->set_sda(adap, scl);
>  		ndelay(RECOVERY_NDELAY / 2);
>  
> -		if (val) {
> +		if (scl) {
>  			ret = i2c_generic_bus_free(adap);
>  			if (ret == 0)
>  				break;
>
Wolfram Sang July 17, 2018, 8:49 a.m. | #2
On Wed, Jul 11, 2018 at 12:27:22AM +0200, Wolfram Sang wrote:
> While refactoring the routine before, it occured to me that this will
> make the code much easier to understand.
> 
> Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com>

Fixed a typo in the commit msg and applied to for-next, thanks!

Patch

diff --git a/drivers/i2c/i2c-core-base.c b/drivers/i2c/i2c-core-base.c
index 59f8dfc5be36..57538d72f2e5 100644
--- a/drivers/i2c/i2c-core-base.c
+++ b/drivers/i2c/i2c-core-base.c
@@ -185,12 +185,12 @@  static int i2c_generic_bus_free(struct i2c_adapter *adap)
 int i2c_generic_scl_recovery(struct i2c_adapter *adap)
 {
 	struct i2c_bus_recovery_info *bri = adap->bus_recovery_info;
-	int i = 0, val = 1, ret;
+	int i = 0, scl = 1, ret;
 
 	if (bri->prepare_recovery)
 		bri->prepare_recovery(adap);
 
-	bri->set_scl(adap, val);
+	bri->set_scl(adap, scl);
 	if (bri->set_sda)
 		bri->set_sda(adap, 1);
 	ndelay(RECOVERY_NDELAY);
@@ -199,7 +199,7 @@  int i2c_generic_scl_recovery(struct i2c_adapter *adap)
 	 * By this time SCL is high, as we need to give 9 falling-rising edges
 	 */
 	while (i++ < RECOVERY_CLK_CNT * 2) {
-		if (val) {
+		if (scl) {
 			/* SCL shouldn't be low here */
 			if (!bri->get_scl(adap)) {
 				dev_err(&adap->dev,
@@ -209,8 +209,8 @@  int i2c_generic_scl_recovery(struct i2c_adapter *adap)
 			}
 		}
 
-		val = !val;
-		bri->set_scl(adap, val);
+		scl = !scl;
+		bri->set_scl(adap, scl);
 
 		/*
 		 * If we can set SDA, we will always create STOP here to ensure
@@ -220,10 +220,10 @@  int i2c_generic_scl_recovery(struct i2c_adapter *adap)
 		 */
 		ndelay(RECOVERY_NDELAY / 2);
 		if (bri->set_sda)
-			bri->set_sda(adap, val);
+			bri->set_sda(adap, scl);
 		ndelay(RECOVERY_NDELAY / 2);
 
-		if (val) {
+		if (scl) {
 			ret = i2c_generic_bus_free(adap);
 			if (ret == 0)
 				break;