aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/crypto/talitos.c
diff options
context:
space:
mode:
authorHoria Geanta <horia.geanta@freescale.com>2013-11-19 07:57:49 -0500
committerHerbert Xu <herbert@gondor.apana.org.au>2013-11-28 09:25:16 -0500
commit935e99a3afda0a58c2eada0ff7c613d3844d738c (patch)
tree45fca0e326613e4ae8143c195ae00d6358d43b10 /drivers/crypto/talitos.c
parent41da8b5adba77e22584f8b45f9641504fa885308 (diff)
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: Horia Geanta <horia.geanta@freescale.com> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Diffstat (limited to 'drivers/crypto/talitos.c')
-rw-r--r--drivers/crypto/talitos.c21
1 files changed, 16 insertions, 5 deletions
diff --git a/drivers/crypto/talitos.c b/drivers/crypto/talitos.c
index 905de4427e7c..81ab42cd14b2 100644
--- a/drivers/crypto/talitos.c
+++ b/drivers/crypto/talitos.c
@@ -790,7 +790,7 @@ static void ipsec_esp_unmap(struct device *dev,
790 790
791 if (edesc->assoc_chained) 791 if (edesc->assoc_chained)
792 talitos_unmap_sg_chain(dev, areq->assoc, DMA_TO_DEVICE); 792 talitos_unmap_sg_chain(dev, areq->assoc, DMA_TO_DEVICE);
793 else 793 else if (areq->assoclen)
794 /* assoc_nents counts also for IV in non-contiguous cases */ 794 /* assoc_nents counts also for IV in non-contiguous cases */
795 dma_unmap_sg(dev, areq->assoc, 795 dma_unmap_sg(dev, areq->assoc,
796 edesc->assoc_nents ? edesc->assoc_nents - 1 : 1, 796 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 dma_sync_single_for_device(dev, edesc->dma_link_tbl, 973 dma_sync_single_for_device(dev, edesc->dma_link_tbl,
974 edesc->dma_len, DMA_BIDIRECTIONAL); 974 edesc->dma_len, DMA_BIDIRECTIONAL);
975 } else { 975 } else {
976 to_talitos_ptr(&desc->ptr[1], sg_dma_address(areq->assoc)); 976 if (areq->assoclen)
977 to_talitos_ptr(&desc->ptr[1],
978 sg_dma_address(areq->assoc));
979 else
980 to_talitos_ptr(&desc->ptr[1], edesc->iv_dma);
977 desc->ptr[1].j_extent = 0; 981 desc->ptr[1].j_extent = 0;
978 } 982 }
979 983
@@ -1122,10 +1126,10 @@ static struct talitos_edesc *talitos_edesc_alloc(struct device *dev,
1122 return ERR_PTR(-EINVAL); 1126 return ERR_PTR(-EINVAL);
1123 } 1127 }
1124 1128
1125 if (iv) 1129 if (ivsize)
1126 iv_dma = dma_map_single(dev, iv, ivsize, DMA_TO_DEVICE); 1130 iv_dma = dma_map_single(dev, iv, ivsize, DMA_TO_DEVICE);
1127 1131
1128 if (assoc) { 1132 if (assoclen) {
1129 /* 1133 /*
1130 * Currently it is assumed that iv is provided whenever assoc 1134 * Currently it is assumed that iv is provided whenever assoc
1131 * is. 1135 * is.
@@ -1173,9 +1177,16 @@ static struct talitos_edesc *talitos_edesc_alloc(struct device *dev,
1173 1177
1174 edesc = kmalloc(alloc_len, GFP_DMA | flags); 1178 edesc = kmalloc(alloc_len, GFP_DMA | flags);
1175 if (!edesc) { 1179 if (!edesc) {
1176 talitos_unmap_sg_chain(dev, assoc, DMA_TO_DEVICE); 1180 if (assoc_chained)
1181 talitos_unmap_sg_chain(dev, assoc, DMA_TO_DEVICE);
1182 else if (assoclen)
1183 dma_unmap_sg(dev, assoc,
1184 assoc_nents ? assoc_nents - 1 : 1,
1185 DMA_TO_DEVICE);
1186
1177 if (iv_dma) 1187 if (iv_dma)
1178 dma_unmap_single(dev, iv_dma, ivsize, DMA_TO_DEVICE); 1188 dma_unmap_single(dev, iv_dma, ivsize, DMA_TO_DEVICE);
1189
1179 dev_err(dev, "could not allocate edescriptor\n"); 1190 dev_err(dev, "could not allocate edescriptor\n");
1180 return ERR_PTR(-ENOMEM); 1191 return ERR_PTR(-ENOMEM);
1181 } 1192 }