Commit 935e99a3 authored by Horia Geanta's avatar Horia Geanta Committed by Herbert Xu

crypto: talitos - corrrectly handle zero-length assoc data

talitos does not handle well zero-length assoc data. From dmesg:
talitos ffe30000.crypto: master data transfer error
talitos ffe30000.crypto: gather return/length error

Check whether assoc data is provided by inspecting assoclen,
not assoc pointer.
This is needed in order to pass testmgr tests.
Signed-off-by: default avatarHoria Geanta <horia.geanta@freescale.com>
Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
parent 41da8b5a
...@@ -790,7 +790,7 @@ static void ipsec_esp_unmap(struct device *dev, ...@@ -790,7 +790,7 @@ static void ipsec_esp_unmap(struct device *dev,
if (edesc->assoc_chained) if (edesc->assoc_chained)
talitos_unmap_sg_chain(dev, areq->assoc, DMA_TO_DEVICE); talitos_unmap_sg_chain(dev, areq->assoc, DMA_TO_DEVICE);
else else if (areq->assoclen)
/* assoc_nents counts also for IV in non-contiguous cases */ /* assoc_nents counts also for IV in non-contiguous cases */
dma_unmap_sg(dev, areq->assoc, dma_unmap_sg(dev, areq->assoc,
edesc->assoc_nents ? edesc->assoc_nents - 1 : 1, edesc->assoc_nents ? edesc->assoc_nents - 1 : 1,
...@@ -973,7 +973,11 @@ static int ipsec_esp(struct talitos_edesc *edesc, struct aead_request *areq, ...@@ -973,7 +973,11 @@ static int ipsec_esp(struct talitos_edesc *edesc, struct aead_request *areq,
dma_sync_single_for_device(dev, edesc->dma_link_tbl, dma_sync_single_for_device(dev, edesc->dma_link_tbl,
edesc->dma_len, DMA_BIDIRECTIONAL); edesc->dma_len, DMA_BIDIRECTIONAL);
} else { } else {
to_talitos_ptr(&desc->ptr[1], sg_dma_address(areq->assoc)); if (areq->assoclen)
to_talitos_ptr(&desc->ptr[1],
sg_dma_address(areq->assoc));
else
to_talitos_ptr(&desc->ptr[1], edesc->iv_dma);
desc->ptr[1].j_extent = 0; desc->ptr[1].j_extent = 0;
} }
...@@ -1122,10 +1126,10 @@ static struct talitos_edesc *talitos_edesc_alloc(struct device *dev, ...@@ -1122,10 +1126,10 @@ static struct talitos_edesc *talitos_edesc_alloc(struct device *dev,
return ERR_PTR(-EINVAL); return ERR_PTR(-EINVAL);
} }
if (iv) if (ivsize)
iv_dma = dma_map_single(dev, iv, ivsize, DMA_TO_DEVICE); iv_dma = dma_map_single(dev, iv, ivsize, DMA_TO_DEVICE);
if (assoc) { if (assoclen) {
/* /*
* Currently it is assumed that iv is provided whenever assoc * Currently it is assumed that iv is provided whenever assoc
* is. * is.
...@@ -1173,9 +1177,16 @@ static struct talitos_edesc *talitos_edesc_alloc(struct device *dev, ...@@ -1173,9 +1177,16 @@ static struct talitos_edesc *talitos_edesc_alloc(struct device *dev,
edesc = kmalloc(alloc_len, GFP_DMA | flags); edesc = kmalloc(alloc_len, GFP_DMA | flags);
if (!edesc) { if (!edesc) {
talitos_unmap_sg_chain(dev, assoc, DMA_TO_DEVICE); if (assoc_chained)
talitos_unmap_sg_chain(dev, assoc, DMA_TO_DEVICE);
else if (assoclen)
dma_unmap_sg(dev, assoc,
assoc_nents ? assoc_nents - 1 : 1,
DMA_TO_DEVICE);
if (iv_dma) if (iv_dma)
dma_unmap_single(dev, iv_dma, ivsize, DMA_TO_DEVICE); dma_unmap_single(dev, iv_dma, ivsize, DMA_TO_DEVICE);
dev_err(dev, "could not allocate edescriptor\n"); dev_err(dev, "could not allocate edescriptor\n");
return ERR_PTR(-ENOMEM); return ERR_PTR(-ENOMEM);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment