Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

kprobe: Simplify prepare_kprobe() by dropping redundant version

The function prepare_kprobe() is called during kprobe registration and
is responsible for ensuring any architecture related preparation for
the kprobe is done before returning.

One of two versions of prepare_kprobe() is chosen depending on the
availability of KPROBE_ON_FTRACE in the kernel configuration.

Simplify the code by dropping the version when KPROBE_ON_FTRACE is not
selected - instead relying on kprobe_ftrace() to return false when
KPROBE_ON_FTRACE is not set.

No functional change.

Link: https://lkml.kernel.org/r/163163033696.489837.9264661820279300788.stgit@devnote2

Signed-off-by: Punit Agrawal <punitagrawal@gmail.com>
Acked-by: Masami Hiramatsu <mhiramat@kernel.org>
Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org>
Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>

authored by

Punit Agrawal and committed by
Steven Rostedt (VMware)
02afb8d6 5d6de7d7

+14 -14
+5
include/linux/kprobes.h
··· 354 354 extern void kprobe_ftrace_handler(unsigned long ip, unsigned long parent_ip, 355 355 struct ftrace_ops *ops, struct ftrace_regs *fregs); 356 356 extern int arch_prepare_kprobe_ftrace(struct kprobe *p); 357 + #else 358 + static inline int arch_prepare_kprobe_ftrace(struct kprobe *p) 359 + { 360 + return -EINVAL; 361 + } 357 362 #endif 358 363 359 364 int arch_check_ftrace_location(struct kprobe *p);
+9 -14
kernel/kprobes.c
··· 1033 1033 static int kprobe_ipmodify_enabled; 1034 1034 static int kprobe_ftrace_enabled; 1035 1035 1036 - /* Must ensure p->addr is really on ftrace */ 1037 - static int prepare_kprobe(struct kprobe *p) 1038 - { 1039 - if (!kprobe_ftrace(p)) 1040 - return arch_prepare_kprobe(p); 1041 - 1042 - return arch_prepare_kprobe_ftrace(p); 1043 - } 1044 - 1045 1036 /* Caller must lock kprobe_mutex */ 1046 1037 static int __arm_kprobe_ftrace(struct kprobe *p, struct ftrace_ops *ops, 1047 1038 int *cnt) ··· 1104 1113 ipmodify ? &kprobe_ipmodify_enabled : &kprobe_ftrace_enabled); 1105 1114 } 1106 1115 #else /* !CONFIG_KPROBES_ON_FTRACE */ 1107 - static inline int prepare_kprobe(struct kprobe *p) 1108 - { 1109 - return arch_prepare_kprobe(p); 1110 - } 1111 - 1112 1116 static inline int arm_kprobe_ftrace(struct kprobe *p) 1113 1117 { 1114 1118 return -ENODEV; ··· 1114 1128 return -ENODEV; 1115 1129 } 1116 1130 #endif 1131 + 1132 + static int prepare_kprobe(struct kprobe *p) 1133 + { 1134 + /* Must ensure p->addr is really on ftrace */ 1135 + if (kprobe_ftrace(p)) 1136 + return arch_prepare_kprobe_ftrace(p); 1137 + 1138 + return arch_prepare_kprobe(p); 1139 + } 1117 1140 1118 1141 /* Arm a kprobe with text_mutex */ 1119 1142 static int arm_kprobe(struct kprobe *kp)