linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] bpf, i386: remove unneeded conversion to bool
@ 2020-05-06 14:03 Jason Yan
  2020-05-06 14:16 ` hpa
  2020-05-06 22:04 ` Martin KaFai Lau
  0 siblings, 2 replies; 4+ messages in thread
From: Jason Yan @ 2020-05-06 14:03 UTC (permalink / raw)
  To: davem, kuznet, yoshfuji, udknight, tglx, mingo, bp, x86, hpa,
	ast, daniel, kafai, songliubraving, yhs, andriin, john.fastabend,
	kpsingh, lukenels, xi.wang, netdev, bpf, linux-kernel
  Cc: 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

Signed-off-by: Jason Yan <yanaijie@huawei.com>
---
 v2: change the name 'x32' to 'i386'.

 arch/x86/net/bpf_jit_comp32.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/x86/net/bpf_jit_comp32.c b/arch/x86/net/bpf_jit_comp32.c
index 66cd150b7e54..96fde03aa987 100644
--- a/arch/x86/net/bpf_jit_comp32.c
+++ b/arch/x86/net/bpf_jit_comp32.c
@@ -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];
-- 
2.21.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH v2] bpf, i386: remove unneeded conversion to bool
  2020-05-06 14:03 [PATCH v2] bpf, i386: remove unneeded conversion to bool Jason Yan
@ 2020-05-06 14:16 ` hpa
  2020-05-06 22:04 ` Martin KaFai Lau
  1 sibling, 0 replies; 4+ messages in thread
From: hpa @ 2020-05-06 14:16 UTC (permalink / raw)
  To: Jason Yan, davem, kuznet, yoshfuji, udknight, tglx, mingo, bp,
	x86, ast, daniel, kafai, songliubraving, yhs, andriin,
	john.fastabend, kpsingh, lukenels, xi.wang, netdev, bpf,
	linux-kernel

On May 6, 2020 7:03:52 AM PDT, Jason Yan <yanaijie@huawei.com> wrote:
>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
>
>Signed-off-by: Jason Yan <yanaijie@huawei.com>
>---
> v2: change the name 'x32' to 'i386'.
>
> arch/x86/net/bpf_jit_comp32.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
>diff --git a/arch/x86/net/bpf_jit_comp32.c
>b/arch/x86/net/bpf_jit_comp32.c
>index 66cd150b7e54..96fde03aa987 100644
>--- a/arch/x86/net/bpf_jit_comp32.c
>+++ b/arch/x86/net/bpf_jit_comp32.c
>@@ -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];

"foo ? true : false" is also far better written !!foo when it isn't totally redundant.
-- 
Sent from my Android device with K-9 Mail. Please excuse my brevity.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v2] bpf, i386: remove unneeded conversion to bool
  2020-05-06 14:03 [PATCH v2] bpf, i386: remove unneeded conversion to bool Jason Yan
  2020-05-06 14:16 ` hpa
@ 2020-05-06 22:04 ` Martin KaFai Lau
  2020-05-07 15:57   ` Daniel Borkmann
  1 sibling, 1 reply; 4+ messages in thread
From: Martin KaFai Lau @ 2020-05-06 22:04 UTC (permalink / raw)
  To: Jason Yan
  Cc: davem, kuznet, yoshfuji, udknight, tglx, mingo, bp, x86, hpa,
	ast, daniel, songliubraving, yhs, andriin, john.fastabend,
	kpsingh, lukenels, xi.wang, netdev, bpf, linux-kernel

On Wed, May 06, 2020 at 10:03:52PM +0800, Jason Yan wrote:
> 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.

Acked-by: Martin KaFai Lau <kafai@fb.com>

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v2] bpf, i386: remove unneeded conversion to bool
  2020-05-06 22:04 ` Martin KaFai Lau
@ 2020-05-07 15:57   ` Daniel Borkmann
  0 siblings, 0 replies; 4+ messages in thread
From: Daniel Borkmann @ 2020-05-07 15:57 UTC (permalink / raw)
  To: Martin KaFai Lau, Jason Yan
  Cc: davem, kuznet, yoshfuji, udknight, tglx, mingo, bp, x86, hpa,
	ast, songliubraving, yhs, andriin, john.fastabend, kpsingh,
	lukenels, xi.wang, netdev, bpf, linux-kernel

On 5/7/20 12:04 AM, Martin KaFai Lau wrote:
> On Wed, May 06, 2020 at 10:03:52PM +0800, Jason Yan wrote:
>> 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.
> 
> Acked-by: Martin KaFai Lau <kafai@fb.com>

Applied, thanks!

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2020-05-07 15:58 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-06 14:03 [PATCH v2] bpf, i386: remove unneeded conversion to bool Jason Yan
2020-05-06 14:16 ` hpa
2020-05-06 22:04 ` Martin KaFai Lau
2020-05-07 15:57   ` Daniel Borkmann

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).