linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] ARM/hw_breakpoint: Mark expected switch fall-throughs
@ 2019-07-28 23:16 Gustavo A. R. Silva
  2019-07-29 16:34 ` Kees Cook
  0 siblings, 1 reply; 2+ messages in thread
From: Gustavo A. R. Silva @ 2019-07-28 23:16 UTC (permalink / raw)
  To: Will Deacon, Mark Rutland, Russell King
  Cc: Kees Cook, Stephen Rothwell, linux-kernel, linux-arm-kernel,
	Gustavo A. R. Silva

Mark switch cases where we are expecting to fall through.

This patch fixes the following warnings:

arch/arm/kernel/hw_breakpoint.c: In function 'hw_breakpoint_arch_parse':
arch/arm/kernel/hw_breakpoint.c:609:6: warning: this statement may fall through [-Wimplicit-fallthrough=]
   if (hw->ctrl.len == ARM_BREAKPOINT_LEN_2)
      ^
arch/arm/kernel/hw_breakpoint.c:611:2: note: here
  case 3:
  ^~~~
arch/arm/kernel/hw_breakpoint.c:613:6: warning: this statement may fall through [-Wimplicit-fallthrough=]
   if (hw->ctrl.len == ARM_BREAKPOINT_LEN_1)
      ^
arch/arm/kernel/hw_breakpoint.c:615:2: note: here
  default:
  ^~~~~~~
arch/arm/kernel/hw_breakpoint.c: In function 'arch_build_bp_info':
arch/arm/kernel/hw_breakpoint.c:544:6: warning: this statement may fall through [-Wimplicit-fallthrough=]
   if ((hw->ctrl.type != ARM_BREAKPOINT_EXECUTE)
      ^
arch/arm/kernel/hw_breakpoint.c:547:2: note: here
  default:
  ^~~~~~~
In file included from include/linux/kernel.h:11,
                 from include/linux/list.h:9,
                 from include/linux/preempt.h:11,
                 from include/linux/hardirq.h:5,
                 from arch/arm/kernel/hw_breakpoint.c:16:
arch/arm/kernel/hw_breakpoint.c: In function 'hw_breakpoint_pending':
include/linux/compiler.h:78:22: warning: this statement may fall through [-Wimplicit-fallthrough=]
 # define unlikely(x) __builtin_expect(!!(x), 0)
                      ^~~~~~~~~~~~~~~~~~~~~~~~~~
include/asm-generic/bug.h:136:2: note: in expansion of macro 'unlikely'
  unlikely(__ret_warn_on);     \
  ^~~~~~~~
arch/arm/kernel/hw_breakpoint.c:863:3: note: in expansion of macro 'WARN'
   WARN(1, "Asynchronous watchpoint exception taken. Debugging results may be unreliable\n");
   ^~~~
arch/arm/kernel/hw_breakpoint.c:864:2: note: here
  case ARM_ENTRY_SYNC_WATCHPOINT:
  ^~~~
arch/arm/kernel/hw_breakpoint.c: In function 'core_has_os_save_restore':
arch/arm/kernel/hw_breakpoint.c:910:6: warning: this statement may fall through [-Wimplicit-fallthrough=]
   if (oslsr & ARM_OSLSR_OSLM0)
      ^
arch/arm/kernel/hw_breakpoint.c:912:2: note: here
  default:
  ^~~~~~~

Reported-by: Stephen Rothwell <sfr@canb.auug.org.au>
Signed-off-by: Gustavo A. R. Silva <gustavo@embeddedor.com>
---
 arch/arm/kernel/hw_breakpoint.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/arch/arm/kernel/hw_breakpoint.c b/arch/arm/kernel/hw_breakpoint.c
index af8b8e15f589..b0c195e3a06d 100644
--- a/arch/arm/kernel/hw_breakpoint.c
+++ b/arch/arm/kernel/hw_breakpoint.c
@@ -544,6 +544,7 @@ static int arch_build_bp_info(struct perf_event *bp,
 		if ((hw->ctrl.type != ARM_BREAKPOINT_EXECUTE)
 			&& max_watchpoint_len >= 8)
 			break;
+		/* Else, fall through */
 	default:
 		return -EINVAL;
 	}
@@ -608,10 +609,12 @@ int hw_breakpoint_arch_parse(struct perf_event *bp,
 		/* Allow halfword watchpoints and breakpoints. */
 		if (hw->ctrl.len == ARM_BREAKPOINT_LEN_2)
 			break;
+		/* Else, fall through */
 	case 3:
 		/* Allow single byte watchpoint. */
 		if (hw->ctrl.len == ARM_BREAKPOINT_LEN_1)
 			break;
+		/* Else, fall through */
 	default:
 		ret = -EINVAL;
 		goto out;
@@ -861,6 +864,7 @@ static int hw_breakpoint_pending(unsigned long addr, unsigned int fsr,
 		break;
 	case ARM_ENTRY_ASYNC_WATCHPOINT:
 		WARN(1, "Asynchronous watchpoint exception taken. Debugging results may be unreliable\n");
+		/* Fall through */
 	case ARM_ENTRY_SYNC_WATCHPOINT:
 		watchpoint_handler(addr, fsr, regs);
 		break;
@@ -909,6 +913,7 @@ static bool core_has_os_save_restore(void)
 		ARM_DBG_READ(c1, c1, 4, oslsr);
 		if (oslsr & ARM_OSLSR_OSLM0)
 			return true;
+		/* Else, fall through */
 	default:
 		return false;
 	}
-- 
2.22.0


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH] ARM/hw_breakpoint: Mark expected switch fall-throughs
  2019-07-28 23:16 [PATCH] ARM/hw_breakpoint: Mark expected switch fall-throughs Gustavo A. R. Silva
@ 2019-07-29 16:34 ` Kees Cook
  0 siblings, 0 replies; 2+ messages in thread
