Skip to contentSkip to conversation

bpf, i386: remove unneeded conversion to bool

PATCH Applied Jason Yan 4 participants 4 messages May 6, 2020 – May 7, 2020

Subsystems (5)
Networking Network drivers x86 BPF +1 more subsystems
lore
Share & tools
lore

Jason Yan

author
#0 lore raw

PATCH v2 1/1 bpf, i386: remove unneeded conversion to bool

The '==' expression itself is bool, no need to convert it to bool again. This fixes the following coccicheck warning:

arch/x86/net/bpf_jit_comp32.c:1478:50-55: WARNING: conversion to bool not needed here
arch/x86/net/bpf_jit_comp32.c:1479:50-55: WARNING: conversion to bool not needed here

---
v2: change the name 'x32' to 'i386'.

 arch/x86/net/bpf_jit_comp32.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
arch/x86/net/bpf_jit_comp32.c +2 -2
index 66cd150b7e54..96fde03aa987 100644
@@ -1475,8 +1475,8 @@ static int do_jit(struct bpf_prog *bpf_prog, int *addrs, u8 *image,
 	for (i = 0; i < insn_cnt; i++, insn++) {
 		const s32 imm32 = insn->imm;
 		const bool is64 = BPF_CLASS(insn->code) == BPF_ALU64;
-		const bool dstk = insn->dst_reg == BPF_REG_AX ? false : true;
-		const bool sstk = insn->src_reg == BPF_REG_AX ? false : true;
+		const bool dstk = insn->dst_reg != BPF_REG_AX;
+		const bool sstk = insn->src_reg != BPF_REG_AX;
 		const u8 code = insn->code;
 		const u8 *dst = bpf2ia32[insn->dst_reg];
 		const u8 *src = bpf2ia32[insn->src_reg];
Signature · 1 line
2.21.1
#1 lore raw
Quoted 32 lines · Jason Yan

The '==' expression itself is bool, no need to convert it to bool again.
This fixes the following coccicheck warning:

arch/x86/net/bpf_jit_comp32.c:1478:50-55: WARNING: conversion to bool not needed here
arch/x86/net/bpf_jit_comp32.c:1479:50-55: WARNING: conversion to bool not needed here

---
v2: change the name 'x32' to 'i386'.

arch/x86/net/bpf_jit_comp32.c | 4 ++--

1 file changed, 2 insertions(+), 2 deletions(-)
arch/x86/net/bpf_jit_comp32.c +2 -2
index 66cd150b7e54..96fde03aa987 100644
@@ -1475,8 +1475,8 @@ static int do_jit(struct bpf_prog *bpf_prog, int
 *addrs, u8 *image,
 	for (i = 0; i < insn_cnt; i++, insn++) {
 		const s32 imm32 = insn->imm;
 		const bool is64 = BPF_CLASS(insn->code) == BPF_ALU64;
-		const bool dstk = insn->dst_reg == BPF_REG_AX ? false : true;
-		const bool sstk = insn->src_reg == BPF_REG_AX ? false : true;
+		const bool dstk = insn->dst_reg != BPF_REG_AX;
+		const bool sstk = insn->src_reg != BPF_REG_AX;
 		const u8 code = insn->code;
 		const u8 *dst = bpf2ia32[insn->dst_reg];
Quoted 1 line
		const u8 *src = bpf2ia32[insn->src_reg];

"foo ? true : false" is also far better written !!foo when it isn't totally redundant.

Signature · 1 line
Sent from my Android device with K-9 Mail. Please excuse my brevity.
maintainer Applied
#3 lore raw
Quoted 8 lines · Martin KaFai Lau
Quoted 2 lines · Jason Yan

The '==' expression itself is bool, no need to convert it to bool again. This fixes the following coccicheck warning:

Make sense.

It may belong to bpf-next instead.

Applied, thanks!