All of lore.kernel.org
 help / color / mirror / Atom feed
From: Peter Rosin <peda@axentia.se>
To: Andrzej Hajda <a.hajda@samsung.com>, linux-kernel@vger.kernel.org
Cc: Kukjin Kim <kgene@kernel.org>,
	Krzysztof Kozlowski <krzk@kernel.org>,
	Wolfram Sang <wsa@the-dreams.de>,
	Masahiro Yamada <yamada.masahiro@socionext.com>,
	Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
	linux-i2c@vger.kernel.org, linux-arm-kernel@lists.infradead.org,
	linux-samsung-soc@vger.kernel.org
Subject: Re: [PATCH 1/2] i2c: exynos5: remove some dead code
Date: Thu, 10 May 2018 21:16:28 +0200	[thread overview]
Message-ID: <fa946b32-99b2-c59b-e4d0-7188fdc7bfc0@axentia.se> (raw)
In-Reply-To: <b3915e40-895f-2a72-27a2-dcffe504456d@samsung.com>

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

WARNING: multiple messages have this Message-ID (diff)
From: peda@axentia.se (Peter Rosin)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH 1/2] i2c: exynos5: remove some dead code
Date: Thu, 10 May 2018 21:16:28 +0200	[thread overview]
Message-ID: <fa946b32-99b2-c59b-e4d0-7188fdc7bfc0@axentia.se> (raw)
In-Reply-To: <b3915e40-895f-2a72-27a2-dcffe504456d@samsung.com>

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

  reply	other threads:[~2018-05-10 19:16 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [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   ` Peter Rosin
2018-05-09 19:45   ` [PATCH 2/2] i2c: exynos5: remove pointless initializers Peter Rosin
2018-05-09 19:45     ` Peter Rosin
2018-05-10  8:44     ` Andrzej Hajda
2018-05-10  8:44       ` Andrzej Hajda
2018-05-10 19:16       ` Peter Rosin
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  8:36     ` Andrzej Hajda
2018-05-10 19:16     ` Peter Rosin [this message]
2018-05-10 19:16       ` Peter Rosin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=fa946b32-99b2-c59b-e4d0-7188fdc7bfc0@axentia.se \
    --to=peda@axentia.se \
    --cc=a.hajda@samsung.com \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=kgene@kernel.org \
    --cc=krzk@kernel.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-i2c@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-samsung-soc@vger.kernel.org \
    --cc=wsa@the-dreams.de \
    --cc=yamada.masahiro@socionext.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.