[2/2] powerpc/kprobes: Reduce depth of a test
diff mbox series

Message ID b67d6705956a1a294af600700115930ff87e643c.1581687838.git.christophe.leroy@c-s.fr
State Superseded
Headers show
Series
  • [1/2] powerpc/kprobes: Remove redundant code
Related show

Checks

Context Check Description
snowpatch_ozlabs/needsstable success Patch has no Fixes tags
snowpatch_ozlabs/checkpatch success total: 0 errors, 0 warnings, 0 checks, 66 lines checked
snowpatch_ozlabs/build-pmac32 success Build succeeded
snowpatch_ozlabs/build-ppc64e success Build succeeded
snowpatch_ozlabs/build-ppc64be success Build succeeded
snowpatch_ozlabs/build-ppc64le success Build succeeded
snowpatch_ozlabs/apply_patch success Successfully applied on branch powerpc/merge (a5bc6e124219546a81ce334dc9b16483d55e9abf)

Commit Message

Christophe Leroy Feb. 14, 2020, 1:44 p.m. UTC
if (a) {
		if (b)
			do_something();
	}

Is equivalent to

	if (a & b)
		do_something();

Signed-off-by: Christophe Leroy <christophe.leroy@c-s.fr>
---
 arch/powerpc/kernel/kprobes.c | 58 +++++++++++++++++------------------
 1 file changed, 28 insertions(+), 30 deletions(-)

Comments

