public inbox for linux-i2c@vger.kernel.org
 help / color / mirror / Atom feed
From: Mike Looijmans <mike.looijmans-Oq418RWZeHk@public.gmane.org>
To: git-gjFFaj9aHVfQT0dZR+AlfA@public.gmane.org,
	wsa-z923LK4zBo2bacvFa/9K2g@public.gmane.org,
	linux-i2c-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
Cc: linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	Mike Looijmans <mike.looijmans-Oq418RWZeHk@public.gmane.org>
Subject: [PATCH] i2c-cadence: Do not let signals interrupt I2C transfers
Date: Tue, 11 Mar 2014 08:07:35 +0100	[thread overview]
Message-ID: <1394521655-3444-1-git-send-email-mike.looijmans@topic.nl> (raw)
In-Reply-To: <1394449954-10797-1-git-send-email-mike.looijmans-Oq418RWZeHk@public.gmane.org>

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-Oq418RWZeHk@public.gmane.org>
---
 drivers/i2c/busses/i2c-cadence.c |   12 ++++--------
 1 file changed, 4 insertions(+), 8 deletions(-)

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);
-- 
1.7.9.5

  parent reply	other threads:[~2014-03-11  7:07 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-03-10 11:12 [PATCH] i2c-cadence: Do not let signals interrupt I2C transfers Mike Looijmans
2014-03-10 21:59 ` Sören Brinkmann
     [not found] ` <20140310215952.GF13293@xsjandreislx>
2014-03-11  4:49   ` Suneel Garapati
     [not found]     ` <b6f0755f-cfc9-4962-851f-5eeac767e93e-dAX9Bq04yCSsiP+nND6G/7jjLBE8jN/0@public.gmane.org>
2014-03-11  6:59       ` Mike Looijmans
     [not found] ` <1394449954-10797-1-git-send-email-mike.looijmans-Oq418RWZeHk@public.gmane.org>
2014-03-11  7:07   ` Mike Looijmans [this message]
     [not found]     ` <1394521655-3444-1-git-send-email-mike.looijmans-Oq418RWZeHk@public.gmane.org>
2014-03-11 16:00       ` Sören Brinkmann

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=1394521655-3444-1-git-send-email-mike.looijmans@topic.nl \
    --to=mike.looijmans-oq418rwzehk@public.gmane.org \
    --cc=git-gjFFaj9aHVfQT0dZR+AlfA@public.gmane.org \
    --cc=linux-i2c-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=wsa-z923LK4zBo2bacvFa/9K2g@public.gmane.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox