Skip to content

Commit e39428d

Browse files
marckleinebuddeBen Dooks
authored andcommitted
i2c-imx: do not allow interruptions when waiting for I2C to complete
The i2c_imx_trx_complete() 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 receives a signal, the wait will be interrupted, returning an error. It is better to let the I2C operation finished before handling the signal (i.e. returning into userspace). 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: Marc Kleine-Budde <mkl@pengutronix.de> Reviewed-by: Wolfram Sang <w.sang@pengutronix.de> Signed-off-by: Ben Dooks <ben-linux@fluff.org>
1 parent c5b4afe commit e39428d

File tree

1 file changed

+3
-9
lines changed

1 file changed

+3
-9
lines changed

drivers/i2c/busses/i2c-imx.c

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -159,15 +159,9 @@ static int i2c_imx_bus_busy(struct imx_i2c_struct *i2c_imx, int for_busy)
159159

160160
static int i2c_imx_trx_complete(struct imx_i2c_struct *i2c_imx)
161161
{
162-
int result;
163-
164-
result = wait_event_interruptible_timeout(i2c_imx->queue,
165-
i2c_imx->i2csr & I2SR_IIF, HZ / 10);
162+
wait_event_timeout(i2c_imx->queue, i2c_imx->i2csr & I2SR_IIF, HZ / 10);
166163

167-
if (unlikely(result < 0)) {
168-
dev_dbg(&i2c_imx->adapter.dev, "<%s> result < 0\n", __func__);
169-
return result;
170-
} else if (unlikely(!(i2c_imx->i2csr & I2SR_IIF))) {
164+
if (unlikely(!(i2c_imx->i2csr & I2SR_IIF))) {
171165
dev_dbg(&i2c_imx->adapter.dev, "<%s> Timeout\n", __func__);
172166
return -ETIMEDOUT;
173167
}
@@ -295,7 +289,7 @@ static irqreturn_t i2c_imx_isr(int irq, void *dev_id)
295289
i2c_imx->i2csr = temp;
296290
temp &= ~I2SR_IIF;
297291
writeb(temp, i2c_imx->base + IMX_I2C_I2SR);
298-
wake_up_interruptible(&i2c_imx->queue);
292+
wake_up(&i2c_imx->queue);
299293
return IRQ_HANDLED;
300294
}
301295

0 commit comments

Comments
 (0)