Skip to content

Commit

Permalink
i2c: davinci: fixup wait_for_completion_timeout handling
Browse files Browse the repository at this point in the history
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>
Acked-by: Alexander Sverdlin <alexander.sverdlin@nokia.com>
Signed-off-by: Wolfram Sang <wsa@the-dreams.de>
  • Loading branch information
Nicholas Mc Guire authored and Wolfram Sang committed Mar 27, 2015
1 parent 9c836d0 commit d9e1f44
Showing 1 changed file with 7 additions and 10 deletions.
17 changes: 7 additions & 10 deletions drivers/i2c/busses/i2c-davinci.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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);
Expand All @@ -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))
Expand Down

0 comments on commit d9e1f44

Please sign in to comment.