Skip to content

Commit 03fbb90

Browse files
mwallewsakernel
authored andcommitted
i2c: at91: use dma safe buffers
The supplied buffer might be on the stack and we get the following error message: [ 3.312058] at91_i2c e0070600.i2c: rejecting DMA map of vmalloc memory Use i2c_{get,put}_dma_safe_msg_buf() to get a DMA-able memory region if necessary. Fixes: 60937b2 ("i2c: at91: add dma support") Signed-off-by: Michael Walle <michael@walle.cc> Reviewed-by: Codrin Ciubotariu <codrin.ciubotariu@microchip.com> Signed-off-by: Wolfram Sang <wsa@kernel.org>
1 parent 8b4fc24 commit 03fbb90

1 file changed

Lines changed: 11 additions & 0 deletions

File tree

drivers/i2c/busses/i2c-at91-master.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -656,6 +656,7 @@ static int at91_twi_xfer(struct i2c_adapter *adap, struct i2c_msg *msg, int num)
656656
unsigned int_addr_flag = 0;
657657
struct i2c_msg *m_start = msg;
658658
bool is_read;
659+
u8 *dma_buf;
659660

660661
dev_dbg(&adap->dev, "at91_xfer: processing %d messages:\n", num);
661662

@@ -703,7 +704,17 @@ static int at91_twi_xfer(struct i2c_adapter *adap, struct i2c_msg *msg, int num)
703704
dev->msg = m_start;
704705
dev->recv_len_abort = false;
705706

707+
if (dev->use_dma) {
708+
dma_buf = i2c_get_dma_safe_msg_buf(m_start, 1);
709+
if (!dma_buf) {
710+
ret = -ENOMEM;
711+
goto out;
712+
}
713+
dev->buf = dma_buf;
714+
}
715+
706716
ret = at91_do_twi_transfer(dev);
717+
i2c_put_dma_safe_msg_buf(dma_buf, m_start, !ret);
707718

708719
ret = (ret < 0) ? ret : num;
709720
out:

0 commit comments

Comments
 (0)