* [PATCH] i2c: davinci: fixup wait_for_completion_timeout handling
@ 2015-03-17 7:51 ` Nicholas Mc Guire
0 siblings, 0 replies; 4+ messages in thread
From: Nicholas Mc Guire @ 2015-03-17 7:51 UTC (permalink / raw)
To: Sekhar Nori
Cc: Kevin Hilman, Wolfram Sang, linux-i2c, linux-kernel, Nicholas Mc Guire
wait_for_completion_timeout return 0 (timeout) or >=1 (completion) so the check
for >= 0 is always true and can be dropped implying that r==-EREMOTEIO and thus
the return of -EREMOTEIO can be done in the if (dev->buf_len) branch.
As wait_for_completion_timeout returns unsigned long not int, and int r is
exclusively used for wait_for_completion_timeout it is renamed and the type
changed to unsigned long.
Signed-off-by: Nicholas Mc Guire <hofrat@osadl.org>
---
Patch was compile tested with davinci_all_defconfig (implies CONFIG_I2C_DAVINCI=y)
Patch is against 4.0-rc4 (localversion-next is -next-20150317)
drivers/i2c/busses/i2c-davinci.c | 17 +++++++----------
1 file changed, 7 insertions(+), 10 deletions(-)
diff --git a/drivers/i2c/busses/i2c-davinci.c b/drivers/i2c/busses/i2c-davinci.c
index 6dc7ff5..120a4ef 100644
--- a/drivers/i2c/busses/i2c-davinci.c
+++ b/drivers/i2c/busses/i2c-davinci.c
@@ -304,7 +304,7 @@ i2c_davinci_xfer_msg(struct i2c_adapter *adap, struct i2c_msg *msg, int stop)
struct davinci_i2c_platform_data *pdata = dev->pdata;
u32 flag;
u16 w;
- int r;
+ unsigned long time_left;
/* Introduce a delay, required for some boards (e.g Davinci EVM) */
if (pdata->bus_delay)
@@ -368,8 +368,9 @@ i2c_davinci_xfer_msg(struct i2c_adapter *adap, struct i2c_msg *msg, int stop)
flag |= DAVINCI_I2C_MDR_STP;
davinci_i2c_write_reg(dev, DAVINCI_I2C_MDR_REG, flag);
- r = wait_for_completion_timeout(&dev->cmd_complete, dev->adapter.timeout);
- if (r == 0) {
+ time_left = wait_for_completion_timeout(&dev->cmd_complete,
+ dev->adapter.timeout);
+ if (!time_left) {
dev_err(dev->dev, "controller timed out\n");
davinci_i2c_recover_bus(dev);
i2c_davinci_init(dev);
@@ -380,17 +381,13 @@ i2c_davinci_xfer_msg(struct i2c_adapter *adap, struct i2c_msg *msg, int stop)
/* This should be 0 if all bytes were transferred
* or dev->cmd_err denotes an error.
*/
- if (r >= 0) {
- dev_err(dev->dev, "abnormal termination buf_len=%i\n",
- dev->buf_len);
- r = -EREMOTEIO;
- }
+ dev_err(dev->dev, "abnormal termination buf_len=%i\n",
+ dev->buf_len);
dev->terminate = 1;
wmb();
dev->buf_len = 0;
+ return -EREMOTEIO;
}
- if (r < 0)
- return r;
/* no error */
if (likely(!dev->cmd_err))
--
1.7.10.4
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH] i2c: davinci: fixup wait_for_completion_timeout handling
@ 2015-03-17 7:51 ` Nicholas Mc Guire
0 siblings, 0 replies; 4+ messages in thread
From: Nicholas Mc Guire @ 2015-03-17 7:51 UTC (permalink / raw)
To: Sekhar Nori
Cc: Kevin Hilman, Wolfram Sang, linux-i2c-u79uwXL29TY76Z2rM5mHXA,
linux-kernel-u79uwXL29TY76Z2rM5mHXA, Nicholas Mc Guire
wait_for_completion_timeout return 0 (timeout) or >=1 (completion) so the check
for >= 0 is always true and can be dropped implying that r==-EREMOTEIO and thus
the return of -EREMOTEIO can be done in the if (dev->buf_len) branch.
As wait_for_completion_timeout returns unsigned long not int, and int r is
exclusively used for wait_for_completion_timeout it is renamed and the type
changed to unsigned long.
Signed-off-by: Nicholas Mc Guire <hofrat-Q945KHDl0DbYtjvyW6yDsg@public.gmane.org>
---
Patch was compile tested with davinci_all_defconfig (implies CONFIG_I2C_DAVINCI=y)
Patch is against 4.0-rc4 (localversion-next is -next-20150317)
drivers/i2c/busses/i2c-davinci.c | 17 +++++++----------
1 file changed, 7 insertions(+), 10 deletions(-)
diff --git a/drivers/i2c/busses/i2c-davinci.c b/drivers/i2c/busses/i2c-davinci.c
index 6dc7ff5..120a4ef 100644
--- a/drivers/i2c/busses/i2c-davinci.c
+++ b/drivers/i2c/busses/i2c-davinci.c
@@ -304,7 +304,7 @@ i2c_davinci_xfer_msg(struct i2c_adapter *adap, struct i2c_msg *msg, int stop)
struct davinci_i2c_platform_data *pdata = dev->pdata;
u32 flag;
u16 w;
- int r;
+ unsigned long time_left;
/* Introduce a delay, required for some boards (e.g Davinci EVM) */
if (pdata->bus_delay)
@@ -368,8 +368,9 @@ i2c_davinci_xfer_msg(struct i2c_adapter *adap, struct i2c_msg *msg, int stop)
flag |= DAVINCI_I2C_MDR_STP;
davinci_i2c_write_reg(dev, DAVINCI_I2C_MDR_REG, flag);
- r = wait_for_completion_timeout(&dev->cmd_complete, dev->adapter.timeout);
- if (r == 0) {
+ time_left = wait_for_completion_timeout(&dev->cmd_complete,
+ dev->adapter.timeout);
+ if (!time_left) {
dev_err(dev->dev, "controller timed out\n");
davinci_i2c_recover_bus(dev);
i2c_davinci_init(dev);
@@ -380,17 +381,13 @@ i2c_davinci_xfer_msg(struct i2c_adapter *adap, struct i2c_msg *msg, int stop)
/* This should be 0 if all bytes were transferred
* or dev->cmd_err denotes an error.
*/
- if (r >= 0) {
- dev_err(dev->dev, "abnormal termination buf_len=%i\n",
- dev->buf_len);
- r = -EREMOTEIO;
- }
+ dev_err(dev->dev, "abnormal termination buf_len=%i\n",
+ dev->buf_len);
dev->terminate = 1;
wmb();
dev->buf_len = 0;
+ return -EREMOTEIO;
}
- if (r < 0)
- return r;
/* no error */
if (likely(!dev->cmd_err))
--
1.7.10.4
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] i2c: davinci: fixup wait_for_completion_timeout handling
2015-03-17 7:51 ` Nicholas Mc Guire
(?)
@ 2015-03-17 9:29 ` Alexander Sverdlin
-1 siblings, 0 replies; 4+ messages in thread
From: Alexander Sverdlin @ 2015-03-17 9:29 UTC (permalink / raw)
To: ext Nicholas Mc Guire, Sekhar Nori
Cc: Kevin Hilman, Wolfram Sang, linux-i2c, linux-kernel
Hi!
On 17/03/15 08:51, ext Nicholas Mc Guire wrote:
> wait_for_completion_timeout return 0 (timeout) or >=1 (completion) so the check
> for >= 0 is always true and can be dropped implying that r==-EREMOTEIO and thus
> the return of -EREMOTEIO can be done in the if (dev->buf_len) branch.
> As wait_for_completion_timeout returns unsigned long not int, and int r is
> exclusively used for wait_for_completion_timeout it is renamed and the type
> changed to unsigned long.
>
> Signed-off-by: Nicholas Mc Guire <hofrat@osadl.org>
Even if it has no effect on functionality, the learning effect is positive, so that
nobody will copy the wrong code out. So the change is correct,
Acked-by: Alexander Sverdlin <alexander.sverdlin@nokia.com>
> ---
>
> Patch was compile tested with davinci_all_defconfig (implies CONFIG_I2C_DAVINCI=y)
>
> Patch is against 4.0-rc4 (localversion-next is -next-20150317)
>
> drivers/i2c/busses/i2c-davinci.c | 17 +++++++----------
> 1 file changed, 7 insertions(+), 10 deletions(-)
>
> diff --git a/drivers/i2c/busses/i2c-davinci.c b/drivers/i2c/busses/i2c-davinci.c
> index 6dc7ff5..120a4ef 100644
> --- a/drivers/i2c/busses/i2c-davinci.c
> +++ b/drivers/i2c/busses/i2c-davinci.c
> @@ -304,7 +304,7 @@ i2c_davinci_xfer_msg(struct i2c_adapter *adap, struct i2c_msg *msg, int stop)
> struct davinci_i2c_platform_data *pdata = dev->pdata;
> u32 flag;
> u16 w;
> - int r;
> + unsigned long time_left;
>
> /* Introduce a delay, required for some boards (e.g Davinci EVM) */
> if (pdata->bus_delay)
> @@ -368,8 +368,9 @@ i2c_davinci_xfer_msg(struct i2c_adapter *adap, struct i2c_msg *msg, int stop)
> flag |= DAVINCI_I2C_MDR_STP;
> davinci_i2c_write_reg(dev, DAVINCI_I2C_MDR_REG, flag);
>
> - r = wait_for_completion_timeout(&dev->cmd_complete, dev->adapter.timeout);
> - if (r == 0) {
> + time_left = wait_for_completion_timeout(&dev->cmd_complete,
> + dev->adapter.timeout);
> + if (!time_left) {
> dev_err(dev->dev, "controller timed out\n");
> davinci_i2c_recover_bus(dev);
> i2c_davinci_init(dev);
> @@ -380,17 +381,13 @@ i2c_davinci_xfer_msg(struct i2c_adapter *adap, struct i2c_msg *msg, int stop)
> /* This should be 0 if all bytes were transferred
> * or dev->cmd_err denotes an error.
> */
> - if (r >= 0) {
> - dev_err(dev->dev, "abnormal termination buf_len=%i\n",
> - dev->buf_len);
> - r = -EREMOTEIO;
> - }
> + dev_err(dev->dev, "abnormal termination buf_len=%i\n",
> + dev->buf_len);
> dev->terminate = 1;
> wmb();
> dev->buf_len = 0;
> + return -EREMOTEIO;
> }
> - if (r < 0)
> - return r;
>
> /* no error */
> if (likely(!dev->cmd_err))
--
Best regards,
Alexander Sverdlin.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] i2c: davinci: fixup wait_for_completion_timeout handling
2015-03-17 7:51 ` Nicholas Mc Guire
(?)
(?)
@ 2015-03-27 15:50 ` Wolfram Sang
-1 siblings, 0 replies; 4+ messages in thread
From: Wolfram Sang @ 2015-03-27 15:50 UTC (permalink / raw)
To: Nicholas Mc Guire; +Cc: Sekhar Nori, Kevin Hilman, linux-i2c, linux-kernel
[-- Attachment #1: Type: text/plain, Size: 593 bytes --]
On Tue, Mar 17, 2015 at 03:51:13AM -0400, Nicholas Mc Guire wrote:
> wait_for_completion_timeout return 0 (timeout) or >=1 (completion) so the check
> for >= 0 is always true and can be dropped implying that r==-EREMOTEIO and thus
> the return of -EREMOTEIO can be done in the if (dev->buf_len) branch.
> As wait_for_completion_timeout returns unsigned long not int, and int r is
> exclusively used for wait_for_completion_timeout it is renamed and the type
> changed to unsigned long.
>
> Signed-off-by: Nicholas Mc Guire <hofrat@osadl.org>
Applied to for-next, thanks!
[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 819 bytes --]
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2015-03-27 15:50 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-03-17 7:51 [PATCH] i2c: davinci: fixup wait_for_completion_timeout handling Nicholas Mc Guire
2015-03-17 7:51 ` Nicholas Mc Guire
2015-03-17 9:29 ` Alexander Sverdlin
2015-03-27 15:50 ` Wolfram Sang
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.