x86/sev-es: Convert to insn_decode()
authorBorislav Petkov <bp@suse.de>
Mon, 16 Nov 2020 17:21:23 +0000 (18:21 +0100)
committerBorislav Petkov <bp@suse.de>
Mon, 15 Mar 2021 10:46:40 +0000 (11:46 +0100)
Simplify code, no functional changes.

Signed-off-by: Borislav Petkov <bp@suse.de>
Link: https://lkml.kernel.org/r/20210304174237.31945-14-bp@alien8.de
arch/x86/kernel/sev-es.c

index 043dc2f46b1fcfa6073a8f551eb77b6fe8a6bbef..75c7df3a0820030861eebeecd3d1d7cffc65508f 100644 (file)
@@ -254,7 +254,6 @@ static int vc_fetch_insn_kernel(struct es_em_ctxt *ctxt,
 static enum es_result __vc_decode_user_insn(struct es_em_ctxt *ctxt)
 {
        char buffer[MAX_INSN_SIZE];
-       enum es_result ret;
        int res;
 
        res = insn_fetch_from_user_inatomic(ctxt->regs, buffer);
@@ -268,16 +267,16 @@ static enum es_result __vc_decode_user_insn(struct es_em_ctxt *ctxt)
        if (!insn_decode_from_regs(&ctxt->insn, ctxt->regs, buffer, res))
                return ES_DECODE_FAILED;
 
-       ret = ctxt->insn.immediate.got ? ES_OK : ES_DECODE_FAILED;
-
-       return ret;
+       if (ctxt->insn.immediate.got)
+               return ES_OK;
+       else
+               return ES_DECODE_FAILED;
 }
 
 static enum es_result __vc_decode_kern_insn(struct es_em_ctxt *ctxt)
 {
        char buffer[MAX_INSN_SIZE];
-       enum es_result ret;
-       int res;
+       int res, ret;
 
        res = vc_fetch_insn_kernel(ctxt, buffer);
        if (res) {
@@ -287,12 +286,11 @@ static enum es_result __vc_decode_kern_insn(struct es_em_ctxt *ctxt)
                return ES_EXCEPTION;
        }
 
-       insn_init(&ctxt->insn, buffer, MAX_INSN_SIZE, 1);
-       insn_get_length(&ctxt->insn);
-
-       ret = ctxt->insn.immediate.got ? ES_OK : ES_DECODE_FAILED;
-
-       return ret;
+       ret = insn_decode(&ctxt->insn, buffer, MAX_INSN_SIZE, INSN_MODE_64);
+       if (ret < 0)
+               return ES_DECODE_FAILED;
+       else
+               return ES_OK;
 }
 
 static enum es_result vc_decode_insn(struct es_em_ctxt *ctxt)