linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/2] i2c: exynos5: remove some dead code
@ 2018-05-09 19:45 ` Peter Rosin
  2018-05-09 19:45   ` [PATCH 2/2] i2c: exynos5: remove pointless initializers Peter Rosin
  2018-05-10  8:36   ` [PATCH 1/2] i2c: exynos5: remove some dead code Andrzej Hajda
  0 siblings, 2 replies; 6+ messages in thread
From: Peter Rosin @ 2018-05-09 19:45 UTC (permalink / raw)
  To: linux-kernel
  Cc: Peter Rosin, Kukjin Kim, Krzysztof Kozlowski, Wolfram Sang,
	Andrzej Hajda, Masahiro Yamada, Andy Shevchenko, linux-i2c,
	linux-arm-kernel, linux-samsung-soc

The else branch cannot be taken as i will always equal num.
Get rid of the whole construct.

Signed-off-by: Peter Rosin <peda@axentia.se>
---
 drivers/i2c/busses/i2c-exynos5.c | 12 +-----------
 1 file changed, 1 insertion(+), 11 deletions(-)

diff --git a/drivers/i2c/busses/i2c-exynos5.c b/drivers/i2c/busses/i2c-exynos5.c
index 12ec8484e653..a2cbc779c33a 100644
--- a/drivers/i2c/busses/i2c-exynos5.c
+++ b/drivers/i2c/busses/i2c-exynos5.c
@@ -727,17 +727,7 @@ static int exynos5_i2c_xfer(struct i2c_adapter *adap,
 			goto out;
 	}
 
-	if (i == num) {
-		ret = num;
-	} else {
-		/* Only one message, cannot access the device */
-		if (i == 1)
-			ret = -EREMOTEIO;
-		else
-			ret = i;
-
-		dev_warn(i2c->dev, "xfer message failed\n");
-	}
+	ret = num;
 
  out:
 	clk_disable(i2c->clk);
-- 
2.11.0

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 2/2] i2c: exynos5: remove pointless initializers
  2018-05-09 19:45 ` [PATCH 1/2] i2c: exynos5: remove some dead code Peter Rosin
@ 2018-05-09 19:45   ` Peter Rosin
  2018-05-10  8:44     ` Andrzej Hajda
  2018-05-10  8:36   ` [PATCH 1/2] i2c: exynos5: remove some dead code Andrzej Hajda
  1 sibling, 1 reply; 6+ messages in thread
From: Peter Rosin @ 2018-05-09 19:45 UTC (permalink / raw)
  To: linux-kernel
  Cc: Peter Rosin, Kukjin Kim, Krzysztof Kozlowski, Wolfram Sang,
	Andrzej Hajda, Masahiro Yamada, Andy Shevchenko, linux-i2c,
	linux-arm-kernel, linux-samsung-soc

The variables are always assigned before use anyway.

Signed-off-by: Peter Rosin <peda@axentia.se>
---
 drivers/i2c/busses/i2c-exynos5.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/i2c/busses/i2c-exynos5.c b/drivers/i2c/busses/i2c-exynos5.c
index a2cbc779c33a..185fba37e830 100644
--- a/drivers/i2c/busses/i2c-exynos5.c
+++ b/drivers/i2c/busses/i2c-exynos5.c
@@ -707,7 +707,7 @@ static int exynos5_i2c_xfer(struct i2c_adapter *adap,
 			struct i2c_msg *msgs, int num)
 {
 	struct exynos5_i2c *i2c = adap->algo_data;
-	int i = 0, ret = 0, stop = 0;
+	int i, ret, stop;
 
 	if (i2c->suspended) {
 		dev_err(i2c->dev, "HS-I2C is not initialized.\n");
-- 
2.11.0

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH 1/2] i2c: exynos5: remove some dead code
  2018-05-09 19:45 ` [PATCH 1/2] i2c: exynos5: remove some dead code Peter Rosin
  2018-05-09 19:45   ` [PATCH 2/2] i2c: exynos5: remove pointless initializers Peter Rosin
@ 2018-05-10  8:36   ` Andrzej Hajda
  2018-05-10 19:16     ` Peter Rosin
  1 sibling, 1 reply; 6+ messages in thread
From: Andrzej Hajda @ 2018-05-10  8:36 UTC (permalink / raw)
  To: Peter Rosin, linux-kernel
  Cc: Kukjin Kim, Krzysztof Kozlowski, Wolfram Sang, Masahiro Yamada,
	Andy Shevchenko, linux-i2c, linux-arm-kernel, linux-samsung-soc

On 09.05.2018 21:45, Peter Rosin wrote:
> The else branch cannot be taken as i will always equal num.
> Get rid of the whole construct.
>
> Signed-off-by: Peter Rosin <peda@axentia.se>
> ---
>  drivers/i2c/busses/i2c-exynos5.c | 12 +-----------
>  1 file changed, 1 insertion(+), 11 deletions(-)
>
> diff --git a/drivers/i2c/busses/i2c-exynos5.c b/drivers/i2c/busses/i2c-exynos5.c
> index 12ec8484e653..a2cbc779c33a 100644
> --- a/drivers/i2c/busses/i2c-exynos5.c
> +++ b/drivers/i2c/busses/i2c-exynos5.c
> @@ -727,17 +727,7 @@ static int exynos5_i2c_xfer(struct i2c_adapter *adap,
>  			goto out;
>  	}
>  
> -	if (i == num) {
> -		ret = num;
> -	} else {
> -		/* Only one message, cannot access the device */
> -		if (i == 1)
> -			ret = -EREMOTEIO;
> -		else
> -			ret = i;
> -
> -		dev_warn(i2c->dev, "xfer message failed\n");
> -	}
> +	ret = num;
>  
>   out:
>  	clk_disable(i2c->clk);

You can go further and remove "out:" label, use break instead, and at
the end use "return (i == num) ? num : ret;" or sth similar.

With this change you can add:

Reviewed-by: Andrzej Hajda <a.hajda@samsung.com>

 --
Regards
Andrzej

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 2/2] i2c: exynos5: remove pointless initializers
  2018-05-09 19:45   ` [PATCH 2/2] i2c: exynos5: remove pointless initializers Peter Rosin
