Skip to content

Commit

Permalink
crypto: stm32/cryp - remove request mutex protection
Browse files Browse the repository at this point in the history
Mutex is badly used between threaded irq and driver.
This mutex must be removed as the framework must ensure
that requests must be serialized to avoid issue. Rework
req to avoid crash during finalize by fixing the NULL
pointer issue.

Change-Id: I66bf6817336425ff70ce3efb8f48658b1e63e010
Signed-off-by: Lionel Debieve <lionel.debieve@st.com>
Reviewed-on: https://gerrit.st.com/c/mpu/oe/st/linux-stm32/+/129120
Reviewed-by: CITOOLS <smet-aci-reviews@lists.codex.cro.st.com>
Reviewed-by: CIBUILD <smet-aci-builds@lists.codex.cro.st.com>
Reviewed-by: Fabien DESSENNE <fabien.dessenne@st.com>
  • Loading branch information
ldebieve authored and ADESTM committed Apr 12, 2019
1 parent 6f9a2f5 commit 76f4f3e
Showing 1 changed file with 7 additions and 19 deletions.
26 changes: 7 additions & 19 deletions drivers/crypto/stm32/stm32-cryp.c
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,6 @@ struct stm32_cryp {

struct crypto_engine *engine;

struct mutex lock; /* protects req / areq */
struct ablkcipher_request *req;
struct aead_request *areq;

Expand Down Expand Up @@ -645,18 +644,13 @@ static void stm32_cryp_finish_req(struct stm32_cryp *cryp, int err)
pm_runtime_mark_last_busy(cryp->dev);
pm_runtime_put_autosuspend(cryp->dev);

if (is_gcm(cryp) || is_ccm(cryp)) {
if (is_gcm(cryp) || is_ccm(cryp))
crypto_finalize_aead_request(cryp->engine, cryp->areq, err);
cryp->areq = NULL;
} else {
else
crypto_finalize_ablkcipher_request(cryp->engine, cryp->req,
err);
cryp->req = NULL;
}

memset(cryp->ctx->key, 0, cryp->ctx->keylen);

mutex_unlock(&cryp->lock);
}

static int stm32_cryp_cpu_start(struct stm32_cryp *cryp)
Expand Down Expand Up @@ -935,8 +929,6 @@ static int stm32_cryp_prepare_req(struct ablkcipher_request *req,
if (!cryp)
return -ENODEV;

mutex_lock(&cryp->lock);

rctx = req ? ablkcipher_request_ctx(req) : aead_request_ctx(areq);
rctx->mode &= FLG_MODE_MASK;

Expand All @@ -948,6 +940,7 @@ static int stm32_cryp_prepare_req(struct ablkcipher_request *req,

if (req) {
cryp->req = req;
cryp->areq = NULL;
cryp->total_in = req->nbytes;
cryp->total_out = cryp->total_in;
} else {
Expand All @@ -973,6 +966,7 @@ static int stm32_cryp_prepare_req(struct ablkcipher_request *req,
* <---------- total_out ----------------->
*/
cryp->areq = areq;
cryp->req = NULL;
cryp->authsize = crypto_aead_authsize(crypto_aead_reqtfm(areq));
cryp->total_in = areq->assoclen + areq->cryptlen;
if (is_encrypt(cryp))
Expand All @@ -994,19 +988,19 @@ static int stm32_cryp_prepare_req(struct ablkcipher_request *req,
if (cryp->in_sg_len < 0) {
dev_err(cryp->dev, "Cannot get in_sg_len\n");
ret = cryp->in_sg_len;
goto out;
return ret;
}

cryp->out_sg_len = sg_nents_for_len(cryp->out_sg, cryp->total_out);
if (cryp->out_sg_len < 0) {
dev_err(cryp->dev, "Cannot get out_sg_len\n");
ret = cryp->out_sg_len;
goto out;
return ret;
}

ret = stm32_cryp_copy_sgs(cryp);
if (ret)
goto out;
return ret;

scatterwalk_start(&cryp->in_walk, cryp->in_sg);
scatterwalk_start(&cryp->out_walk, cryp->out_sg);
Expand All @@ -1018,10 +1012,6 @@ static int stm32_cryp_prepare_req(struct ablkcipher_request *req,
}

ret = stm32_cryp_hw_init(cryp);
out:
if (ret)
mutex_unlock(&cryp->lock);

return ret;
}

Expand Down Expand Up @@ -1961,8 +1951,6 @@ static int stm32_cryp_probe(struct platform_device *pdev)

cryp->dev = dev;

mutex_init(&cryp->lock);

res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
cryp->regs = devm_ioremap_resource(dev, res);
if (IS_ERR(cryp->regs))
Expand Down

0 comments on commit 76f4f3e

Please sign in to comment.