2015-02-10 08:15:50

by Nicholas Mc Guire

[permalink] [raw]
Subject: [PATCH v2] i2c: designware: fixup return handling of wait_for_completion_timeout

return type of wait_for_completion_timeout is unsigned long not int, rather
than introducing a new variable the wait_for_completion_timeout is moved
into the if condition as the return value is only used to detect timeout.

Signed-off-by: Nicholas Mc Guire <[email protected]>
---

v2: Aside from the newly added variable having the wrong type (...) the
preferred solution is to simply wrap wait_for_completion_timeout into
the condition as the remaining jiffies is actually not used - suggested
be Jarkko Nikula <[email protected].

Patch was compile tested with x86_64_defconfig +
CONFIG_X86_AMD_PLATFORM_DEVICE=y, CONFIG_I2C_DESIGNWARE_PLATFORM=m
(implies CONFIG_I2C_DESIGNWARE_CORE=y)

Patch is against 3.19.0-rc7 (localversion-next is -next-20150209)

drivers/i2c/busses/i2c-designware-core.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/i2c/busses/i2c-designware-core.c b/drivers/i2c/busses/i2c-designware-core.c
index 6e25c01..6f19a33 100644
--- a/drivers/i2c/busses/i2c-designware-core.c
+++ b/drivers/i2c/busses/i2c-designware-core.c
@@ -656,8 +656,7 @@ i2c_dw_xfer(struct i2c_adapter *adap, struct i2c_msg msgs[], int num)
i2c_dw_xfer_init(dev);

/* wait for tx to complete */
- ret = wait_for_completion_timeout(&dev->cmd_complete, HZ);
- if (ret == 0) {
+ if (!wait_for_completion_timeout(&dev->cmd_complete, HZ)) {
dev_err(dev->dev, "controller timed out\n");
/* i2c_dw_init implicitly disables the adapter */
i2c_dw_init(dev);
--
1.7.10.4


2015-02-10 08:31:07

by Jarkko Nikula

[permalink] [raw]
Subject: Re: [PATCH v2] i2c: designware: fixup return handling of wait_for_completion_timeout

On 02/10/2015 10:11 AM, Nicholas Mc Guire wrote:
> return type of wait_for_completion_timeout is unsigned long not int, rather
> than introducing a new variable the wait_for_completion_timeout is moved
> into the if condition as the return value is only used to detect timeout.
>
> Signed-off-by: Nicholas Mc Guire <[email protected]>
> ---
>
> v2: Aside from the newly added variable having the wrong type (...) the
> preferred solution is to simply wrap wait_for_completion_timeout into
> the condition as the remaining jiffies is actually not used - suggested
> be Jarkko Nikula <[email protected].
>
> Patch was compile tested with x86_64_defconfig +
> CONFIG_X86_AMD_PLATFORM_DEVICE=y, CONFIG_I2C_DESIGNWARE_PLATFORM=m
> (implies CONFIG_I2C_DESIGNWARE_CORE=y)
>
> Patch is against 3.19.0-rc7 (localversion-next is -next-20150209)
>
> drivers/i2c/busses/i2c-designware-core.c | 3 +--
> 1 file changed, 1 insertion(+), 2 deletions(-)
>
> diff --git a/drivers/i2c/busses/i2c-designware-core.c b/drivers/i2c/busses/i2c-designware-core.c
> index 6e25c01..6f19a33 100644
> --- a/drivers/i2c/busses/i2c-designware-core.c
> +++ b/drivers/i2c/busses/i2c-designware-core.c
> @@ -656,8 +656,7 @@ i2c_dw_xfer(struct i2c_adapter *adap, struct i2c_msg msgs[], int num)
> i2c_dw_xfer_init(dev);
>
> /* wait for tx to complete */
> - ret = wait_for_completion_timeout(&dev->cmd_complete, HZ);
> - if (ret == 0) {
> + if (!wait_for_completion_timeout(&dev->cmd_complete, HZ)) {
> dev_err(dev->dev, "controller timed out\n");
> /* i2c_dw_init implicitly disables the adapter */
> i2c_dw_init(dev);
>
Reviewed-by: Jarkko Nikula <[email protected]>