Skip to content

Commit

Permalink
linuxkm/module_hooks.c: separate cleanup into static libwolfssl_clean…
Browse files Browse the repository at this point in the history
…up(), and call it from wolfssl_init() if wolfcrypt_test() fails.
  • Loading branch information
douzzer committed Dec 23, 2020
1 parent 9c87f97 commit 542ad0a
Showing 1 changed file with 23 additions and 16 deletions.
39 changes: 23 additions & 16 deletions linuxkm/module_hooks.c
Expand Up @@ -31,6 +31,26 @@
#include <linux/delay.h>
#endif

static int libwolfssl_cleanup(void) {
int ret;
#ifdef WOLFCRYPT_ONLY
ret = wolfCrypt_Cleanup();
if (ret != 0)
pr_err("wolfCrypt_Cleanup() failed: %s", wc_GetErrorString(ret));
else
pr_info("wolfCrypt " LIBWOLFSSL_VERSION_STRING " cleanup complete.\n");
#else
ret = wolfSSL_Cleanup();
if (ret != WOLFSSL_SUCCESS)
pr_err("wolfSSL_Cleanup() failed: %s", wc_GetErrorString(ret));
else
pr_info("wolfSSL " LIBWOLFSSL_VERSION_STRING " cleanup complete.\n");
#endif

return ret;
}


#if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 0, 0)
static int __init wolfssl_init(void)
#else
Expand All @@ -55,7 +75,8 @@ static int wolfssl_init(void)
#ifndef NO_CRYPT_TEST
ret = wolfcrypt_test(NULL);
if (ret < 0) {
pr_err("wolfcrypt self-test failed.");
pr_err("wolfcrypt self-test failed with return code %d.", ret);
(void)libwolfssl_cleanup();
msleep(10);
return -ENOTRECOVERABLE;
}
Expand All @@ -81,21 +102,7 @@ static void __exit wolfssl_exit(void)
static void wolfssl_exit(void)
#endif
{
int ret;
#ifdef WOLFCRYPT_ONLY
ret = wolfCrypt_Cleanup();
if (ret != 0)
pr_err("wolfCrypt_Cleanup() failed: %s", wc_GetErrorString(ret));
else
pr_info("wolfCrypt " LIBWOLFSSL_VERSION_STRING " cleanup complete.\n");
#else
ret = wolfSSL_Cleanup();
if (ret != WOLFSSL_SUCCESS)
pr_err("wolfSSL_Cleanup() failed: %s", wc_GetErrorString(ret));
else
pr_info("wolfSSL " LIBWOLFSSL_VERSION_STRING " cleanup complete.\n");
#endif

(void)libwolfssl_cleanup();
return;
}

Expand Down

0 comments on commit 542ad0a

Please sign in to comment.