@ 2018-05-10  8:44     ` Andrzej Hajda
  2018-05-10 19:16       ` Peter Rosin
  0 siblings, 1 reply; 6+ messages in thread
From: Andrzej Hajda @ 2018-05-10  8:44 UTC (permalink / raw)
  To: Peter Rosin, linux-kernel
  Cc: Kukjin Kim, Krzysztof Kozlowski, Wolfram Sang, Masahiro Yamada,
	Andy Shevchenko, linux-i2c, linux-arm-kernel, linux-samsung-soc

On 09.05.2018 21:45, Peter Rosin wrote:
> The variables are always assigned before use anyway.
>
> Signed-off-by: Peter Rosin <peda@axentia.se>
> ---
>  drivers/i2c/busses/i2c-exynos5.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/i2c/busses/i2c-exynos5.c b/drivers/i2c/busses/i2c-exynos5.c
> index a2cbc779c33a..185fba37e830 100644
> --- a/drivers/i2c/busses/i2c-exynos5.c
> +++ b/drivers/i2c/busses/i2c-exynos5.c
> @@ -707,7 +707,7 @@ static int exynos5_i2c_xfer(struct i2c_adapter *adap,
>  			struct i2c_msg *msgs, int num)
>  {
>  	struct exynos5_i2c *i2c = adap->algo_data;
> -	int i = 0, ret = 0, stop = 0;
> +	int i, ret, stop;

I hope gcc is smart enough to not complain in case of ret.
I think you can merge both patches into one.

Regards
Andrzej

>  
>  	if (i2c->suspended) {
>  		dev_err(i2c->dev, "HS-I2C is not initialized.\n");

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 1/2] i2c: exynos5: remove some dead code
  2018-05-10  8:36   ` [PATCH 1/2] i2c: exynos5: remove some dead code Andrzej Hajda
@ 2018-05-10 19:16     ` Peter Rosin
  0 siblings, 0 replies; 6+ messages in thread
From: Peter Rosin @ 2018-05-10 19:16 UTC (permalink / raw)
  To: Andrzej Hajda, linux-kernel
  Cc: Kukjin Kim, Krzysztof Kozlowski, Wolfram Sang, Masahiro Yamada,
	Andy Shevchenko, linux-i2c, linux-arm-kernel, linux-samsung-soc

On 2018-05-10 10:36, Andrzej Hajda wrote:
> On 09.05.2018 21:45, Peter Rosin wrote:
>> The else branch cannot be taken as i will always equal num.
>> Get rid of the whole construct.
>>
>> Signed-off-by: Peter Rosin <peda@axentia.se>
>> ---
>>  drivers/i2c/busses/i2c-exynos5.c | 12 +-----------
>>  1 file changed, 1 insertion(+), 11 deletions(-)
>>
>> diff --git a/drivers/i2c/busses/i2c-exynos5.c b/drivers/i2c/busses/i2c-exynos5.c
>> index 12ec8484e653..a2cbc779c33a 100644
>> --- a/drivers/i2c/busses/i2c-exynos5.c
>> +++ b/drivers/i2c/busses/i2c-exynos5.c
>> @@ -727,17 +727,7 @@ static int exynos5_i2c_xfer(struct i2c_adapter *adap,
>>  			goto out;
>>  	}
>>  
>> -	if (i == num) {
>> -		ret = num;
>> -	} else {
>> -		/* Only one message, cannot access the device */
>> -		if (i == 1)
>> -			ret = -EREMOTEIO;
>> -		else
>> -			ret = i;
>> -
>> -		dev_warn(i2c->dev, "xfer message failed\n");
>> -	}
>> +	ret = num;
>>  
>>   out:
>>  	clk_disable(i2c->clk);
> 
> You can go further and remove "out:" label, use break instead, and at
> the end use "return (i == num) ? num : ret;" or sth similar.
> 
> With this change you can add:
> 
> Reviewed-by: Andrzej Hajda <a.hajda@samsung.com>

But then the patch wouldn't be so obviously safe. If I would write
a function equivalent to the original function, I think I'd write
something like:

static int exynos5_i2c_xfer(struct i2c_adapter *adap,
			    struct i2c_msg *msgs, int num)
{
	struct exynos5_i2c *i2c = adap->algo_data;
	int i, ret;

	if (i2c->suspended) {
		dev_err(i2c->dev, "HS-I2C is not initialized.\n");
		return -EIO;
	}

	ret = clk_enable(i2c->clk);
	if (ret)
		return ret;

	for (i = 0; !ret && i < num; i++)
		ret = exynos5_i2c_xfer_msg(i2c, msgs + i, i == num - 1);

	clk_disable(i2c->clk);

	return ret ?: num;
}

And I think that is safe because I don't see any possibility for
exynos_i2c_xfer_msg to return anything but zero success or negative
errors. Since I can only compile-test, so I do not feel all that
good about going further than I did.

But if you or anyone can test the above function, feel free to make
a patch out of it. I don't care enough to make a bunch of iterations
on these trivialities. I just spotted dead code and dumb initializers
while looking for other things. So, take it or leave it. I.e. it was
just a couple of drive-by patches.

Cheers,
Peter

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 2/2] i2c: exynos5: remove pointless initializers
  2018-05-10  8:44     ` Andrzej Hajda
@ 2018-05-10 19:16       ` Peter Rosin
  0 siblings, 0 replies; 6+ messages in thread
