Skip to content

Commit 4bf5390

Browse files
committed
bsdkm: misc cleanup.
1 parent 2dd7947 commit 4bf5390

3 files changed

Lines changed: 24 additions & 16 deletions

File tree

bsdkm/bsdkm_wc_port.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
#ifndef CHAR_BIT
3737
#include <sys/limits.h>
3838
#endif /* !CHAR_BIT*/
39+
#include <sys/proc.h>
3940

4041
#define NO_THREAD_LS
4142
#define NO_ATTRIBUTE_CONSTRUCTOR
@@ -80,20 +81,22 @@ extern struct malloc_type M_WOLFSSL[1];
8081
#if defined(WOLFSSL_BSDKM_MEMORY_DEBUG)
8182
#define XMALLOC(s, h, t) ({ \
8283
(void)(h); (void)(t); \
83-
void * _ptr = malloc(s, M_WOLFSSL, M_WAITOK | M_ZERO); \
84+
int _wait_flag = curthread->td_critnest == 0 ? M_WAITOK : M_NOWAIT; \
85+
void * _ptr = malloc((s), M_WOLFSSL, _wait_flag | M_ZERO); \
8486
printf("info: malloc: %p, M_WOLFSSL, %zu\n", _ptr, (size_t) s); \
8587
(void *)_ptr; \
8688
})
8789

8890
#define XFREE(p, h, t) ({ \
8991
void* _xp; (void)(h); (void)(t); _xp = (p); \
90-
printf("info: free: %p, M_WOLFSSL\n", p); \
92+
printf("info: free: %p, M_WOLFSSL\n", _xp); \
9193
if(_xp) free(_xp, M_WOLFSSL); \
9294
})
9395
#else
9496
#define XMALLOC(s, h, t) ({ \
9597
(void)(h); (void)(t); \
96-
void * _ptr = malloc(s, M_WOLFSSL, M_WAITOK | M_ZERO); \
98+
int _wait_flag = curthread->td_critnest == 0 ? M_WAITOK : M_NOWAIT; \
99+
void * _ptr = malloc((s), M_WOLFSSL, _wait_flag | M_ZERO); \
97100
(void *)_ptr; \
98101
})
99102

bsdkm/wolfkmod.c

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -249,15 +249,14 @@ static int wolfkmod_load(void)
249249

250250
error = wolfkmod_init();
251251
if (error != 0) {
252-
return (ECANCELED);
252+
goto wolfkmod_load_out;
253253
}
254254

255255
#ifndef NO_CRYPT_TEST
256256
error = wolfcrypt_test(NULL);
257257
if (error != 0) {
258258
printf("error: wolfcrypt test failed: %d\n", error);
259-
(void)wolfkmod_cleanup();
260-
return (ECANCELED);
259+
goto wolfkmod_load_out;
261260
}
262261
printf("info: wolfCrypt self-test passed.\n");
263262
#endif /* NO_CRYPT_TEST */
@@ -266,15 +265,19 @@ static int wolfkmod_load(void)
266265
error = benchmark_test(NULL);
267266
if (error != 0) {
268267
printf("error: wolfcrypt benchmark failed: %d\n", error);
269-
(void)wolfkmod_cleanup();
270-
return (ECANCELED);
268+
goto wolfkmod_load_out;
271269
}
272270
printf("info: wolfCrypt benchmark passed.\n");
273271
#endif /* WOLFSSL_KERNEL_BENCHMARKS */
274-
275272
printf("info: libwolfssl loaded\n");
276273

277-
return (0);
274+
wolfkmod_load_out:
275+
if (error != 0) {
276+
(void)wolfkmod_cleanup();
277+
error = ECANCELED;
278+
}
279+
280+
return (error);
278281
}
279282

280283
static int wolfkmod_unload(void)
@@ -435,7 +438,8 @@ static int wolfkdriv_attach(device_t dev)
435438

436439
ret = wolfkmod_init();
437440
if (ret != 0) {
438-
return (ECANCELED);
441+
error = ECANCELED;
442+
goto attach_out;
439443
}
440444

441445
/**
@@ -452,7 +456,8 @@ static int wolfkdriv_attach(device_t dev)
452456
if (softc->crid < 0) {
453457
device_printf(dev, "error: crypto_get_driverid failed: %d\n",
454458
softc->crid);
455-
return (ENXIO);
459+
error = ENXIO;
460+
goto attach_out;
456461
}
457462

458463
/*
@@ -487,7 +492,7 @@ static int wolfkdriv_attach(device_t dev)
487492
attach_out:
488493
if (error) {
489494
wolfkdriv_unregister(softc);
490-
error = ENXIO;
495+
(void)wolfkmod_cleanup();
491496
}
492497

493498
return (error);

bsdkm/x86_vecreg.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,13 @@
2929
#include <machine/pcb.h>
3030

3131
struct wolfkmod_fpu_state_t {
32-
volatile lwpid_t td_tid;
33-
volatile u_int nest;
32+
volatile lwpid_t td_tid; /* the thread curently using fpu. */
33+
volatile u_int nest; /* the fpu nesting level. */
3434
};
3535

3636
typedef struct wolfkmod_fpu_state_t wolfkmod_fpu_state_t;
3737

38-
/* fpu_states array tracks thread id and nesting level of save/restore
38+
/* The fpu_states array tracks thread id and nesting level of save/restore
3939
* and push/pop vector registers macro calls. It is indexed by raw cpu id,
4040
* and only accessed after the thread calls fpu_kern_enter(), and before
4141
* calling fpu_kern_leave(), and only indexed by the thread's PCPU_GET(cpuid).

0 commit comments

Comments
 (0)