tools/objtool: Convert to insn_decode()
authorBorislav Petkov <bp@suse.de>
Fri, 20 Nov 2020 16:37:06 +0000 (17:37 +0100)
committerBorislav Petkov <bp@suse.de>
Mon, 15 Mar 2021 11:10:41 +0000 (12:10 +0100)
Simplify code, no functional changes.

Signed-off-by: Borislav Petkov <bp@suse.de>
Link: https://lkml.kernel.org/r/20210304174237.31945-18-bp@alien8.de
tools/objtool/arch/x86/decode.c

index 549813c..8380d0b 100644 (file)
@@ -90,7 +90,7 @@ int arch_decode_instruction(const struct elf *elf, const struct section *sec,
                            struct list_head *ops_list)
 {
        struct insn insn;
-       int x86_64, sign;
+       int x86_64, sign, ret;
        unsigned char op1, op2, rex = 0, rex_b = 0, rex_r = 0, rex_w = 0,
                      rex_x = 0, modrm = 0, modrm_mod = 0, modrm_rm = 0,
                      modrm_reg = 0, sib = 0;
@@ -101,10 +101,9 @@ int arch_decode_instruction(const struct elf *elf, const struct section *sec,
        if (x86_64 == -1)
                return -1;
 
-       insn_init(&insn, sec->data->d_buf + offset, maxlen, x86_64);
-       insn_get_length(&insn);
-
-       if (!insn_complete(&insn)) {
+       ret = insn_decode(&insn, sec->data->d_buf + offset, maxlen,
+                         x86_64 ? INSN_MODE_64 : INSN_MODE_32);
+       if (ret < 0) {
                WARN("can't decode instruction at %s:0x%lx", sec->name, offset);
                return -1;
        }