Skip to content

Commit 1d93484

Browse files
authored
Merge pull request #10565 from philljj/bsdkm_misc_cleanup
bsdkm: misc cleanup.
2 parents f9817cf + 27edd64 commit 1d93484

3 files changed

Lines changed: 30 additions & 9 deletions

File tree

bsdkm/wolfkmod.c

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -491,6 +491,7 @@ static int wolfkdriv_attach(device_t dev)
491491

492492
attach_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

803802
cbc_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

980985
gcm_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

bsdkm/wolfkmod_aes.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ static int wolfkdriv_test_aes_gcm(device_t dev, int crid)
212212
XMEMSET(resultT, 0, sizeof(resultT));
213213
XMEMSET(resultC, 0, sizeof(resultC));
214214

215-
XMEMSET(resultC2, 0, sizeof(resultC));
215+
XMEMSET(resultC2, 0, sizeof(resultC2));
216216
XMEMCPY(resultC2, p, sizeof(p));
217217

218218
/* wolfcrypt encrypt */

bsdkm/x86_vecreg.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,11 @@ int wolfkmod_vecreg_save(int flags_unused)
139139
wolfkmod_print_curthread("wolfkmod_vecreg_save");
140140
#endif
141141

142+
if (fpu_states == NULL) {
143+
printf("error: wolfkmod_vecreg_save: fpu_states null\n");
144+
return (EINVAL);
145+
}
146+
142147
if (is_fpu_kern_thread(0)) {
143148
/* kernel fpu threads are special, do nothing. They own a
144149
* persistent, dedicated fpu context. */
@@ -189,6 +194,11 @@ void wolfkmod_vecreg_restore(void)
189194
wolfkmod_print_curthread("wolfkmod_vecreg_restore");
190195
#endif
191196

197+
if (fpu_states == NULL) {
198+
printf("error: wolfkmod_vecreg_restore: fpu_states null\n");
199+
return;
200+
}
201+
192202
if (is_fpu_kern_thread(0)) {
193203
/* kernel fpu threads are special, do nothing. They own a
194204
* persistent, dedicated fpu context. */

0 commit comments

Comments
 (0)