diff mbox

i2c-cadence: Do not let signals interrupt I2C transfers

Message ID 1394521655-3444-1-git-send-email-mike.looijmans@topic.nl
State Superseded
Headers show

Commit Message

Mike Looijmans March 11, 2014, 7:07 a.m. UTC
Pressing CTRL-C while communicating with an I2C device leads to erratic
behaviour. The cause is that the controller will interrupt the I2C transfer
in progress, and leave the client device in an undefined state. Many
drivers do not handle error return codes on I2C transfers. The calling driver
has no way of telling how much of the transfer has actually completed, so
it cannot reliably determine the device's state.

The best solution here is to not handle signals in the I2C bus driver at all,
but always complete a transaction before returning control.

See for a related patch and discussion on this topic:
http://lkml.org/lkml/2014/1/9/246

Signed-off-by: Mike Looijmans <mike.looijmans@topic.nl>
---
 drivers/i2c/busses/i2c-cadence.c |   12 ++++--------
 1 file changed, 4 insertions(+), 8 deletions(-)

Comments

Soren Brinkmann March 11, 2014, 4 p.m. UTC | #1
Hi Mike,

On Tue, 2014-03-11 at 08:07AM +0100, Mike Looijmans wrote:
> Pressing CTRL-C while communicating with an I2C device leads to erratic
> behaviour. The cause is that the controller will interrupt the I2C transfer
> in progress, and leave the client device in an undefined state. Many
> drivers do not handle error return codes on I2C transfers. The calling driver
> has no way of telling how much of the transfer has actually completed, so
> it cannot reliably determine the device's state.
> 
> The best solution here is to not handle signals in the I2C bus driver at all,
> but always complete a transaction before returning control.
> 
> See for a related patch and discussion on this topic:
> http://lkml.org/lkml/2014/1/9/246
> 
> Signed-off-by: Mike Looijmans <mike.looijmans@topic.nl>
Acked-by: Soren Brinkmann <soren.brinkmann@xilinx.com>

Thanks for the update. I'll take these changes and resubmit the driver
to LKML as well.

	Sören


--
To unsubscribe from this list: send the line "unsubscribe linux-i2c" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/drivers/i2c/busses/i2c-cadence.c b/drivers/i2c/busses/i2c-cadence.c
index 86713d6..c61c3c9 100644
--- a/drivers/i2c/busses/i2c-cadence.c
+++ b/drivers/i2c/busses/i2c-cadence.c
@@ -452,16 +452,12 @@  static int cdns_i2c_process_msg(struct cdns_i2c *id, struct i2c_msg *msg,
 			cdns_i2c_msend(id);
 
 		/* Wait for the signal of completion */
-		ret = wait_for_completion_interruptible_timeout(
-							&id->xfer_done, HZ);
-		if (ret < 1) {
+		ret = wait_for_completion_timeout(&id->xfer_done, HZ);
+		if (!ret) {
 			cdns_i2c_master_reset(adap);
-			if (!ret) {
-				dev_err(id->adap.dev.parent,
+			dev_err(id->adap.dev.parent,
 					"timeout waiting on completion\n");
-				return -ETIMEDOUT;
-			}
-			return ret;
+			return -ETIMEDOUT;
 		}
 		cdns_i2c_writereg(CDNS_I2C_IXR_ALL_INTR_MASK,
 				  CDNS_I2C_IDR_OFFSET);