Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

crypto: img-hash - use API helpers to setup fallback request

Rather than setting up the fallback request by hand, use
ahash_request_set_callback() and ahash_request_set_crypt() API helpers
to properly setup the new request.

This also ensures that the completion callback is properly passed down
to the fallback algorithm, which avoids a crash with async fallbacks.

Signed-off-by: Ovidiu Panait <ovidiu.panait.oss@gmail.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

authored by

Ovidiu Panait and committed by
Herbert Xu
2f0c856a c360df01

+23 -18
+23 -18
drivers/crypto/img-hash.c
··· 491 491 struct img_hash_ctx *ctx = crypto_ahash_ctx(tfm); 492 492 493 493 ahash_request_set_tfm(&rctx->fallback_req, ctx->fallback); 494 - rctx->fallback_req.base.flags = req->base.flags 495 - & CRYPTO_TFM_REQ_MAY_SLEEP; 494 + ahash_request_set_callback(&rctx->fallback_req, 495 + req->base.flags & CRYPTO_TFM_REQ_MAY_SLEEP, 496 + req->base.complete, req->base.data); 496 497 497 498 return crypto_ahash_init(&rctx->fallback_req); 498 499 } ··· 556 555 struct img_hash_ctx *ctx = crypto_ahash_ctx(tfm); 557 556 558 557 ahash_request_set_tfm(&rctx->fallback_req, ctx->fallback); 559 - rctx->fallback_req.base.flags = req->base.flags 560 - & CRYPTO_TFM_REQ_MAY_SLEEP; 561 - rctx->fallback_req.nbytes = req->nbytes; 562 - rctx->fallback_req.src = req->src; 558 + ahash_request_set_callback(&rctx->fallback_req, 559 + req->base.flags & CRYPTO_TFM_REQ_MAY_SLEEP, 560 + req->base.complete, req->base.data); 561 + ahash_request_set_crypt(&rctx->fallback_req, req->src, NULL, req->nbytes); 563 562 564 563 return crypto_ahash_update(&rctx->fallback_req); 565 564 } ··· 571 570 struct img_hash_ctx *ctx = crypto_ahash_ctx(tfm); 572 571 573 572 ahash_request_set_tfm(&rctx->fallback_req, ctx->fallback); 574 - rctx->fallback_req.base.flags = req->base.flags 575 - & CRYPTO_TFM_REQ_MAY_SLEEP; 576 - rctx->fallback_req.result = req->result; 573 + ahash_request_set_callback(&rctx->fallback_req, 574 + req->base.flags & CRYPTO_TFM_REQ_MAY_SLEEP, 575 + req->base.complete, req->base.data); 576 + ahash_request_set_crypt(&rctx->fallback_req, NULL, req->result, 0); 577 577 578 578 return crypto_ahash_final(&rctx->fallback_req); 579 579 } ··· 586 584 struct img_hash_ctx *ctx = crypto_ahash_ctx(tfm); 587 585 588 586 ahash_request_set_tfm(&rctx->fallback_req, ctx->fallback); 589 - rctx->fallback_req.base.flags = req->base.flags 590 - & CRYPTO_TFM_REQ_MAY_SLEEP; 591 - rctx->fallback_req.nbytes = req->nbytes; 592 - rctx->fallback_req.src = req->src; 593 - rctx->fallback_req.result = req->result; 587 + ahash_request_set_callback(&rctx->fallback_req, 588 + req->base.flags & CRYPTO_TFM_REQ_MAY_SLEEP, 589 + req->base.complete, req->base.data); 590 + ahash_request_set_crypt(&rctx->fallback_req, req->src, req->result, 591 + req->nbytes); 592 + 594 593 595 594 return crypto_ahash_finup(&rctx->fallback_req); 596 595 } ··· 603 600 struct img_hash_ctx *ctx = crypto_ahash_ctx(tfm); 604 601 605 602 ahash_request_set_tfm(&rctx->fallback_req, ctx->fallback); 606 - rctx->fallback_req.base.flags = req->base.flags 607 - & CRYPTO_TFM_REQ_MAY_SLEEP; 603 + ahash_request_set_callback(&rctx->fallback_req, 604 + req->base.flags & CRYPTO_TFM_REQ_MAY_SLEEP, 605 + req->base.complete, req->base.data); 608 606 609 607 return crypto_ahash_import(&rctx->fallback_req, in); 610 608 } ··· 617 613 struct img_hash_ctx *ctx = crypto_ahash_ctx(tfm); 618 614 619 615 ahash_request_set_tfm(&rctx->fallback_req, ctx->fallback); 620 - rctx->fallback_req.base.flags = req->base.flags 621 - & CRYPTO_TFM_REQ_MAY_SLEEP; 616 + ahash_request_set_callback(&rctx->fallback_req, 617 + req->base.flags & CRYPTO_TFM_REQ_MAY_SLEEP, 618 + req->base.complete, req->base.data); 622 619 623 620 return crypto_ahash_export(&rctx->fallback_req, out); 624 621 }