Commit a5d87237bb15eed8449e5a30c0bbe626e0e7f43d
Committed by
Herbert Xu
1 parent
3e133c8bf6
Exists in
master
and in
4 other branches
crypto: omap-sham - removed redundunt locking
Locking for queuing and dequeuing is combined. test_and_set_bit() is also replaced with checking under dd->lock. Signed-off-by: Dmitry Kasatkin <dmitry.kasatkin@nokia.com> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Showing 1 changed file with 21 additions and 26 deletions Side-by-side Diff
drivers/crypto/omap-sham.c
... | ... | @@ -84,10 +84,8 @@ |
84 | 84 | #define FLAGS_CPU 0x0200 |
85 | 85 | #define FLAGS_HMAC 0x0400 |
86 | 86 | #define FLAGS_ERROR 0x0800 |
87 | +#define FLAGS_BUSY 0x1000 | |
87 | 88 | |
88 | -/* 3rd byte */ | |
89 | -#define FLAGS_BUSY 16 | |
90 | - | |
91 | 89 | #define OP_UPDATE 1 |
92 | 90 | #define OP_FINAL 2 |
93 | 91 | |
94 | 92 | |
95 | 93 | |
96 | 94 | |
97 | 95 | |
98 | 96 | |
99 | 97 | |
100 | 98 | |
... | ... | @@ -629,32 +627,37 @@ |
629 | 627 | if ((ctx->flags & FLAGS_FINAL) || err) |
630 | 628 | omap_sham_cleanup(req); |
631 | 629 | |
632 | - clear_bit(FLAGS_BUSY, &ctx->dd->flags); | |
630 | + ctx->dd->flags &= ~FLAGS_BUSY; | |
633 | 631 | |
634 | 632 | if (req->base.complete) |
635 | 633 | req->base.complete(&req->base, err); |
636 | 634 | } |
637 | 635 | |
638 | -static int omap_sham_handle_queue(struct omap_sham_dev *dd) | |
636 | +static int omap_sham_handle_queue(struct omap_sham_dev *dd, | |
637 | + struct ahash_request *req) | |
639 | 638 | { |
640 | 639 | struct crypto_async_request *async_req, *backlog; |
641 | 640 | struct omap_sham_reqctx *ctx; |
642 | - struct ahash_request *req, *prev_req; | |
641 | + struct ahash_request *prev_req; | |
643 | 642 | unsigned long flags; |
644 | - int err = 0; | |
643 | + int err = 0, ret = 0; | |
645 | 644 | |
646 | - if (test_and_set_bit(FLAGS_BUSY, &dd->flags)) | |
647 | - return 0; | |
648 | - | |
649 | 645 | spin_lock_irqsave(&dd->lock, flags); |
650 | - backlog = crypto_get_backlog(&dd->queue); | |
646 | + if (req) | |
647 | + ret = ahash_enqueue_request(&dd->queue, req); | |
648 | + if (dd->flags & FLAGS_BUSY) { | |
649 | + spin_unlock_irqrestore(&dd->lock, flags); | |
650 | + return ret; | |
651 | + } | |
651 | 652 | async_req = crypto_dequeue_request(&dd->queue); |
652 | - if (!async_req) | |
653 | - clear_bit(FLAGS_BUSY, &dd->flags); | |
653 | + if (async_req) { | |
654 | + dd->flags |= FLAGS_BUSY; | |
655 | + backlog = crypto_get_backlog(&dd->queue); | |
656 | + } | |
654 | 657 | spin_unlock_irqrestore(&dd->lock, flags); |
655 | 658 | |
656 | 659 | if (!async_req) |
657 | - return 0; | |
660 | + return ret; | |
658 | 661 | |
659 | 662 | if (backlog) |
660 | 663 | backlog->complete(backlog, -EINPROGRESS); |
... | ... | @@ -690,7 +693,7 @@ |
690 | 693 | |
691 | 694 | dev_dbg(dd->dev, "exit, err: %d\n", err); |
692 | 695 | |
693 | - return err; | |
696 | + return ret; | |
694 | 697 | } |
695 | 698 | |
696 | 699 | static int omap_sham_enqueue(struct ahash_request *req, unsigned int op) |
697 | 700 | |
... | ... | @@ -698,18 +701,10 @@ |
698 | 701 | struct omap_sham_reqctx *ctx = ahash_request_ctx(req); |
699 | 702 | struct omap_sham_ctx *tctx = crypto_tfm_ctx(req->base.tfm); |
700 | 703 | struct omap_sham_dev *dd = tctx->dd; |
701 | - unsigned long flags; | |
702 | - int err; | |
703 | 704 | |
704 | 705 | ctx->op = op; |
705 | 706 | |
706 | - spin_lock_irqsave(&dd->lock, flags); | |
707 | - err = ahash_enqueue_request(&dd->queue, req); | |
708 | - spin_unlock_irqrestore(&dd->lock, flags); | |
709 | - | |
710 | - omap_sham_handle_queue(dd); | |
711 | - | |
712 | - return err; | |
707 | + return omap_sham_handle_queue(dd, req); | |
713 | 708 | } |
714 | 709 | |
715 | 710 | static int omap_sham_update(struct ahash_request *req) |
... | ... | @@ -1041,7 +1036,7 @@ |
1041 | 1036 | /* finish curent request */ |
1042 | 1037 | omap_sham_finish_req(req, err); |
1043 | 1038 | /* start new request */ |
1044 | - omap_sham_handle_queue(dd); | |
1039 | + omap_sham_handle_queue(dd, NULL); | |
1045 | 1040 | } |
1046 | 1041 | } |
1047 | 1042 | |
... | ... | @@ -1049,7 +1044,7 @@ |
1049 | 1044 | { |
1050 | 1045 | struct omap_sham_dev *dd = (struct omap_sham_dev *)data; |
1051 | 1046 | |
1052 | - omap_sham_handle_queue(dd); | |
1047 | + omap_sham_handle_queue(dd, NULL); | |
1053 | 1048 | } |
1054 | 1049 | |
1055 | 1050 | static irqreturn_t omap_sham_irq(int irq, void *dev_id) |