Naveen N. Rao Feb. 18, 2020, 2:40 p.m. UTC | #1
Christophe Leroy wrote:
> 	if (a) {
> 		if (b)
> 			do_something();
> 	}
> 
> Is equivalent to
> 
> 	if (a & b)
> 		do_something();
> 
> Signed-off-by: Christophe Leroy <christophe.leroy@c-s.fr>
> ---
>  arch/powerpc/kernel/kprobes.c | 58 +++++++++++++++++------------------
>  1 file changed, 28 insertions(+), 30 deletions(-)
> 
> diff --git a/arch/powerpc/kernel/kprobes.c b/arch/powerpc/kernel/kprobes.c
> index 7a925eb76ec0..d7c80a078c1e 100644
> --- a/arch/powerpc/kernel/kprobes.c
> +++ b/arch/powerpc/kernel/kprobes.c
> @@ -277,38 +277,36 @@ int kprobe_handler(struct pt_regs *regs)
>  
>  	/* Check we're not actually recursing */
>  	p = get_kprobe(addr);
> -	if (kprobe_running()) {
> -		if (p) {
> -			kprobe_opcode_t insn = *p->ainsn.insn;
> -			if (kcb->kprobe_status == KPROBE_HIT_SS &&
> -					is_trap(insn)) {
> -				/* Turn off 'trace' bits */
> -				regs->msr &= ~MSR_SINGLESTEP;
> -				regs->msr |= kcb->kprobe_saved_msr;
> -				goto no_kprobe;
> -			}
> -			/* We have reentered the kprobe_handler(), since
> -			 * another probe was hit while within the handler.
> -			 * We here save the original kprobes variables and
> -			 * just single step on the instruction of the new probe
> -			 * without calling any user handlers.
> -			 */
> -			save_previous_kprobe(kcb);
> -			set_current_kprobe(p, regs, kcb);
> -			kprobes_inc_nmissed_count(p);
> -			kcb->kprobe_status = KPROBE_REENTER;
> -			if (p->ainsn.boostable >= 0) {
> -				ret = try_to_emulate(p, regs);
> -
> -				if (ret > 0) {
> -					restore_previous_kprobe(kcb);
> -					preempt_enable_no_resched();
> -					return 1;
> -				}
> +	if (kprobe_running() && p) {
> +		kprobe_opcode_t insn = *p->ainsn.insn;
> +
> +		if (kcb->kprobe_status == KPROBE_HIT_SS && is_trap(insn)) {
> +			/* Turn off 'trace' bits */
> +			regs->msr &= ~MSR_SINGLESTEP;
> +			regs->msr |= kcb->kprobe_saved_msr;
> +			goto no_kprobe;
> +		}
> +		/* We have reentered the kprobe_handler(), since
> +		 * another probe was hit while within the handler.
> +		 * We here save the original kprobes variables and
> +		 * just single step on the instruction of the new probe
> +		 * without calling any user handlers.
> +		 */
> +		save_previous_kprobe(kcb);
> +		set_current_kprobe(p, regs, kcb);
> +		kprobes_inc_nmissed_count(p);
> +		kcb->kprobe_status = KPROBE_REENTER;
> +		if (p->ainsn.boostable >= 0) {
> +			ret = try_to_emulate(p, regs);
> +
> +			if (ret > 0) {
> +				restore_previous_kprobe(kcb);
> +				preempt_enable_no_resched();
> +				return 1;
>  			}
> -			prepare_singlestep(p, regs);
> -			return 1;
>  		}
> +		prepare_singlestep(p, regs);
> +		return 1;
>  	}
>  

If we move the below !p case before the check for kprobe_running() right 
after get_kprobe(), we won't need to check for (p) above and we won't 
have any change in logic from Patch 1.

>  	if (!p) {


- Naveen

Patch
diff mbox series

diff --git a/arch/powerpc/kernel/kprobes.c b/arch/powerpc/kernel/kprobes.c
index 7a925eb76ec0..d7c80a078c1e 100644
--- a/arch/powerpc/kernel/kprobes.c
+++ b/arch/powerpc/kernel/kprobes.c
@@ -277,38 +277,36 @@  int kprobe_handler(struct pt_regs *regs)
 
 	/* Check we're not actually recursing */
 	p = get_kprobe(addr);
-	if (kprobe_running()) {
-		if (p) {
-			kprobe_opcode_t insn = *p->ainsn.insn;
-			if (kcb->kprobe_status == KPROBE_HIT_SS &&
-					is_trap(insn)) {
-				/* Turn off 'trace' bits */
-				regs->msr &= ~MSR_SINGLESTEP;
-				regs->msr |= kcb->kprobe_saved_msr;
-				goto no_kprobe;
-			}
-			/* We have reentered the kprobe_handler(), since
-			 * another probe was hit while within the handler.
-			 * We here save the original kprobes variables and
-			 * just single step on the instruction of the new probe
-			 * without calling any user handlers.
-			 */
-			save_previous_kprobe(kcb);
-			set_current_kprobe(p, regs, kcb);
-			kprobes_inc_nmissed_count(p);
-			kcb->kprobe_status = KPROBE_REENTER;
-			if (p->ainsn.boostable >= 0) {
-				ret = try_to_emulate(p, regs);
-
-				if (ret > 0) {
-					restore_previous_kprobe(kcb);
-					preempt_enable_no_resched();
-					return 1;
-				}
+	if (kprobe_running() && p) {
+		kprobe_opcode_t insn = *p->ainsn.insn;
+
+		if (kcb->kprobe_status == KPROBE_HIT_SS && is_trap(insn)) {
+			/* Turn off 'trace' bits */
+			regs->msr &= ~MSR_SINGLESTEP;
+			regs->msr |= kcb->kprobe_saved_msr;
+			goto no_kprobe;
+		}
+		/* We have reentered the kprobe_handler(), since
+		 * another probe was hit while within the handler.
+		 * We here save the original kprobes variables and
+		 * just single step on the instruction of the new probe
+		 * without calling any user handlers.
+		 */
+		save_previous_kprobe(kcb);
+		set_current_kprobe(p, regs, kcb);
+		kprobes_inc_nmissed_count(p);
+		kcb->kprobe_status = KPROBE_REENTER;
+		if (p->ainsn.boostable >= 0) {
+			ret = try_to_emulate(p, regs);
+
+			if (ret > 0) {
+				restore_previous_kprobe(kcb);
+				preempt_enable_no_resched();
+				return 1;
 			}
-			prepare_singlestep(p, regs);
-			return 1;
 		}
+		prepare_singlestep(p, regs);
+		return 1;
 	}
 
 	if (!p) {