diff mbox series

[for_v25,2/4] x86/sgx: Use goto to handle sgx_encl_get_backing() failure in SECS flows

Message ID 20191221003156.27236-3-sean.j.christopherson@intel.com (mailing list archive)
State New, archived
Headers show
Series x86/sgx: Reclaim bug fix and cleanup | expand

Commit Message

Sean Christopherson Dec. 21, 2019, 12:31 a.m. UTC
Use a goto for the SECS backing error path in sgx_reclaimer_write() so
that the happy path is a straight shot, e.g. to make it obvious that the
backing is not being leaked.  Reducing the indentation also eliminates a
line wrap.

No functional change intended.

Signed-off-by: Sean Christopherson <sean.j.christopherson@intel.com>
---

I could go either way on this patch, included it in case you have a
preference.

 arch/x86/kernel/cpu/sgx/reclaim.c | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)
diff mbox series

Patch

diff --git a/arch/x86/kernel/cpu/sgx/reclaim.c b/arch/x86/kernel/cpu/sgx/reclaim.c
index 67bda5528625..c5c0ba92ab63 100644
--- a/arch/x86/kernel/cpu/sgx/reclaim.c
+++ b/arch/x86/kernel/cpu/sgx/reclaim.c
@@ -355,18 +355,19 @@  static void sgx_reclaimer_write(struct sgx_epc_page *epc_page,
 		} else if (atomic_read(&encl->flags) & SGX_ENCL_INITIALIZED) {
 			ret = sgx_encl_get_backing(encl, PFN_DOWN(encl->size),
 						   &secs_backing);
-			if (!ret) {
-				sgx_encl_ewb(encl->secs.epc_page,
-					     &secs_backing);
+			if (ret)
+				goto out;
 
-				sgx_free_page(encl->secs.epc_page);
-				encl->secs.epc_page = NULL;
+			sgx_encl_ewb(encl->secs.epc_page, &secs_backing);
 
-				sgx_encl_put_backing(&secs_backing, true);
-			}
+			sgx_free_page(encl->secs.epc_page);
+			encl->secs.epc_page = NULL;
+
+			sgx_encl_put_backing(&secs_backing, true);
 		}
 	}
 
+out:
 	mutex_unlock(&encl->lock);
 }