crypto: tegra-aes: rng: check if bsea is busy before using it
Varun Wadekar [Mon, 12 Dec 2011 07:02:36 +0000 (12:02 +0530)]
Bug 917607

Change-Id: I7497411932b6ba8c155026f1662063e87c21eb40
Signed-off-by: Varun Wadekar <vwadekar@nvidia.com>
Reviewed-on: http://git-master/r/74012
Reviewed-by: Automatic_Commit_Validation_User
Reviewed-by: Sanjay Singh Rawat <srawat@nvidia.com>

Rebase-Id: Rcecec9ae6298489313818c12688e1918c5499645

drivers/crypto/tegra-aes.c

index 3106955..13e5a43 100644 (file)
@@ -938,7 +938,6 @@ static int tegra_aes_rng_reset(struct crypto_rng *tfm, u8 *seed,
        struct tegra_aes_ctx *ctx = &rng_ctx;
        struct tegra_aes_engine *eng = NULL;
        struct tegra_aes_slot *key_slot;
-       int bsev_busy = false;
        int bsea_busy = false;
        unsigned long flags;
        struct timespec ts;
@@ -946,24 +945,21 @@ static int tegra_aes_rng_reset(struct crypto_rng *tfm, u8 *seed,
        int ret = 0;
        u8 *dt;
 
+       if (!dd)
+               return -EINVAL;
+
        if (slen < (DEFAULT_RNG_BLK_SZ + AES_KEYSIZE_128)) {
                return -ENOMEM;
        }
 
        spin_lock_irqsave(&dd->lock, flags);
-       bsev_busy = test_and_set_bit(FLAGS_BUSY, &dd->bsev.busy);
-       if (bsev_busy)
-               bsea_busy = test_and_set_bit(FLAGS_BUSY, &dd->bsea.busy);
+       bsea_busy = test_and_set_bit(FLAGS_BUSY, &dd->bsea.busy);
        spin_unlock_irqrestore(&dd->lock, flags);
 
-       if (!bsev_busy) {
-               eng = &dd->bsev;
-       } else if (!bsea_busy) {
+       if (!bsea_busy)
                eng = &dd->bsea;
-       } else {
-               dev_err(dd->dev, "%s: hardware engine is busy\n", __func__);
+       else
                return -EBUSY;
-       }
 
        ctx->eng = eng;
        dd->flags = FLAGS_ENCRYPT | FLAGS_RNG;