Skip to content

Commit d8f3e97

Browse files
davem330borkmann
authored andcommitted
bpf: Avoid unnecessary instruction in convert_bpf_ld_abs()
'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>
1 parent 4afe60a commit d8f3e97

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

net/core/filter.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -463,7 +463,8 @@ static bool convert_bpf_ld_abs(struct sock_filter *fp, struct bpf_insn **insnp)
463463
bool ldx_off_ok = offset <= S16_MAX;
464464

465465
*insn++ = BPF_MOV64_REG(BPF_REG_TMP, BPF_REG_H);
466-
*insn++ = BPF_ALU64_IMM(BPF_SUB, BPF_REG_TMP, offset);
466+
if (offset)
467+
*insn++ = BPF_ALU64_IMM(BPF_SUB, BPF_REG_TMP, offset);
467468
*insn++ = BPF_JMP_IMM(BPF_JSLT, BPF_REG_TMP,
468469
size, 2 + endian + (!ldx_off_ok * 2));
469470
if (ldx_off_ok) {

0 commit comments

Comments
 (0)