]> git.karo-electronics.de Git - karo-tx-linux.git/commitdiff
i2c: at91: use correct length in dma_unmap_single()
authorLothar Waßmann <LW@KARO-electronics.de>
Wed, 3 Jun 2015 05:49:23 +0000 (07:49 +0200)
committerLothar Waßmann <LW@KARO-electronics.de>
Wed, 3 Jun 2015 05:49:23 +0000 (07:49 +0200)
The driver calls dma_map_single() with either 'dev->buf_len' or
'dev->buf_len - 2' as length argument, but always uses 'dev->buf_len'
in dma_unmap_single(). This produces the warning:
at91_i2c f8014000.i2c: DMA-API: device driver frees DMA memory with different size [device address=0x000000002fbf9240] [map size=20 bytes] [unmap size=22 bytes]
with CONFIG_DMA_API_DEBUG enabled.

Use dma_sg_len() as argument for dma_unmap_single() which is always
set to the correct length.

drivers/i2c/busses/i2c-at91.c

index ff23d1bdd23072c6c5cec5f690b048ae4dee0f8e..6011bd4136a452bd8c75bf03a19f5b7922b25006 100644 (file)
@@ -185,7 +185,7 @@ static void at91_twi_dma_cleanup(struct at91_twi_dev *dev)
        }
        if (dma->buf_mapped) {
                dma_unmap_single(dev->dev, sg_dma_address(&dma->sg),
-                                dev->buf_len, dma->direction);
+                               sg_dma_len(&dma->sg), dma->direction);
                dma->buf_mapped = false;
        }
 
@@ -213,7 +213,7 @@ static void at91_twi_write_data_dma_callback(void *data)
        struct at91_twi_dev *dev = (struct at91_twi_dev *)data;
 
        dma_unmap_single(dev->dev, sg_dma_address(&dev->dma.sg),
-                        dev->buf_len, DMA_TO_DEVICE);
+                       sg_dma_len(&dev->dma.sg), DMA_TO_DEVICE);
 
        at91_twi_write(dev, AT91_TWI_CR, AT91_TWI_STOP);
 }
@@ -304,7 +304,7 @@ static void at91_twi_read_data_dma_callback(void *data)
        struct at91_twi_dev *dev = (struct at91_twi_dev *)data;
 
        dma_unmap_single(dev->dev, sg_dma_address(&dev->dma.sg),
-                        dev->buf_len, DMA_FROM_DEVICE);
+                       sg_dma_len(&dev->dma.sg), DMA_FROM_DEVICE);
 
        /* The last two bytes have to be read without using dma */
        dev->buf += dev->buf_len - 2;