Fix module unload when SGX support is not present in CPU.

Sponsored by:	DARPA, AFRL
This commit is contained in:
Ruslan Bukin 2017-08-18 14:47:06 +00:00
parent 03f55691de
commit 5651294282
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=322660

View File

@ -1132,9 +1132,6 @@ sgx_load(void)
if ((cpu_stdext_feature & CPUID_STDEXT_SGX) == 0)
return (ENXIO);
mtx_init(&sc->mtx_encls, "SGX ENCLS", NULL, MTX_DEF);
mtx_init(&sc->mtx, "SGX driver", NULL, MTX_DEF);
error = sgx_get_epc_area(sc);
if (error) {
printf("%s: Failed to get Processor Reserved Memory area.\n",
@ -1142,6 +1139,9 @@ sgx_load(void)
return (ENXIO);
}
mtx_init(&sc->mtx_encls, "SGX ENCLS", NULL, MTX_DEF);
mtx_init(&sc->mtx, "SGX driver", NULL, MTX_DEF);
TAILQ_INIT(&sc->enclaves);
sc->sgx_cdev = make_dev(&sgx_cdevsw, 0, UID_ROOT, GID_WHEEL,
@ -1162,6 +1162,9 @@ sgx_unload(void)
sc = &sgx_sc;
if ((sc->state & SGX_STATE_RUNNING) == 0)
return (0);
mtx_lock(&sc->mtx);
if (!TAILQ_EMPTY(&sc->enclaves)) {
mtx_unlock(&sc->mtx);