diff options
Diffstat (limited to 'drivers/crypto/hisilicon/sec/sec_algs.c')
-rw-r--r-- | drivers/crypto/hisilicon/sec/sec_algs.c | 31 |
1 files changed, 17 insertions, 14 deletions
diff --git a/drivers/crypto/hisilicon/sec/sec_algs.c b/drivers/crypto/hisilicon/sec/sec_algs.c index f7d6d690116e..cdc4f9a171d9 100644 --- a/drivers/crypto/hisilicon/sec/sec_algs.c +++ b/drivers/crypto/hisilicon/sec/sec_algs.c | |||
@@ -732,6 +732,7 @@ static int sec_alg_skcipher_crypto(struct skcipher_request *skreq, | |||
732 | int *splits_in_nents; | 732 | int *splits_in_nents; |
733 | int *splits_out_nents = NULL; | 733 | int *splits_out_nents = NULL; |
734 | struct sec_request_el *el, *temp; | 734 | struct sec_request_el *el, *temp; |
735 | bool split = skreq->src != skreq->dst; | ||
735 | 736 | ||
736 | mutex_init(&sec_req->lock); | 737 | mutex_init(&sec_req->lock); |
737 | sec_req->req_base = &skreq->base; | 738 | sec_req->req_base = &skreq->base; |
@@ -750,7 +751,7 @@ static int sec_alg_skcipher_crypto(struct skcipher_request *skreq, | |||
750 | if (ret) | 751 | if (ret) |
751 | goto err_free_split_sizes; | 752 | goto err_free_split_sizes; |
752 | 753 | ||
753 | if (skreq->src != skreq->dst) { | 754 | if (split) { |
754 | sec_req->len_out = sg_nents(skreq->dst); | 755 | sec_req->len_out = sg_nents(skreq->dst); |
755 | ret = sec_map_and_split_sg(skreq->dst, split_sizes, steps, | 756 | ret = sec_map_and_split_sg(skreq->dst, split_sizes, steps, |
756 | &splits_out, &splits_out_nents, | 757 | &splits_out, &splits_out_nents, |
@@ -785,8 +786,9 @@ static int sec_alg_skcipher_crypto(struct skcipher_request *skreq, | |||
785 | split_sizes[i], | 786 | split_sizes[i], |
786 | skreq->src != skreq->dst, | 787 | skreq->src != skreq->dst, |
787 | splits_in[i], splits_in_nents[i], | 788 | splits_in[i], splits_in_nents[i], |
788 | splits_out[i], | 789 | split ? splits_out[i] : NULL, |
789 | splits_out_nents[i], info); | 790 | split ? splits_out_nents[i] : 0, |
791 | info); | ||
790 | if (IS_ERR(el)) { | 792 | if (IS_ERR(el)) { |
791 | ret = PTR_ERR(el); | 793 | ret = PTR_ERR(el); |
792 | goto err_free_elements; | 794 | goto err_free_elements; |
@@ -806,13 +808,6 @@ static int sec_alg_skcipher_crypto(struct skcipher_request *skreq, | |||
806 | * more refined but this is unlikely to happen so no need. | 808 | * more refined but this is unlikely to happen so no need. |
807 | */ | 809 | */ |
808 | 810 | ||
809 | /* Cleanup - all elements in pointer arrays have been coppied */ | ||
810 | kfree(splits_in_nents); | ||
811 | kfree(splits_in); | ||
812 | kfree(splits_out_nents); | ||
813 | kfree(splits_out); | ||
814 | kfree(split_sizes); | ||
815 | |||
816 | /* Grab a big lock for a long time to avoid concurrency issues */ | 811 | /* Grab a big lock for a long time to avoid concurrency issues */ |
817 | mutex_lock(&queue->queuelock); | 812 | mutex_lock(&queue->queuelock); |
818 | 813 | ||
@@ -827,13 +822,13 @@ static int sec_alg_skcipher_crypto(struct skcipher_request *skreq, | |||
827 | (!queue->havesoftqueue || | 822 | (!queue->havesoftqueue || |
828 | kfifo_avail(&queue->softqueue) > steps)) || | 823 | kfifo_avail(&queue->softqueue) > steps)) || |
829 | !list_empty(&ctx->backlog)) { | 824 | !list_empty(&ctx->backlog)) { |
825 | ret = -EBUSY; | ||
830 | if ((skreq->base.flags & CRYPTO_TFM_REQ_MAY_BACKLOG)) { | 826 | if ((skreq->base.flags & CRYPTO_TFM_REQ_MAY_BACKLOG)) { |
831 | list_add_tail(&sec_req->backlog_head, &ctx->backlog); | 827 | list_add_tail(&sec_req->backlog_head, &ctx->backlog); |
832 | mutex_unlock(&queue->queuelock); | 828 | mutex_unlock(&queue->queuelock); |
833 | return -EBUSY; | 829 | goto out; |
834 | } | 830 | } |
835 | 831 | ||
836 | ret = -EBUSY; | ||
837 | mutex_unlock(&queue->queuelock); | 832 | mutex_unlock(&queue->queuelock); |
838 | goto err_free_elements; | 833 | goto err_free_elements; |
839 | } | 834 | } |
@@ -842,7 +837,15 @@ static int sec_alg_skcipher_crypto(struct skcipher_request *skreq, | |||
842 | if (ret) | 837 | if (ret) |
843 | goto err_free_elements; | 838 | goto err_free_elements; |
844 | 839 | ||
845 | return -EINPROGRESS; | 840 | ret = -EINPROGRESS; |
841 | out: | ||
842 | /* Cleanup - all elements in pointer arrays have been copied */ | ||
843 | kfree(splits_in_nents); | ||
844 | kfree(splits_in); | ||
845 | kfree(splits_out_nents); | ||
846 | kfree(splits_out); | ||
847 | kfree(split_sizes); | ||
848 | return ret; | ||
846 | 849 | ||
847 | err_free_elements: | 850 | err_free_elements: |
848 | list_for_each_entry_safe(el, temp, &sec_req->elements, head) { | 851 | list_for_each_entry_safe(el, temp, &sec_req->elements, head) { |
@@ -854,7 +857,7 @@ err_free_elements: | |||
854 | crypto_skcipher_ivsize(atfm), | 857 | crypto_skcipher_ivsize(atfm), |
855 | DMA_BIDIRECTIONAL); | 858 | DMA_BIDIRECTIONAL); |
856 | err_unmap_out_sg: | 859 | err_unmap_out_sg: |
857 | if (skreq->src != skreq->dst) | 860 | if (split) |
858 | sec_unmap_sg_on_err(skreq->dst, steps, splits_out, | 861 | sec_unmap_sg_on_err(skreq->dst, steps, splits_out, |
859 | splits_out_nents, sec_req->len_out, | 862 | splits_out_nents, sec_req->len_out, |
860 | info->dev); | 863 | info->dev); |