diff options
author | Timur Tabi <timur@freescale.com> | 2009-02-06 09:00:37 -0500 |
---|---|---|
committer | Kumar Gala <galak@kernel.crashing.org> | 2009-03-09 10:25:34 -0400 |
commit | 1ab082d7cbd0f34e39a5396cc6340c00bc5d66ef (patch) | |
tree | ae55102ad5c2ef84ca0462f29e6adf3607daf9b7 /drivers/i2c | |
parent | 652e8f8d579d61745094e36b4ff085026a332e73 (diff) |
i2c-mpc: do not allow interruptions when waiting for I2C to complete
The i2c_wait() function is using wait_event_interruptible_timeout() to wait for
the I2C controller to signal that it has completed an I2C bus operation. If
the process that causes the I2C operation terminated abruptly, the wait will
be interrupted, returning an error. It is better to let the I2C operation
finished before the process exits.
It is safe to use wait_event_timeout() instead, because the timeout will allow
the process to exit if the I2C bus hangs. It's also better to allow the
I2C operation to finish, because unacknowledged I2C operations can cause the
I2C bus to hang.
Signed-off-by: Timur Tabi <timur@freescale.com>
Acked-by: Ben Dooks <ben-linux@fluff.org>
Signed-off-by: Kumar Gala <galak@kernel.crashing.org>
Diffstat (limited to 'drivers/i2c')
-rw-r--r-- | drivers/i2c/busses/i2c-mpc.c | 9 |
1 files changed, 3 insertions, 6 deletions
diff --git a/drivers/i2c/busses/i2c-mpc.c b/drivers/i2c/busses/i2c-mpc.c index aedbbe6618db..3163eab3f608 100644 --- a/drivers/i2c/busses/i2c-mpc.c +++ b/drivers/i2c/busses/i2c-mpc.c | |||
@@ -70,7 +70,7 @@ static irqreturn_t mpc_i2c_isr(int irq, void *dev_id) | |||
70 | /* Read again to allow register to stabilise */ | 70 | /* Read again to allow register to stabilise */ |
71 | i2c->interrupt = readb(i2c->base + MPC_I2C_SR); | 71 | i2c->interrupt = readb(i2c->base + MPC_I2C_SR); |
72 | writeb(0, i2c->base + MPC_I2C_SR); | 72 | writeb(0, i2c->base + MPC_I2C_SR); |
73 | wake_up_interruptible(&i2c->queue); | 73 | wake_up(&i2c->queue); |
74 | } | 74 | } |
75 | return IRQ_HANDLED; | 75 | return IRQ_HANDLED; |
76 | } | 76 | } |
@@ -115,13 +115,10 @@ static int i2c_wait(struct mpc_i2c *i2c, unsigned timeout, int writing) | |||
115 | writeb(0, i2c->base + MPC_I2C_SR); | 115 | writeb(0, i2c->base + MPC_I2C_SR); |
116 | } else { | 116 | } else { |
117 | /* Interrupt mode */ | 117 | /* Interrupt mode */ |
118 | result = wait_event_interruptible_timeout(i2c->queue, | 118 | result = wait_event_timeout(i2c->queue, |
119 | (i2c->interrupt & CSR_MIF), timeout * HZ); | 119 | (i2c->interrupt & CSR_MIF), timeout * HZ); |
120 | 120 | ||
121 | if (unlikely(result < 0)) { | 121 | if (unlikely(!(i2c->interrupt & CSR_MIF))) { |
122 | pr_debug("I2C: wait interrupted\n"); | ||
123 | writeccr(i2c, 0); | ||
124 | } else if (unlikely(!(i2c->interrupt & CSR_MIF))) { | ||
125 | pr_debug("I2C: wait timeout\n"); | 122 | pr_debug("I2C: wait timeout\n"); |
126 | writeccr(i2c, 0); | 123 | writeccr(i2c, 0); |
127 | result = -ETIMEDOUT; | 124 | result = -ETIMEDOUT; |