Skip to content

Commit 3e5e470

Browse files
authored
Merge pull request #8876 from philljj/small_drbg_cleanup
linuxkm drbg: refactor drbg_ctx clear.
2 parents 842e236 + 4196575 commit 3e5e470

1 file changed

Lines changed: 18 additions & 15 deletions

File tree

linuxkm/lkcapi_sha_glue.c

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -946,6 +946,22 @@ struct wc_linuxkm_drbg_ctx {
946946
} *rngs; /* one per CPU ID */
947947
};
948948

949+
static inline void wc_linuxkm_drbg_ctx_clear(struct wc_linuxkm_drbg_ctx * ctx)
950+
{
951+
unsigned int i;
952+
953+
if (ctx->rngs) {
954+
for (i = 0; i < nr_cpu_ids; ++i) {
955+
(void)wc_FreeMutex(&ctx->rngs[i].lock);
956+
wc_FreeRng(&ctx->rngs[i].rng);
957+
}
958+
free(ctx->rngs);
959+
ctx->rngs = NULL;
960+
}
961+
962+
return;
963+
}
964+
949965
static int wc_linuxkm_drbg_init_tfm(struct crypto_tfm *tfm)
950966
{
951967
struct wc_linuxkm_drbg_ctx *ctx = (struct wc_linuxkm_drbg_ctx *)crypto_tfm_ctx(tfm);
@@ -975,12 +991,7 @@ static int wc_linuxkm_drbg_init_tfm(struct crypto_tfm *tfm)
975991
}
976992

977993
if (ret != 0) {
978-
for (i = 0; i < nr_cpu_ids; ++i) {
979-
(void)wc_FreeMutex(&ctx->rngs[i].lock);
980-
wc_FreeRng(&ctx->rngs[i].rng);
981-
}
982-
free(ctx->rngs);
983-
ctx->rngs = NULL;
994+
wc_linuxkm_drbg_ctx_clear(ctx);
984995
}
985996

986997
return ret;
@@ -989,16 +1000,8 @@ static int wc_linuxkm_drbg_init_tfm(struct crypto_tfm *tfm)
9891000
static void wc_linuxkm_drbg_exit_tfm(struct crypto_tfm *tfm)
9901001
{
9911002
struct wc_linuxkm_drbg_ctx *ctx = (struct wc_linuxkm_drbg_ctx *)crypto_tfm_ctx(tfm);
992-
unsigned int i;
9931003

994-
if (ctx->rngs) {
995-
for (i = 0; i < nr_cpu_ids; ++i) {
996-
(void)wc_FreeMutex(&ctx->rngs[i].lock);
997-
wc_FreeRng(&ctx->rngs[i].rng);
998-
}
999-
free(ctx->rngs);
1000-
ctx->rngs = NULL;
1001-
}
1004+
wc_linuxkm_drbg_ctx_clear(ctx);
10021005

10031006
return;
10041007
}

0 commit comments

Comments
 (0)