crypto: sun8i-ce-hash - factor out debugfs fallback statistics
authorOvidiu Panait <ovidiu.panait.oss@gmail.com>
Tue, 1 Apr 2025 19:23:18 +0000 (22:23 +0300)
committerHerbert Xu <herbert@gondor.apana.org.au>
Tue, 8 Apr 2025 07:54:38 +0000 (15:54 +0800)
In order to reduce code duplication, factor out to a separate function
the codepath that increments debugfs fallback stats.

Signed-off-by: Ovidiu Panait <ovidiu.panait.oss@gmail.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
drivers/crypto/allwinner/sun8i-ce/sun8i-ce-hash.c

index 2c2d285de154eb1d58c6ca5df58f17999f6fe3b0..b0959d8218cb43ed6a69f6b32ee9ec989b9ce950 100644 (file)
 #include <linux/string.h>
 #include "sun8i-ce.h"
 
+static void sun8i_ce_hash_stat_fb_inc(struct crypto_ahash *tfm)
+{
+       if (IS_ENABLED(CONFIG_CRYPTO_DEV_SUN8I_CE_DEBUG)) {
+               struct sun8i_ce_alg_template *algt __maybe_unused;
+               struct ahash_alg *alg = crypto_ahash_alg(tfm);
+
+               algt = container_of(alg, struct sun8i_ce_alg_template,
+                                   alg.hash.base);
+#ifdef CONFIG_CRYPTO_DEV_SUN8I_CE_DEBUG
+               algt->stat_fb++;
+#endif
+       }
+}
+
 int sun8i_ce_hash_init_tfm(struct crypto_ahash *tfm)
 {
        struct sun8i_ce_hash_tfm_ctx *op = crypto_ahash_ctx(tfm);
@@ -113,22 +127,13 @@ int sun8i_ce_hash_final(struct ahash_request *areq)
        struct crypto_ahash *tfm = crypto_ahash_reqtfm(areq);
        struct sun8i_ce_hash_tfm_ctx *tfmctx = crypto_ahash_ctx(tfm);
 
+       sun8i_ce_hash_stat_fb_inc(tfm);
+
        ahash_request_set_tfm(&rctx->fallback_req, tfmctx->fallback_tfm);
        rctx->fallback_req.base.flags = areq->base.flags &
                                        CRYPTO_TFM_REQ_MAY_SLEEP;
        rctx->fallback_req.result = areq->result;
 
-       if (IS_ENABLED(CONFIG_CRYPTO_DEV_SUN8I_CE_DEBUG)) {
-               struct sun8i_ce_alg_template *algt __maybe_unused;
-               struct ahash_alg *alg = crypto_ahash_alg(tfm);
-
-               algt = container_of(alg, struct sun8i_ce_alg_template,
-                                   alg.hash.base);
-#ifdef CONFIG_CRYPTO_DEV_SUN8I_CE_DEBUG
-               algt->stat_fb++;
-#endif
-       }
-
        return crypto_ahash_final(&rctx->fallback_req);
 }
 
@@ -153,6 +158,8 @@ int sun8i_ce_hash_finup(struct ahash_request *areq)
        struct crypto_ahash *tfm = crypto_ahash_reqtfm(areq);
        struct sun8i_ce_hash_tfm_ctx *tfmctx = crypto_ahash_ctx(tfm);
 
+       sun8i_ce_hash_stat_fb_inc(tfm);
+
        ahash_request_set_tfm(&rctx->fallback_req, tfmctx->fallback_tfm);
        rctx->fallback_req.base.flags = areq->base.flags &
                                        CRYPTO_TFM_REQ_MAY_SLEEP;
@@ -161,17 +168,6 @@ int sun8i_ce_hash_finup(struct ahash_request *areq)
        rctx->fallback_req.src = areq->src;
        rctx->fallback_req.result = areq->result;
 
-       if (IS_ENABLED(CONFIG_CRYPTO_DEV_SUN8I_CE_DEBUG)) {
-               struct sun8i_ce_alg_template *algt __maybe_unused;
-               struct ahash_alg *alg = crypto_ahash_alg(tfm);
-
-               algt = container_of(alg, struct sun8i_ce_alg_template,
-                                   alg.hash.base);
-#ifdef CONFIG_CRYPTO_DEV_SUN8I_CE_DEBUG
-               algt->stat_fb++;
-#endif
-       }
-
        return crypto_ahash_finup(&rctx->fallback_req);
 }
 
@@ -181,6 +177,8 @@ static int sun8i_ce_hash_digest_fb(struct ahash_request *areq)
        struct crypto_ahash *tfm = crypto_ahash_reqtfm(areq);
        struct sun8i_ce_hash_tfm_ctx *tfmctx = crypto_ahash_ctx(tfm);
 
+       sun8i_ce_hash_stat_fb_inc(tfm);
+
        ahash_request_set_tfm(&rctx->fallback_req, tfmctx->fallback_tfm);
        rctx->fallback_req.base.flags = areq->base.flags &
                                        CRYPTO_TFM_REQ_MAY_SLEEP;
@@ -189,17 +187,6 @@ static int sun8i_ce_hash_digest_fb(struct ahash_request *areq)
        rctx->fallback_req.src = areq->src;
        rctx->fallback_req.result = areq->result;
 
-       if (IS_ENABLED(CONFIG_CRYPTO_DEV_SUN8I_CE_DEBUG)) {
-               struct sun8i_ce_alg_template *algt __maybe_unused;
-               struct ahash_alg *alg = crypto_ahash_alg(tfm);
-
-               algt = container_of(alg, struct sun8i_ce_alg_template,
-                                   alg.hash.base);
-#ifdef CONFIG_CRYPTO_DEV_SUN8I_CE_DEBUG
-               algt->stat_fb++;
-#endif
-       }
-
        return crypto_ahash_digest(&rctx->fallback_req);
 }