OSDN Git Service

bpf: Avoid unnecessary instruction in convert_bpf_ld_abs()
authorDavid Miller <davem@redhat.com>
Mon, 26 Nov 2018 21:42:41 +0000 (13:42 -0800)
committerDaniel Borkmann <daniel@iogearbox.net>
Mon, 26 Nov 2018 22:10:27 +0000 (23:10 +0100)
'offset' is constant and if it is zero, no need to subtract it
from BPF_REG_TMP.

Signed-off-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
net/core/filter.c

index aa27467..f50ea97 100644 (file)
@@ -463,7 +463,8 @@ static bool convert_bpf_ld_abs(struct sock_filter *fp, struct bpf_insn **insnp)
                bool ldx_off_ok = offset <= S16_MAX;
 
                *insn++ = BPF_MOV64_REG(BPF_REG_TMP, BPF_REG_H);
-               *insn++ = BPF_ALU64_IMM(BPF_SUB, BPF_REG_TMP, offset);
+               if (offset)
+                       *insn++ = BPF_ALU64_IMM(BPF_SUB, BPF_REG_TMP, offset);
                *insn++ = BPF_JMP_IMM(BPF_JSLT, BPF_REG_TMP,
                                      size, 2 + endian + (!ldx_off_ok * 2));
                if (ldx_off_ok) {