Skip to content

Commit b745ab7

Browse files
ovpanaitherbertx
authored andcommitted
crypto: sun8i-ce-hash - factor out debugfs fallback statistics
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>
1 parent d68c4a7 commit b745ab7

1 file changed

Lines changed: 20 additions & 33 deletions

File tree

drivers/crypto/allwinner/sun8i-ce/sun8i-ce-hash.c

Lines changed: 20 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,20 @@
2323
#include <linux/string.h>
2424
#include "sun8i-ce.h"
2525

26+
static void sun8i_ce_hash_stat_fb_inc(struct crypto_ahash *tfm)
27+
{
28+
if (IS_ENABLED(CONFIG_CRYPTO_DEV_SUN8I_CE_DEBUG)) {
29+
struct sun8i_ce_alg_template *algt __maybe_unused;
30+
struct ahash_alg *alg = crypto_ahash_alg(tfm);
31+
32+
algt = container_of(alg, struct sun8i_ce_alg_template,
33+
alg.hash.base);
34+
#ifdef CONFIG_CRYPTO_DEV_SUN8I_CE_DEBUG
35+
algt->stat_fb++;
36+
#endif
37+
}
38+
}
39+
2640
int sun8i_ce_hash_init_tfm(struct crypto_ahash *tfm)
2741
{
2842
struct sun8i_ce_hash_tfm_ctx *op = crypto_ahash_ctx(tfm);
@@ -113,22 +127,13 @@ int sun8i_ce_hash_final(struct ahash_request *areq)
113127
struct crypto_ahash *tfm = crypto_ahash_reqtfm(areq);
114128
struct sun8i_ce_hash_tfm_ctx *tfmctx = crypto_ahash_ctx(tfm);
115129

130+
sun8i_ce_hash_stat_fb_inc(tfm);
131+
116132
ahash_request_set_tfm(&rctx->fallback_req, tfmctx->fallback_tfm);
117133
rctx->fallback_req.base.flags = areq->base.flags &
118134
CRYPTO_TFM_REQ_MAY_SLEEP;
119135
rctx->fallback_req.result = areq->result;
120136

121-
if (IS_ENABLED(CONFIG_CRYPTO_DEV_SUN8I_CE_DEBUG)) {
122-
struct sun8i_ce_alg_template *algt __maybe_unused;
123-
struct ahash_alg *alg = crypto_ahash_alg(tfm);
124-
125-
algt = container_of(alg, struct sun8i_ce_alg_template,
126-
alg.hash.base);
127-
#ifdef CONFIG_CRYPTO_DEV_SUN8I_CE_DEBUG
128-
algt->stat_fb++;
129-
#endif
130-
}
131-
132137
return crypto_ahash_final(&rctx->fallback_req);
133138
}
134139

@@ -153,6 +158,8 @@ int sun8i_ce_hash_finup(struct ahash_request *areq)
153158
struct crypto_ahash *tfm = crypto_ahash_reqtfm(areq);
154159
struct sun8i_ce_hash_tfm_ctx *tfmctx = crypto_ahash_ctx(tfm);
155160

161+
sun8i_ce_hash_stat_fb_inc(tfm);
162+
156163
ahash_request_set_tfm(&rctx->fallback_req, tfmctx->fallback_tfm);
157164
rctx->fallback_req.base.flags = areq->base.flags &
158165
CRYPTO_TFM_REQ_MAY_SLEEP;
@@ -161,17 +168,6 @@ int sun8i_ce_hash_finup(struct ahash_request *areq)
161168
rctx->fallback_req.src = areq->src;
162169
rctx->fallback_req.result = areq->result;
163170

164-
if (IS_ENABLED(CONFIG_CRYPTO_DEV_SUN8I_CE_DEBUG)) {
165-
struct sun8i_ce_alg_template *algt __maybe_unused;
166-
struct ahash_alg *alg = crypto_ahash_alg(tfm);
167-
168-
algt = container_of(alg, struct sun8i_ce_alg_template,
169-
alg.hash.base);
170-
#ifdef CONFIG_CRYPTO_DEV_SUN8I_CE_DEBUG
171-
algt->stat_fb++;
172-
#endif
173-
}
174-
175171
return crypto_ahash_finup(&rctx->fallback_req);
176172
}
177173

@@ -181,6 +177,8 @@ static int sun8i_ce_hash_digest_fb(struct ahash_request *areq)
181177
struct crypto_ahash *tfm = crypto_ahash_reqtfm(areq);
182178
struct sun8i_ce_hash_tfm_ctx *tfmctx = crypto_ahash_ctx(tfm);
183179

180+
sun8i_ce_hash_stat_fb_inc(tfm);
181+
184182
ahash_request_set_tfm(&rctx->fallback_req, tfmctx->fallback_tfm);
185183
rctx->fallback_req.base.flags = areq->base.flags &
186184
CRYPTO_TFM_REQ_MAY_SLEEP;
@@ -189,17 +187,6 @@ static int sun8i_ce_hash_digest_fb(struct ahash_request *areq)
189187
rctx->fallback_req.src = areq->src;
190188
rctx->fallback_req.result = areq->result;
191189

192-
if (IS_ENABLED(CONFIG_CRYPTO_DEV_SUN8I_CE_DEBUG)) {
193-
struct sun8i_ce_alg_template *algt __maybe_unused;
194-
struct ahash_alg *alg = crypto_ahash_alg(tfm);
195-
196-
algt = container_of(alg, struct sun8i_ce_alg_template,
197-
alg.hash.base);
198-
#ifdef CONFIG_CRYPTO_DEV_SUN8I_CE_DEBUG
199-
algt->stat_fb++;
200-
#endif
201-
}
202-
203190
return crypto_ahash_digest(&rctx->fallback_req);
204191
}
205192

0 commit comments

Comments
 (0)