Merge git://git.kernel.org/pub/scm/linux/kernel/git/herbert/crypto-2.6

* git://git.kernel.org/pub/scm/linux/kernel/git/herbert/crypto-2.6:
crypto: talitos - sparse fix
crypto: talitos - Stop leaking memory in error path
crypto: talitos - Fix GFP flag usage
crypto: talitos - Preempt overflow interrupts
crypto: talitos - Correct dst != src case handling
crypto: talitos - Remove calls to of_node_put

+34 -15
+34 -15
drivers/crypto/talitos.c
··· 99 99 /* next channel to be assigned next incoming descriptor */ 100 100 atomic_t last_chan; 101 101 102 + /* per-channel number of requests pending in channel h/w fifo */ 103 + atomic_t *submit_count; 104 + 102 105 /* per-channel request fifo */ 103 106 struct talitos_request **fifo; 104 107 ··· 266 263 267 264 spin_lock_irqsave(&priv->head_lock[ch], flags); 268 265 269 - head = priv->head[ch]; 270 - request = &priv->fifo[ch][head]; 271 - 272 - if (request->desc) { 273 - /* request queue is full */ 266 + if (!atomic_inc_not_zero(&priv->submit_count[ch])) { 267 + /* h/w fifo is full */ 274 268 spin_unlock_irqrestore(&priv->head_lock[ch], flags); 275 269 return -EAGAIN; 276 270 } 271 + 272 + head = priv->head[ch]; 273 + request = &priv->fifo[ch][head]; 277 274 278 275 /* map descriptor and save caller data */ 279 276 request->dma_desc = dma_map_single(dev, desc, sizeof(*desc), ··· 338 335 priv->tail[ch] = (tail + 1) & (priv->fifo_len - 1); 339 336 340 337 spin_unlock_irqrestore(&priv->tail_lock[ch], flags); 338 + 339 + atomic_dec(&priv->submit_count[ch]); 340 + 341 341 saved_req.callback(dev, saved_req.desc, saved_req.context, 342 342 status); 343 343 /* channel may resume processing in single desc error case */ ··· 848 842 849 843 /* adjust (decrease) last one (or two) entry's len to cryptlen */ 850 844 link_tbl_ptr--; 851 - while (link_tbl_ptr->len <= (-cryptlen)) { 845 + while (be16_to_cpu(link_tbl_ptr->len) <= (-cryptlen)) { 852 846 /* Empty this entry, and move to previous one */ 853 847 cryptlen += be16_to_cpu(link_tbl_ptr->len); 854 848 link_tbl_ptr->len = 0; ··· 880 874 unsigned int cryptlen = areq->cryptlen; 881 875 unsigned int authsize = ctx->authsize; 882 876 unsigned int ivsize; 883 - int sg_count; 877 + int sg_count, ret; 884 878 885 879 /* hmac key */ 886 880 map_single_talitos_ptr(dev, &desc->ptr[0], ctx->authkeylen, &ctx->key, ··· 984 978 map_single_talitos_ptr(dev, &desc->ptr[6], ivsize, ctx->iv, 0, 985 979 DMA_FROM_DEVICE); 986 980 987 - return talitos_submit(dev, desc, callback, areq); 981 + ret = talitos_submit(dev, desc, callback, areq); 982 + if (ret != -EINPROGRESS) { 983 + ipsec_esp_unmap(dev, edesc, areq); 984 + kfree(edesc); 985 + } 986 + return ret; 988 987 } 989 988 990 989 ··· 1020 1009 struct talitos_ctx *ctx = crypto_aead_ctx(authenc); 1021 1010 struct ipsec_esp_edesc *edesc; 1022 1011 int src_nents, dst_nents, alloc_len, dma_len; 1012 + gfp_t flags = areq->base.flags & CRYPTO_TFM_REQ_MAY_SLEEP ? GFP_KERNEL : 1013 + GFP_ATOMIC; 1023 1014 1024 1015 if (areq->cryptlen + ctx->authsize > TALITOS_MAX_DATA_LEN) { 1025 1016 dev_err(ctx->dev, "cryptlen exceeds h/w max limit\n"); ··· 1035 1022 dst_nents = src_nents; 1036 1023 } else { 1037 1024 dst_nents = sg_count(areq->dst, areq->cryptlen + ctx->authsize); 1038 - dst_nents = (dst_nents == 1) ? 0 : src_nents; 1025 + dst_nents = (dst_nents == 1) ? 0 : dst_nents; 1039 1026 } 1040 1027 1041 1028 /* ··· 1053 1040 alloc_len += icv_stashing ? ctx->authsize : 0; 1054 1041 } 1055 1042 1056 - edesc = kmalloc(alloc_len, GFP_DMA); 1043 + edesc = kmalloc(alloc_len, GFP_DMA | flags); 1057 1044 if (!edesc) { 1058 1045 dev_err(ctx->dev, "could not allocate edescriptor\n"); 1059 1046 return ERR_PTR(-ENOMEM); ··· 1350 1337 if (hw_supports(dev, DESC_HDR_SEL0_RNG)) 1351 1338 talitos_unregister_rng(dev); 1352 1339 1340 + kfree(priv->submit_count); 1353 1341 kfree(priv->tail); 1354 1342 kfree(priv->head); 1355 1343 ··· 1480 1466 goto err_out; 1481 1467 } 1482 1468 1483 - of_node_put(np); 1484 - np = NULL; 1485 - 1486 1469 priv->head_lock = kmalloc(sizeof(spinlock_t) * priv->num_channels, 1487 1470 GFP_KERNEL); 1488 1471 priv->tail_lock = kmalloc(sizeof(spinlock_t) * priv->num_channels, ··· 1514 1503 goto err_out; 1515 1504 } 1516 1505 } 1506 + 1507 + priv->submit_count = kmalloc(sizeof(atomic_t) * priv->num_channels, 1508 + GFP_KERNEL); 1509 + if (!priv->submit_count) { 1510 + dev_err(dev, "failed to allocate fifo submit count space\n"); 1511 + err = -ENOMEM; 1512 + goto err_out; 1513 + } 1514 + for (i = 0; i < priv->num_channels; i++) 1515 + atomic_set(&priv->submit_count[i], -priv->chfifo_len); 1517 1516 1518 1517 priv->head = kzalloc(sizeof(int) * priv->num_channels, GFP_KERNEL); 1519 1518 priv->tail = kzalloc(sizeof(int) * priv->num_channels, GFP_KERNEL); ··· 1580 1559 1581 1560 err_out: 1582 1561 talitos_remove(ofdev); 1583 - if (np) 1584 - of_node_put(np); 1585 1562 1586 1563 return err; 1587 1564 }