File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -908,6 +908,22 @@ struct wc_linuxkm_drbg_ctx {
908908 } * rngs ; /* one per CPU ID */
909909};
910910
911+ static inline void wc_linuxkm_drbg_ctx_clear (struct wc_linuxkm_drbg_ctx * ctx )
912+ {
913+ unsigned int i ;
914+
915+ if (ctx -> rngs ) {
916+ for (i = 0 ; i < nr_cpu_ids ; ++ i ) {
917+ (void )wc_FreeMutex (& ctx -> rngs [i ].lock );
918+ wc_FreeRng (& ctx -> rngs [i ].rng );
919+ }
920+ free (ctx -> rngs );
921+ ctx -> rngs = NULL ;
922+ }
923+
924+ return ;
925+ }
926+
911927static int wc_linuxkm_drbg_init_tfm (struct crypto_tfm * tfm )
912928{
913929 struct wc_linuxkm_drbg_ctx * ctx = (struct wc_linuxkm_drbg_ctx * )crypto_tfm_ctx (tfm );
@@ -937,12 +953,7 @@ static int wc_linuxkm_drbg_init_tfm(struct crypto_tfm *tfm)
937953 }
938954
939955 if (ret != 0 ) {
940- for (i = 0 ; i < nr_cpu_ids ; ++ i ) {
941- (void )wc_FreeMutex (& ctx -> rngs [i ].lock );
942- wc_FreeRng (& ctx -> rngs [i ].rng );
943- }
944- free (ctx -> rngs );
945- ctx -> rngs = NULL ;
956+ wc_linuxkm_drbg_ctx_clear (ctx );
946957 }
947958
948959 return ret ;
@@ -951,16 +962,8 @@ static int wc_linuxkm_drbg_init_tfm(struct crypto_tfm *tfm)
951962static void wc_linuxkm_drbg_exit_tfm (struct crypto_tfm * tfm )
952963{
953964 struct wc_linuxkm_drbg_ctx * ctx = (struct wc_linuxkm_drbg_ctx * )crypto_tfm_ctx (tfm );
954- unsigned int i ;
955965
956- if (ctx -> rngs ) {
957- for (i = 0 ; i < nr_cpu_ids ; ++ i ) {
958- (void )wc_FreeMutex (& ctx -> rngs [i ].lock );
959- wc_FreeRng (& ctx -> rngs [i ].rng );
960- }
961- free (ctx -> rngs );
962- ctx -> rngs = NULL ;
963- }
966+ wc_linuxkm_drbg_ctx_clear (ctx );
964967
965968 return ;
966969}
You can’t perform that action at this time.
0 commit comments