MLK-22039: crypto: caam - print debugging hex dumps after unmapping
authorSascha Hauer <s.hauer@pengutronix.de>
Thu, 16 May 2019 14:24:42 +0000 (16:24 +0200)
committerHoria Geantă <horia.geanta@nxp.com>
Fri, 5 Jul 2019 14:59:52 +0000 (17:59 +0300)
For encryption the destination pointer was still mapped, so the hex dump
may be wrong. The IV still contained the input IV while printing instead
of the output IV as intended.

For decryption the destination pointer was still mapped, so the hex dump
may be wrong. The IV dump was correct.

Do the hex dumps consistenly after the buffers have been unmapped and
in case of IV copied to their final destination.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Reviewed-by: Horia Geantă <horia.geanta@nxp.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
(cherry picked from commit bb992bc418e12d4658d39e037f610e0d03940d86)

backported to imx_4.19.y

Signed-off-by: Horia Geantă <horia.geanta@nxp.com>
Reviewed-by: Iuliana Prodan <iuliana.prodan@nxp.com>
drivers/crypto/caam/caamalg.c

index 4a8bea7..42d768d 100644 (file)
@@ -1002,15 +1002,6 @@ static void ablkcipher_encrypt_done(struct device *jrdev, u32 *desc, u32 err,
        if (err)
                caam_jr_strstatus(jrdev, err);
 
-#ifdef DEBUG
-       print_hex_dump(KERN_ERR, "dstiv  @"__stringify(__LINE__)": ",
-                      DUMP_PREFIX_ADDRESS, 16, 4, req->info,
-                      edesc->src_nents > 1 ? 100 : ivsize, 1);
-#endif
-       caam_dump_sg(KERN_ERR, "dst    @" __stringify(__LINE__)": ",
-                    DUMP_PREFIX_ADDRESS, 16, 4, req->dst,
-                    edesc->dst_nents > 1 ? 100 : req->nbytes, 1);
-
        ablkcipher_unmap(jrdev, edesc, req);
 
        /*
@@ -1021,6 +1012,15 @@ static void ablkcipher_encrypt_done(struct device *jrdev, u32 *desc, u32 err,
                scatterwalk_map_and_copy(req->info, req->dst, req->nbytes -
                                         ivsize, ivsize, 0);
 
+#ifdef DEBUG
+       print_hex_dump(KERN_ERR, "dstiv  @"__stringify(__LINE__)": ",
+                      DUMP_PREFIX_ADDRESS, 16, 4, req->info,
+                      edesc->src_nents > 1 ? 100 : ivsize, 1);
+#endif
+       caam_dump_sg(KERN_ERR, "dst    @" __stringify(__LINE__)": ",
+                    DUMP_PREFIX_ADDRESS, 16, 4, req->dst,
+                    edesc->dst_nents > 1 ? 100 : req->nbytes, 1);
+
        /* In case initial IV was generated, copy it in GIVCIPHER request */
        if (edesc->iv_dir == DMA_FROM_DEVICE) {
                u8 *iv;
@@ -1054,6 +1054,8 @@ static void ablkcipher_decrypt_done(struct device *jrdev, u32 *desc, u32 err,
        if (err)
                caam_jr_strstatus(jrdev, err);
 
+       ablkcipher_unmap(jrdev, edesc, req);
+
 #ifdef DEBUG
        print_hex_dump(KERN_ERR, "dstiv  @"__stringify(__LINE__)": ",
                       DUMP_PREFIX_ADDRESS, 16, 4, req->info,
@@ -1063,7 +1065,6 @@ static void ablkcipher_decrypt_done(struct device *jrdev, u32 *desc, u32 err,
                     DUMP_PREFIX_ADDRESS, 16, 4, req->dst,
                     edesc->dst_nents > 1 ? 100 : req->nbytes, 1);
 
-       ablkcipher_unmap(jrdev, edesc, req);
        kfree(edesc);
 
        ablkcipher_request_complete(req, err);