If sgx_page_cache_init() fails in the middle, a trivial return statement
causes unused memory and virtual address space reserved for the EPC
section, not freed. Fix this by using the same rollback, as when
sgx_page_reclaimer_init() fails.

Cc: sta...@vger.kernel.org # 5.11
Fixes: e7e0545299d8 ("x86/sgx: Initialize metadata for Enclave Page Cache (EPC) 
sections")
Signed-off-by: Jarkko Sakkinen <jar...@kernel.org>
---
 arch/x86/kernel/cpu/sgx/main.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/arch/x86/kernel/cpu/sgx/main.c b/arch/x86/kernel/cpu/sgx/main.c
index 8df81a3ed945..52d070fb4c9a 100644
--- a/arch/x86/kernel/cpu/sgx/main.c
+++ b/arch/x86/kernel/cpu/sgx/main.c
@@ -708,8 +708,10 @@ static int __init sgx_init(void)
        if (!cpu_feature_enabled(X86_FEATURE_SGX))
                return -ENODEV;
 
-       if (!sgx_page_cache_init())
-               return -ENOMEM;
+       if (!sgx_page_cache_init()) {
+               ret = -ENOMEM;
+               goto err_page_cache;
+       }
 
        if (!sgx_page_reclaimer_init()) {
                ret = -ENOMEM;
-- 
2.30.1

Reply via email to