From: Peter Rosin @ 2018-05-10 19:16 UTC (permalink / raw)
  To: Andrzej Hajda, linux-kernel
  Cc: Kukjin Kim, Krzysztof Kozlowski, Wolfram Sang, Masahiro Yamada,
	Andy Shevchenko, linux-i2c, linux-arm-kernel, linux-samsung-soc

On 2018-05-10 10:44, Andrzej Hajda wrote:
> On 09.05.2018 21:45, Peter Rosin wrote:
>> The variables are always assigned before use anyway.
>>
>> Signed-off-by: Peter Rosin <peda@axentia.se>
>> ---
>>  drivers/i2c/busses/i2c-exynos5.c | 2 +-
>>  1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/drivers/i2c/busses/i2c-exynos5.c b/drivers/i2c/busses/i2c-exynos5.c
>> index a2cbc779c33a..185fba37e830 100644
>> --- a/drivers/i2c/busses/i2c-exynos5.c
>> +++ b/drivers/i2c/busses/i2c-exynos5.c
>> @@ -707,7 +707,7 @@ static int exynos5_i2c_xfer(struct i2c_adapter *adap,
>>  			struct i2c_msg *msgs, int num)
>>  {
>>  	struct exynos5_i2c *i2c = adap->algo_data;
>> -	int i = 0, ret = 0, stop = 0;
>> +	int i, ret, stop;
> 
> I hope gcc is smart enough to not complain in case of ret.

I think any compiler is smart enough to see that; you must have missed
this line:

	ret = clk_enable(i2c->clk);

which is the first to touch ret in the function.

> I think you can merge both patches into one.

I could, but I wanted to make the patches totally obvious and easy to
review. The patches do independent things, so I prefer not to squash.

Cheers,
Peter

> 
> Regards
> Andrzej
> 
>>  
>>  	if (i2c->suspended) {
>>  		dev_err(i2c->dev, "HS-I2C is not initialized.\n");
> 
> 

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2018-05-10 19:16 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <CGME20180509194548epcas2p25579e969e21707afe2435b1f568ff005@epcas2p2.samsung.com>
2018-05-09 19:45 ` [PATCH 1/2] i2c: exynos5: remove some dead code Peter Rosin
2018-05-09 19:45   ` [PATCH 2/2] i2c: exynos5: remove pointless initializers Peter Rosin
2018-05-10  8:44     ` Andrzej Hajda
2018-05-10 19:16       ` Peter Rosin
2018-05-10  8:36   ` [PATCH 1/2] i2c: exynos5: remove some dead code Andrzej Hajda
2018-05-10 19:16     ` Peter Rosin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).