File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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+
949965static 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)
9891000static 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}
You can’t perform that action at this time.
0 commit comments