Skip to content

Commit d4a7a0f

Browse files
Marek Vasutherbertx
Marek Vasut
authored andcommitted
crypto: hash - Simplify the ahash_finup implementation
The ahash_def_finup() can make use of the request save/restore functions, thus make it so. This simplifies the code a little and unifies the code paths. Note that the same remark about free()ing the req->priv applies here, the req->priv can only be free()'d after the original request was restored. Finally, squash a bug in the invocation of completion in the ASYNC path. In both ahash_def_finup_done{1,2}, the function areq->base.complete(X, err); was called with X=areq->base.data . This is incorrect , as X=&areq->base is the correct value. By analysis of the data structures, we see the areq is of type 'struct ahash_request' , areq->base is of type 'struct crypto_async_request' and areq->base.completion is of type crypto_completion_t, which is defined in include/linux/crypto.h as: typedef void (*crypto_completion_t)(struct crypto_async_request *req, int err); This is one lead that the X should be &areq->base . Next up, we can inspect other code which calls the completion callback to give us kind-of statistical idea of how this callback is used. We can try: $ git grep base\.complete\( drivers/crypto/ Finally, by inspecting ahash_request_set_callback() implementation defined in include/crypto/hash.h , we observe that the .data entry of 'struct crypto_async_request' is intended for arbitrary data, not for completion argument. Signed-off-by: Marek Vasut <[email protected]> Cc: David S. Miller <[email protected]> Cc: Fabio Estevam <[email protected]> Cc: Herbert Xu <[email protected]> Cc: Shawn Guo <[email protected]> Cc: Tom Lendacky <[email protected]> Signed-off-by: Herbert Xu <[email protected]>
1 parent 1ffc9fb commit d4a7a0f

File tree

1 file changed

+9
-27
lines changed

1 file changed

+9
-27
lines changed

crypto/ahash.c

+9-27
Original file line numberDiff line numberDiff line change
@@ -349,19 +349,16 @@ static void ahash_def_finup_finish2(struct ahash_request *req, int err)
349349
memcpy(priv->result, req->result,
350350
crypto_ahash_digestsize(crypto_ahash_reqtfm(req)));
351351

352-
kzfree(priv);
352+
ahash_restore_req(req);
353353
}
354354

355355
static void ahash_def_finup_done2(struct crypto_async_request *req, int err)
356356
{
357357
struct ahash_request *areq = req->data;
358-
struct ahash_request_priv *priv = areq->priv;
359-
crypto_completion_t complete = priv->complete;
360-
void *data = priv->data;
361358

362359
ahash_def_finup_finish2(areq, err);
363360

364-
complete(data, err);
361+
areq->base.complete(&areq->base, err);
365362
}
366363

367364
static int ahash_def_finup_finish1(struct ahash_request *req, int err)
@@ -381,38 +378,23 @@ static int ahash_def_finup_finish1(struct ahash_request *req, int err)
381378
static void ahash_def_finup_done1(struct crypto_async_request *req, int err)
382379
{
383380
struct ahash_request *areq = req->data;
384-
struct ahash_request_priv *priv = areq->priv;
385-
crypto_completion_t complete = priv->complete;
386-
void *data = priv->data;
387381

388382
err = ahash_def_finup_finish1(areq, err);
389383

390-
complete(data, err);
384+
areq->base.complete(&areq->base, err);
391385
}
392386

393387
static int ahash_def_finup(struct ahash_request *req)
394388
{
395389
struct crypto_ahash *tfm = crypto_ahash_reqtfm(req);
396-
unsigned long alignmask = crypto_ahash_alignmask(tfm);
397-
unsigned int ds = crypto_ahash_digestsize(tfm);
398-
struct ahash_request_priv *priv;
399-
400-
priv = kmalloc(sizeof(*priv) + ahash_align_buffer_size(ds, alignmask),
401-
(req->base.flags & CRYPTO_TFM_REQ_MAY_SLEEP) ?
402-
GFP_KERNEL : GFP_ATOMIC);
403-
if (!priv)
404-
return -ENOMEM;
405-
406-
priv->result = req->result;
407-
priv->complete = req->base.complete;
408-
priv->data = req->base.data;
390+
int err;
409391

410-
req->result = PTR_ALIGN((u8 *)priv->ubuf, alignmask + 1);
411-
req->base.complete = ahash_def_finup_done1;
412-
req->base.data = req;
413-
req->priv = priv;
392+
err = ahash_save_req(req, ahash_def_finup_done1);
393+
if (err)
394+
return err;
414395

415-
return ahash_def_finup_finish1(req, tfm->update(req));
396+
err = tfm->update(req);
397+
return ahash_def_finup_finish1(req, err);
416398
}
417399

418400
static int ahash_no_export(struct ahash_request *req, void *out)

0 commit comments

Comments
 (0)