All of lore.kernel.org
 help / color / mirror / Atom feed
* [Untested patch] ia64: Eliminate goto from ftrace_modify_code
@ 2019-04-28 22:21 Adam Richter
  0 siblings, 0 replies; only message in thread
From: Adam Richter @ 2019-04-28 22:21 UTC (permalink / raw)
  To: linux-ia64

[-- Attachment #1: Type: text/plain, Size: 1235 bytes --]

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

[-- Attachment #2: ia64_ftrace_modify_code.remove_goto.diff --]
[-- Type: text/x-diff, Size: 1014 bytes --]

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;

^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2019-04-28 22:21 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-04-28 22:21 [Untested patch] ia64: Eliminate goto from ftrace_modify_code Adam Richter

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.