The attached untested patch avoids a cppcheck warning by eliminating an unnecessary use of goto, which apparently caused cppcheck not to recognize the impossibility of a null pointer dereference in one case. It as a revision to my previous incorrect patch from two days ago ("Suspected null pointer dereference in ftrace_make_nop() for ia64"). Ideally, cppcheck should be enhanced to recognize "goto" usage in this form and do the same analysis that it does with "if" statements (and I intend to look into that), but, even with such a cppcheck enhancement, I believe it still helps maintainability to avoid using "goto" statements that do not provide some technical benefit. I have not built or tested this change, and I am aware that yesterday Greg K-H asked everyone to avoid device driver churn for untested code. So, I am not requesting integration without someone else trying it first. I am, however, posting this patch just in case anyone to try it at some point and then submit it upstream if it actually works and their are no complaints. I hereby release my copyright interest in this contribution to the public domain. Please let me know if anyone needs me to make any other statements with regard to this patch. Adam
diff --git a/arch/ia64/kernel/ftrace.c b/arch/ia64/kernel/ftrace.c index 7fc8c961b1f7..788f70ef5346 100644 --- a/arch/ia64/kernel/ftrace.c +++ b/arch/ia64/kernel/ftrace.c @@ -106,18 +106,17 @@ ftrace_modify_code(unsigned long ip, unsigned char *old_code, * kstop_machine, or before SMP starts. */ - if (!do_check) - goto skip_check; + if (do_check) { - /* read the text we want to modify */ - if (probe_kernel_read(replaced, (void *)ip, MCOUNT_INSN_SIZE)) - return -EFAULT; + /* read the text we want to modify */ + if (probe_kernel_read(replaced, (void *)ip, MCOUNT_INSN_SIZE)) + return -EFAULT; - /* Make sure it is what we expect it to be */ - if (memcmp(replaced, old_code, MCOUNT_INSN_SIZE) != 0) - return -EINVAL; + /* Make sure it is what we expect it to be */ + if (memcmp(replaced, old_code, MCOUNT_INSN_SIZE) != 0) + return -EINVAL; + } -skip_check: /* replace the text with the new text */ if (probe_kernel_write(((void *)ip), new_code, MCOUNT_INSN_SIZE)) return -EPERM;
![]() |