diff options
author | Dmitry Kasatkin <dmitry.kasatkin@nokia.com> | 2010-11-19 09:04:25 -0500 |
---|---|---|
committer | Herbert Xu <herbert@gondor.apana.org.au> | 2010-11-27 03:37:17 -0500 |
commit | a5d87237bb15eed8449e5a30c0bbe626e0e7f43d (patch) | |
tree | efa77f435272006e9ae802cf2c8d13a58997138a /drivers/crypto/omap-sham.c | |
parent | 3e133c8bf6a6723377d94bc97aa52596e49a4090 (diff) |
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>
Diffstat (limited to 'drivers/crypto/omap-sham.c')
-rw-r--r-- | drivers/crypto/omap-sham.c | 47 |
1 files changed, 21 insertions, 26 deletions
diff --git a/drivers/crypto/omap-sham.c b/drivers/crypto/omap-sham.c index db206284835a..6340c5ef4712 100644 --- a/drivers/crypto/omap-sham.c +++ b/drivers/crypto/omap-sham.c | |||
@@ -84,9 +84,7 @@ | |||
84 | #define FLAGS_CPU 0x0200 | 84 | #define FLAGS_CPU 0x0200 |
85 | #define FLAGS_HMAC 0x0400 | 85 | #define FLAGS_HMAC 0x0400 |
86 | #define FLAGS_ERROR 0x0800 | 86 | #define FLAGS_ERROR 0x0800 |
87 | 87 | #define FLAGS_BUSY 0x1000 | |
88 | /* 3rd byte */ | ||
89 | #define FLAGS_BUSY 16 | ||
90 | 88 | ||
91 | #define OP_UPDATE 1 | 89 | #define OP_UPDATE 1 |
92 | #define OP_FINAL 2 | 90 | #define OP_FINAL 2 |
@@ -629,32 +627,37 @@ static void omap_sham_finish_req(struct ahash_request *req, int err) | |||
629 | if ((ctx->flags & FLAGS_FINAL) || err) | 627 | if ((ctx->flags & FLAGS_FINAL) || err) |
630 | omap_sham_cleanup(req); | 628 | omap_sham_cleanup(req); |
631 | 629 | ||
632 | clear_bit(FLAGS_BUSY, &ctx->dd->flags); | 630 | ctx->dd->flags &= ~FLAGS_BUSY; |
633 | 631 | ||
634 | if (req->base.complete) | 632 | if (req->base.complete) |
635 | req->base.complete(&req->base, err); | 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 | struct crypto_async_request *async_req, *backlog; | 639 | struct crypto_async_request *async_req, *backlog; |
641 | struct omap_sham_reqctx *ctx; | 640 | struct omap_sham_reqctx *ctx; |
642 | struct ahash_request *req, *prev_req; | 641 | struct ahash_request *prev_req; |
643 | unsigned long flags; | 642 | unsigned long flags; |
644 | int err = 0; | 643 | int err = 0, ret = 0; |
645 | |||
646 | if (test_and_set_bit(FLAGS_BUSY, &dd->flags)) | ||
647 | return 0; | ||
648 | 644 | ||
649 | spin_lock_irqsave(&dd->lock, flags); | 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 | async_req = crypto_dequeue_request(&dd->queue); | 652 | async_req = crypto_dequeue_request(&dd->queue); |
652 | if (!async_req) | 653 | if (async_req) { |
653 | clear_bit(FLAGS_BUSY, &dd->flags); | 654 | dd->flags |= FLAGS_BUSY; |
655 | backlog = crypto_get_backlog(&dd->queue); | ||
656 | } | ||
654 | spin_unlock_irqrestore(&dd->lock, flags); | 657 | spin_unlock_irqrestore(&dd->lock, flags); |
655 | 658 | ||
656 | if (!async_req) | 659 | if (!async_req) |
657 | return 0; | 660 | return ret; |
658 | 661 | ||
659 | if (backlog) | 662 | if (backlog) |
660 | backlog->complete(backlog, -EINPROGRESS); | 663 | backlog->complete(backlog, -EINPROGRESS); |
@@ -690,7 +693,7 @@ static int omap_sham_handle_queue(struct omap_sham_dev *dd) | |||
690 | 693 | ||
691 | dev_dbg(dd->dev, "exit, err: %d\n", err); | 694 | dev_dbg(dd->dev, "exit, err: %d\n", err); |
692 | 695 | ||
693 | return err; | 696 | return ret; |
694 | } | 697 | } |
695 | 698 | ||
696 | static int omap_sham_enqueue(struct ahash_request *req, unsigned int op) | 699 | static int omap_sham_enqueue(struct ahash_request *req, unsigned int op) |
@@ -698,18 +701,10 @@ static int omap_sham_enqueue(struct ahash_request *req, unsigned int op) | |||
698 | struct omap_sham_reqctx *ctx = ahash_request_ctx(req); | 701 | struct omap_sham_reqctx *ctx = ahash_request_ctx(req); |
699 | struct omap_sham_ctx *tctx = crypto_tfm_ctx(req->base.tfm); | 702 | struct omap_sham_ctx *tctx = crypto_tfm_ctx(req->base.tfm); |
700 | struct omap_sham_dev *dd = tctx->dd; | 703 | struct omap_sham_dev *dd = tctx->dd; |
701 | unsigned long flags; | ||
702 | int err; | ||
703 | 704 | ||
704 | ctx->op = op; | 705 | ctx->op = op; |
705 | 706 | ||
706 | spin_lock_irqsave(&dd->lock, flags); | 707 | return omap_sham_handle_queue(dd, req); |
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; | ||
713 | } | 708 | } |
714 | 709 | ||
715 | static int omap_sham_update(struct ahash_request *req) | 710 | static int omap_sham_update(struct ahash_request *req) |
@@ -1041,7 +1036,7 @@ static void omap_sham_done_task(unsigned long data) | |||
1041 | /* finish curent request */ | 1036 | /* finish curent request */ |
1042 | omap_sham_finish_req(req, err); | 1037 | omap_sham_finish_req(req, err); |
1043 | /* start new request */ | 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 @@ static void omap_sham_queue_task(unsigned long data) | |||
1049 | { | 1044 | { |
1050 | struct omap_sham_dev *dd = (struct omap_sham_dev *)data; | 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 | static irqreturn_t omap_sham_irq(int irq, void *dev_id) | 1050 | static irqreturn_t omap_sham_irq(int irq, void *dev_id) |