[From nobody Sat Oct 28 12:22:55 2006
Message-ID: &lt;4543234A.2010808@gmail.com&gt;
Date: Sat, 28 Oct 2006 11:30:50 +0200
From: e9hack &lt;e9hack@gmail.com&gt;
User-Agent: Thunderbird 1.5.0.5 (Windows/20060719)
MIME-Version: 1.0
To: linux-dvb@linuxtv.org
Subject: [PATCH 2/3] Fix a timeout problem of the interrupt driven i2c-transfer
	of the SAA7146
Content-Type: multipart/mixed; boundary=&quot;------------090609090708090401070307&quot;

This is a multi-part message in MIME format.
--------------090609090708090401070307
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit

Hi,

the attached patch adds a timeout to the waiting for an interrupt after the executing of an i2c-operation. This prevents
 against a endless waiting, if the SAA7146 does not hit the interrupt.

This patch needs my previous patch.

- Hartmut


--------------090609090708090401070307
Content-Type: text/x-patch;
 name=&quot;saa7146-i2c-fix.patch&quot;
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename=&quot;saa7146-i2c-fix.patch&quot;

Signed-of-by: Hartmut Birr &lt;e9hack@googlemail.com&gt;

Add a timeout to the wait for the i2c-interrupt. 
The interrupt may never hit. The timeout prevents from endless waiting.

diff -r 5e9d301ef13b linux/drivers/media/common/saa7146_i2c.c
--- a/linux/drivers/media/common/saa7146_i2c.c	Thu Oct 26 10:10:56 2006 -0300
+++ b/linux/drivers/media/common/saa7146_i2c.c	Sat Oct 28 10:03:44 2006 +0200
@@ -193,10 +193,22 @@ static int saa7146_i2c_writeout(struct s
 		SAA7146_IER_ENABLE(dev, MASK_16|MASK_17);
 		saa7146_write(dev, MC2, (MASK_00 | MASK_16));
 
-		wait_event_interruptible(dev-&gt;i2c_wq, dev-&gt;i2c_op == 0);
-		if (signal_pending (current)) {
-			/* a signal arrived */
-			return -ERESTARTSYS;
+		timeout = HZ/100 + 1; /* 10ms */
+		timeout = wait_event_interruptible_timeout(dev-&gt;i2c_wq, dev-&gt;i2c_op == 0, timeout);
+		if (timeout == -ERESTARTSYS || dev-&gt;i2c_op) {
+			spin_lock_irqsave(&amp;dev-&gt;slock, flags);
+			SAA7146_IER_DISABLE(dev, MASK_16|MASK_17);
+			saa7146_write(dev, ISR, MASK_16|MASK_17);
+			spin_unlock_irqrestore(&amp;dev-&gt;slock, flags);
+			if (timeout == -ERESTARTSYS) {
+				/* a signal arrived */
+				return -ERESTARTSYS;
+			}
+			/* this is normal when probing the bus
+			 * (no answer from nonexisistant device...)
+			 */
+			DEB_I2C((&quot;saa7146_i2c_writeout: timed out waiting for end of xfer\n&quot;));
+			return -EIO;
 		}
 		status = saa7146_read(dev, I2C_STATUS);
 	} else {

--------------090609090708090401070307--

]