Skip to content

Commit

Permalink
crypto: engine - Remove prepare/unprepare request
Browse files Browse the repository at this point in the history
The callbacks for prepare and unprepare request in crypto_engine
is superfluous.  They can be done directly from do_one_request.

Move the code into do_one_request and remove the unused callbacks.

Signed-off-by: Herbert Xu <[email protected]>
  • Loading branch information
herbertx committed Aug 18, 2023
1 parent be8b8a9 commit bcd6e41
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 47 deletions.
42 changes: 1 addition & 41 deletions crypto/crypto_engine.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,6 @@ static void crypto_finalize_request(struct crypto_engine *engine,
struct crypto_async_request *req, int err)
{
unsigned long flags;
bool finalize_req = false;
int ret;
struct crypto_engine_ctx *enginectx;

/*
* If hardware cannot enqueue more requests
Expand All @@ -38,21 +35,11 @@ static void crypto_finalize_request(struct crypto_engine *engine,
if (!engine->retry_support) {
spin_lock_irqsave(&engine->queue_lock, flags);
if (engine->cur_req == req) {
finalize_req = true;
engine->cur_req = NULL;
}
spin_unlock_irqrestore(&engine->queue_lock, flags);
}

if (finalize_req || engine->retry_support) {
enginectx = crypto_tfm_ctx(req->tfm);
if (enginectx->op.prepare_request &&
enginectx->op.unprepare_request) {
ret = enginectx->op.unprepare_request(engine, req);
if (ret)
dev_err(engine->dev, "failed to unprepare request\n");
}
}
lockdep_assert_in_softirq();
crypto_request_complete(req, err);

Expand Down Expand Up @@ -141,20 +128,12 @@ static void crypto_pump_requests(struct crypto_engine *engine,
ret = engine->prepare_crypt_hardware(engine);
if (ret) {
dev_err(engine->dev, "failed to prepare crypt hardware\n");
goto req_err_2;
goto req_err_1;
}
}

enginectx = crypto_tfm_ctx(async_req->tfm);

if (enginectx->op.prepare_request) {
ret = enginectx->op.prepare_request(engine, async_req);
if (ret) {
dev_err(engine->dev, "failed to prepare request: %d\n",
ret);
goto req_err_2;
}
}
if (!enginectx->op.do_one_request) {
dev_err(engine->dev, "failed to do request\n");
ret = -EINVAL;
Expand All @@ -177,18 +156,6 @@ static void crypto_pump_requests(struct crypto_engine *engine,
ret);
goto req_err_1;
}
/*
* If retry mechanism is supported,
* unprepare current request and
* enqueue it back into crypto-engine queue.
*/
if (enginectx->op.unprepare_request) {
ret = enginectx->op.unprepare_request(engine,
async_req);
if (ret)
dev_err(engine->dev,
"failed to unprepare request\n");
}
spin_lock_irqsave(&engine->queue_lock, flags);
/*
* If hardware was unable to execute request, enqueue it
Expand All @@ -204,13 +171,6 @@ static void crypto_pump_requests(struct crypto_engine *engine,
goto retry;

req_err_1:
if (enginectx->op.unprepare_request) {
ret = enginectx->op.unprepare_request(engine, async_req);
if (ret)
dev_err(engine->dev, "failed to unprepare request\n");
}

req_err_2:
crypto_request_complete(async_req, ret);

retry:
Expand Down
6 changes: 0 additions & 6 deletions include/crypto/engine.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,15 +78,9 @@ struct crypto_engine {

/*
* struct crypto_engine_op - crypto hardware engine operations
* @prepare_request: do some preparation if needed before handling the current request
* @unprepare_request: undo any work done by prepare_request()
* @do_one_request: do encryption for current request
*/
struct crypto_engine_op {
int (*prepare_request)(struct crypto_engine *engine,
void *areq);
int (*unprepare_request)(struct crypto_engine *engine,
void *areq);
int (*do_one_request)(struct crypto_engine *engine,
void *areq);
};
Expand Down

0 comments on commit bcd6e41

Please sign in to comment.