@@ -491,6 +491,7 @@ static int wolfkdriv_attach(device_t dev)
491491
492492attach_out :
493493 if (error ) {
494+ device_printf (dev , "error: attach_out: %d\n" , error );
494495 wolfkdriv_unregister (softc );
495496 (void )wolfkmod_cleanup ();
496497 }
@@ -503,16 +504,14 @@ static int wolfkdriv_detach(device_t dev)
503504 struct wolfkdriv_softc * softc = NULL ;
504505 int ret = 0 ;
505506
507+ /* unregister wolfcrypt algs */
508+ softc = device_get_softc (dev );
509+ wolfkdriv_unregister (softc );
506510 ret = wolfkmod_cleanup ();
507-
508- if (ret == 0 ) {
509- /* unregister wolfcrypt algs */
510- softc = device_get_softc (dev );
511- wolfkdriv_unregister (softc );
512- }
513-
514511 #if defined(WOLFSSL_BSDKM_VERBOSE_DEBUG )
515- device_printf (dev , "info: exiting detach\n" );
512+ device_printf (dev , "info: exiting detach: %d\n" , ret );
513+ #else
514+ (void )ret ;
516515 #endif /* WOLFSSL_BSDKM_VERBOSE_DEBUG */
517516
518517 return (0 );
@@ -802,6 +801,7 @@ static int wolfkdriv_cbc_work(device_t dev, wolfkdriv_session_t * session,
802801
803802cbc_work_out :
804803 /* cleanup. */
804+ wc_ForceZero (& aes , sizeof (aes ));
805805 wc_ForceZero (iv , sizeof (iv ));
806806 wc_ForceZero (block , sizeof (block ));
807807
@@ -812,6 +812,11 @@ static int wolfkdriv_cbc_work(device_t dev, wolfkdriv_session_t * session,
812812 error );
813813 #endif /* WOLFSSL_BSDKM_VERBOSE_DEBUG */
814814
815+ if (error < 0 ) {
816+ /* convert wolfcrypt errors to EINVAL. */
817+ error = EINVAL ;
818+ }
819+
815820 return (error );
816821}
817822
@@ -979,6 +984,7 @@ static int wolfkdriv_gcm_work(device_t dev, wolfkdriv_session_t * session,
979984
980985gcm_work_out :
981986 /* cleanup. */
987+ wc_ForceZero (& aes , sizeof (aes ));
982988 wc_ForceZero (iv , sizeof (iv ));
983989 wc_ForceZero (auth_tag , sizeof (auth_tag ));
984990
@@ -989,6 +995,11 @@ static int wolfkdriv_gcm_work(device_t dev, wolfkdriv_session_t * session,
989995 error );
990996 #endif /* WOLFSSL_BSDKM_VERBOSE_DEBUG */
991997
998+ if (error < 0 ) {
999+ /* convert wolfcrypt errors to EINVAL. */
1000+ error = EINVAL ;
1001+ }
1002+
9921003 return (error );
9931004}
9941005
0 commit comments