x86/hw_breakpoints: Return -EINVAL in default case in hw_breakpoint_arch_parse
PATCH 1/1 x86/hw_breakpoints: Return -EINVAL in default case in hw_breakpoint_arch_parse
When building with -Wsometimes-uninitialized, Clang warns:
arch/x86/kernel/hw_breakpoint.c:355:2: warning: variable 'align' is used uninitialized whenever switch default is taken [-Wsometimes-uninitialized]
It's not wrong but we can see that arch_build_bp_info will only ever initialize hw->len to one of the specified switch cases. We can easily silence Clang by just returning -EINVAL in the default case so that we can never use align without initializing it first.
--- arch/x86/kernel/hw_breakpoint.c | 1 + 1 file changed, 1 insertion(+)
arch/x86/kernel/hw_breakpoint.c +1 -0
@@ -354,6 +354,7 @@ int hw_breakpoint_arch_parse(struct perf_event *bp,#endif default :WARN_ON_ONCE (1 ); +return -EINVAL ; }/*
Signature · 1 line
2.21.0
Quoted 11 lines · Nathan Chancellor
When building with -Wsometimes-uninitialized, Clang warns:
arch/x86/kernel/hw_breakpoint.c:355:2: warning: variable 'align' is used uninitialized whenever switch default is taken [-Wsometimes-uninitialized]It's not wrong but we can see that
arch_build_bp_infowill only ever initializehw->lento one of the specified switch cases. We can easily silence Clang by just returning-EINVALin the default case so that we can never use align without initializing it first.
And the call site just bubbles up return codes anyways. Thanks for sending.
Quoted 23 lines
Suggested-by Nick Desaulniers <[email protected]>Signed-off-by Nathan Chancellor <[email protected]>--- arch/x86/kernel/hw_breakpoint.c | 1 + 1 file changed, 1 insertion(+)arch/x86/kernel/hw_breakpoint.c +1
-1@@ -354,6 +354,7 @@ int hw_breakpoint_arch_parse(struct perf_event *bp,#endif default :WARN_ON_ONCE (1 ); +return -EINVAL ; }/* -- 2.21.0
Signature · 2 lines
Thanks, ~Nick Desaulniers
Quoted 33 lines · Nathan Chancellor
When building with -Wsometimes-uninitialized, Clang warns:
arch/x86/kernel/hw_breakpoint.c:355:2: warning: variable 'align' is used uninitialized whenever switch default is taken [-Wsometimes-uninitialized]It's not wrong but we can see that
arch_build_bp_infowill only ever initializehw->lento one of the specified switch cases. We can easily silence Clang by just returning-EINVALin the default case so that we can never use align without initializing it first.Suggested-by Nick Desaulniers <[email protected]>Signed-off-by Nathan Chancellor <[email protected]>--- arch/x86/kernel/hw_breakpoint.c | 1 + 1 file changed, 1 insertion(+)arch/x86/kernel/hw_breakpoint.c +1
-0@@ -354,6 +354,7 @@ int hw_breakpoint_arch_parse(struct perf_event *bp,#endif default :WARN_ON_ONCE (1 ); +return -EINVAL ; }/* Signature · 1 line
2.21.0
Gentle ping (if there was a response to this, I didn't receive it). I know I sent it in the middle of a merge window so I get if it slipped through the cracks.
Thanks,
Nathan
tip-bot for Nathan Chancellor
merge bot[tip:x86/urgent] x86/hw_breakpoints: Make default case in hw_breakpoint_arch_parse() return an error
In reply to Nathan Chancellorx86/hw_breakpoints: Make default case in hw_breakpoint_arch_parse() return an error
Commit-ID: e898e69d6b9475bf123f99b3c5d1a67bb7cb2361 Gitweb: https://git.kernel.org/tip/e898e69d6b9475bf123f99b3c5d1a67bb7cb2361 Author: Nathan Chancellor <[email protected]> AuthorDate: Thu, 7 Mar 2019 14:27:56 -0700 Committer: Thomas Gleixner <[email protected]> CommitDate: Fri, 22 Mar 2019 17:08:17 +0100
x86/hw_breakpoints: Make default case in hw_breakpoint_arch_parse() return an error
When building with -Wsometimes-uninitialized, Clang warns:
arch/x86/kernel/hw_breakpoint.c:355:2: warning: variable 'align' is used uninitialized whenever switch default is taken [-Wsometimes-uninitialized]
The default cannot be reached because arch_build_bp_info() initializes hw->len to one of the specified cases. Nevertheless the warning is valid and returning -EINVAL makes sure that this cannot be broken by future modifications.
--- arch/x86/kernel/hw_breakpoint.c | 1 + 1 file changed, 1 insertion(+)
arch/x86/kernel/hw_breakpoint.c +1 -0
@@ -354,6 +354,7 @@ int hw_breakpoint_arch_parse(struct perf_event *bp,#endif default :WARN_ON_ONCE (1 ); +return -EINVAL ; }/*