mirror of
git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2025-11-27 01:11:31 +00:00
crypto: atmel-sha - fix error management in atmel_sha_start()
This patch clarifies and fixes how errors should be handled by atmel_sha_start(). For update operations, the previous code wrongly assumed that (err != -EINPROGRESS) implies (err == 0). It's wrong because that doesn't take the error cases (err < 0) into account. This patch also adds many comments to detail all the possible returned values and what should be done in each case. Especially, when an error occurs, since atmel_sha_complete() has already been called, hence releasing the hardware, atmel_sha_start() must not call atmel_sha_finish_req() later otherwise atmel_sha_complete() would be called a second time. Signed-off-by: Cyrille Pitchen <cyrille.pitchen@atmel.com> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
This commit is contained in:
parent
dd3f9f40b5
commit
19998acb0f
1 changed files with 22 additions and 5 deletions
|
|
@ -1106,22 +1106,39 @@ static int atmel_sha_start(struct atmel_sha_dev *dd)
|
||||||
ctx->op, req->nbytes);
|
ctx->op, req->nbytes);
|
||||||
|
|
||||||
err = atmel_sha_hw_init(dd);
|
err = atmel_sha_hw_init(dd);
|
||||||
|
|
||||||
if (err)
|
if (err)
|
||||||
goto err1;
|
return atmel_sha_complete(dd, err);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* atmel_sha_update_req() and atmel_sha_final_req() can return either:
|
||||||
|
* -EINPROGRESS: the hardware is busy and the SHA driver will resume
|
||||||
|
* its job later in the done_task.
|
||||||
|
* This is the main path.
|
||||||
|
*
|
||||||
|
* 0: the SHA driver can continue its job then release the hardware
|
||||||
|
* later, if needed, with atmel_sha_finish_req().
|
||||||
|
* This is the alternate path.
|
||||||
|
*
|
||||||
|
* < 0: an error has occurred so atmel_sha_complete(dd, err) has already
|
||||||
|
* been called, hence the hardware has been released.
|
||||||
|
* The SHA driver must stop its job without calling
|
||||||
|
* atmel_sha_finish_req(), otherwise atmel_sha_complete() would be
|
||||||
|
* called a second time.
|
||||||
|
*
|
||||||
|
* Please note that currently, atmel_sha_final_req() never returns 0.
|
||||||
|
*/
|
||||||
|
|
||||||
dd->resume = atmel_sha_done;
|
dd->resume = atmel_sha_done;
|
||||||
if (ctx->op == SHA_OP_UPDATE) {
|
if (ctx->op == SHA_OP_UPDATE) {
|
||||||
err = atmel_sha_update_req(dd);
|
err = atmel_sha_update_req(dd);
|
||||||
if (err != -EINPROGRESS && (ctx->flags & SHA_FLAGS_FINUP))
|
if (!err && (ctx->flags & SHA_FLAGS_FINUP))
|
||||||
/* no final() after finup() */
|
/* no final() after finup() */
|
||||||
err = atmel_sha_final_req(dd);
|
err = atmel_sha_final_req(dd);
|
||||||
} else if (ctx->op == SHA_OP_FINAL) {
|
} else if (ctx->op == SHA_OP_FINAL) {
|
||||||
err = atmel_sha_final_req(dd);
|
err = atmel_sha_final_req(dd);
|
||||||
}
|
}
|
||||||
|
|
||||||
err1:
|
if (!err)
|
||||||
if (err != -EINPROGRESS)
|
|
||||||
/* done_task will not finish it, so do it here */
|
/* done_task will not finish it, so do it here */
|
||||||
atmel_sha_finish_req(req, err);
|
atmel_sha_finish_req(req, err);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue