crypto: caam - fix endless loop when DECO acquire fails

"Linux Kernel Mailing List" <[email protected]> Mon, 12 Feb 2018 17:22:09 +0000 (UTC)
Newsgroups gmane.linux.kernel.commits.head
Message-ID <[email protected]>
Web:        https://git.kernel.org/torvalds/c/225ece3e7dad4cfc44cca38ce7a3a80f255ea8f1
Commit:     225ece3e7dad4cfc44cca38ce7a3a80f255ea8f1
Parent:     ba916b6a0339ed6cc6441ad83c097ab795dbdbc5
Refname:    refs/heads/master
Author:     Horia Geantă <[email protected]>
AuthorDate: Mon Feb 5 11:15:52 2018 +0200
Committer:  Herbert Xu <[email protected]>
CommitDate: Thu Feb 8 22:38:13 2018 +1100

    crypto: caam - fix endless loop when DECO acquire fails
    
    In case DECO0 cannot be acquired - i.e. run_descriptor_deco0() fails
    with -ENODEV, caam_probe() enters an endless loop:
    
    run_descriptor_deco0
            ret -ENODEV
            -> instantiate_rng
                    -ENODEV, overwritten by -EAGAIN
                    ret -EAGAIN
                    -> caam_probe
                            -EAGAIN results in endless loop
    
    It turns out the error path in instantiate_rng() is incorrect,
    the checks are done in the wrong order.
    
    Cc: <[email protected]> # 3.13+
    Fixes: 1005bccd7a4a6 ("crypto: caam - enable instantiation of all RNG4 state handles")
    Reported-by: Bryan O'Donoghue <[email protected]>
    Suggested-by: Auer Lukas <[email protected]>
    Signed-off-by: Horia Geantă <[email protected]>
    Signed-off-by: Herbert Xu <[email protected]>
---
 drivers/crypto/caam/ctrl.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/drivers/crypto/caam/ctrl.c b/drivers/crypto/caam/ctrl.c
index 75d280cb2dc0..e843cf410373 100644
--- a/drivers/crypto/caam/ctrl.c
+++ b/drivers/crypto/caam/ctrl.c
@@ -228,12 +228,16 @@ static int instantiate_rng(struct device *ctrldev, int state_handle_mask,
 		 * without any error (HW optimizations for later
 		 * CAAM eras), then try again.
 		 */
+		if (ret)
+			break;
+
 		rdsta_val = rd_reg32(&ctrl->r4tst[0].rdsta) & RDSTA_IFMASK;
 		if ((status && status != JRSTA_SSRC_JUMP_HALT_CC) ||
-		    !(rdsta_val & (1 << sh_idx)))
+		    !(rdsta_val & (1 << sh_idx))) {
 			ret = -EAGAIN;
-		if (ret)
 			break;
+		}
+
 		dev_info(ctrldev, "Instantiated RNG4 SH%d\n", sh_idx);
 		/* Clear the contents before recreating the descriptor */
 		memset(desc, 0x00, CAAM_CMD_SZ * 7);
--
To unsubscribe from this list: send the line "unsubscribe git-commits-head" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html