From: Kees Cook @ 2019-07-29 16:34 UTC (permalink / raw)
  To: Gustavo A. R. Silva
  Cc: Mark Rutland, Stephen Rothwell, Russell King, linux-kernel,
	Will Deacon, linux-arm-kernel

On Sun, Jul 28, 2019 at 06:16:51PM -0500, Gustavo A. R. Silva wrote:
> Mark switch cases where we are expecting to fall through.
> 
> This patch fixes the following warnings:
> 
> arch/arm/kernel/hw_breakpoint.c: In function 'hw_breakpoint_arch_parse':
> arch/arm/kernel/hw_breakpoint.c:609:6: warning: this statement may fall through [-Wimplicit-fallthrough=]
>    if (hw->ctrl.len == ARM_BREAKPOINT_LEN_2)
>       ^
> arch/arm/kernel/hw_breakpoint.c:611:2: note: here
>   case 3:
>   ^~~~
> arch/arm/kernel/hw_breakpoint.c:613:6: warning: this statement may fall through [-Wimplicit-fallthrough=]
>    if (hw->ctrl.len == ARM_BREAKPOINT_LEN_1)
>       ^
> arch/arm/kernel/hw_breakpoint.c:615:2: note: here
>   default:
>   ^~~~~~~
> arch/arm/kernel/hw_breakpoint.c: In function 'arch_build_bp_info':
> arch/arm/kernel/hw_breakpoint.c:544:6: warning: this statement may fall through [-Wimplicit-fallthrough=]
>    if ((hw->ctrl.type != ARM_BREAKPOINT_EXECUTE)
>       ^
> arch/arm/kernel/hw_breakpoint.c:547:2: note: here
>   default:
>   ^~~~~~~
> In file included from include/linux/kernel.h:11,
>                  from include/linux/list.h:9,
>                  from include/linux/preempt.h:11,
>                  from include/linux/hardirq.h:5,
>                  from arch/arm/kernel/hw_breakpoint.c:16:
> arch/arm/kernel/hw_breakpoint.c: In function 'hw_breakpoint_pending':
> include/linux/compiler.h:78:22: warning: this statement may fall through [-Wimplicit-fallthrough=]
>  # define unlikely(x) __builtin_expect(!!(x), 0)
>                       ^~~~~~~~~~~~~~~~~~~~~~~~~~
> include/asm-generic/bug.h:136:2: note: in expansion of macro 'unlikely'
>   unlikely(__ret_warn_on);     \
>   ^~~~~~~~
> arch/arm/kernel/hw_breakpoint.c:863:3: note: in expansion of macro 'WARN'
>    WARN(1, "Asynchronous watchpoint exception taken. Debugging results may be unreliable\n");
>    ^~~~
> arch/arm/kernel/hw_breakpoint.c:864:2: note: here
>   case ARM_ENTRY_SYNC_WATCHPOINT:
>   ^~~~
> arch/arm/kernel/hw_breakpoint.c: In function 'core_has_os_save_restore':
> arch/arm/kernel/hw_breakpoint.c:910:6: warning: this statement may fall through [-Wimplicit-fallthrough=]
>    if (oslsr & ARM_OSLSR_OSLM0)
>       ^
> arch/arm/kernel/hw_breakpoint.c:912:2: note: here
>   default:
>   ^~~~~~~
> 
> Reported-by: Stephen Rothwell <sfr@canb.auug.org.au>
> Signed-off-by: Gustavo A. R. Silva <gustavo@embeddedor.com>

Reviewed-by: Kees Cook <keescook@chromium.org>

-Kees

> ---
>  arch/arm/kernel/hw_breakpoint.c | 5 +++++
>  1 file changed, 5 insertions(+)
> 
> diff --git a/arch/arm/kernel/hw_breakpoint.c b/arch/arm/kernel/hw_breakpoint.c
> index af8b8e15f589..b0c195e3a06d 100644
> --- a/arch/arm/kernel/hw_breakpoint.c
> +++ b/arch/arm/kernel/hw_breakpoint.c
> @@ -544,6 +544,7 @@ static int arch_build_bp_info(struct perf_event *bp,
>  		if ((hw->ctrl.type != ARM_BREAKPOINT_EXECUTE)
>  			&& max_watchpoint_len >= 8)
>  			break;
> +		/* Else, fall through */
>  	default:
>  		return -EINVAL;
>  	}
> @@ -608,10 +609,12 @@ int hw_breakpoint_arch_parse(struct perf_event *bp,
>  		/* Allow halfword watchpoints and breakpoints. */
>  		if (hw->ctrl.len == ARM_BREAKPOINT_LEN_2)
>  			break;
> +		/* Else, fall through */
>  	case 3:
>  		/* Allow single byte watchpoint. */
>  		if (hw->ctrl.len == ARM_BREAKPOINT_LEN_1)
>  			break;
> +		/* Else, fall through */
>  	default:
>  		ret = -EINVAL;
>  		goto out;
> @@ -861,6 +864,7 @@ static int hw_breakpoint_pending(unsigned long addr, unsigned int fsr,
>  		break;
>  	case ARM_ENTRY_ASYNC_WATCHPOINT:
>  		WARN(1, "Asynchronous watchpoint exception taken. Debugging results may be unreliable\n");
> +		/* Fall through */
>  	case ARM_ENTRY_SYNC_WATCHPOINT:
>  		watchpoint_handler(addr, fsr, regs);
>  		break;
> @@ -909,6 +913,7 @@ static bool core_has_os_save_restore(void)
>  		ARM_DBG_READ(c1, c1, 4, oslsr);
>  		if (oslsr & ARM_OSLSR_OSLM0)
>  			return true;
> +		/* Else, fall through */
>  	default:
>  		return false;
>  	}
> -- 
> 2.22.0
> 

-- 
Kees Cook

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

end of thread, other threads:[~2019-07-29 16:34 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-07-28 23:16 [PATCH] ARM/hw_breakpoint: Mark expected switch fall-throughs Gustavo A. R. Silva
2019-07-29 16:34 ` Kees Cook

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).