Skip to content

Commit 128161f

Browse files
committed
ftrace: Add helper find_direct_entry() to consolidate code
Both unregister_ftrace_direct() and modify_ftrace_direct() needs to normalize the ip passed in to match the rec->ip, as it is acceptable to have the ip on the ftrace call site but not the start. There are also common validity checks with the record found by the ip, these should be done for both unregister_ftrace_direct() and modify_ftrace_direct(). Signed-off-by: Steven Rostedt (VMware) <[email protected]>
1 parent 406acdd commit 128161f

File tree

1 file changed

+29
-30
lines changed

1 file changed

+29
-30
lines changed

kernel/trace/ftrace.c

Lines changed: 29 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -5112,30 +5112,40 @@ int register_ftrace_direct(unsigned long ip, unsigned long addr)
51125112
}
51135113
EXPORT_SYMBOL_GPL(register_ftrace_direct);
51145114

5115-
int unregister_ftrace_direct(unsigned long ip, unsigned long addr)
5115+
static struct ftrace_func_entry *find_direct_entry(unsigned long *ip)
51165116
{
51175117
struct ftrace_func_entry *entry;
5118-
struct ftrace_direct_func *direct;
51195118
struct dyn_ftrace *rec;
5120-
int ret = -ENODEV;
51215119

5122-
mutex_lock(&direct_mutex);
5120+
rec = lookup_rec(*ip, *ip);
5121+
if (!rec)
5122+
return NULL;
51235123

5124-
entry = __ftrace_lookup_ip(direct_functions, ip);
5124+
entry = __ftrace_lookup_ip(direct_functions, rec->ip);
51255125
if (!entry) {
5126-
/* OK if it is off by a little */
5127-
rec = lookup_rec(ip, ip);
5128-
if (!rec || rec->ip == ip)
5129-
goto out_unlock;
5126+
WARN_ON(rec->flags & FTRACE_FL_DIRECT);
5127+
return NULL;
5128+
}
51305129

5131-
entry = __ftrace_lookup_ip(direct_functions, rec->ip);
5132-
if (!entry) {
5133-
WARN_ON(rec->flags & FTRACE_FL_DIRECT);
5134-
goto out_unlock;
5135-
}
5130+
WARN_ON(!(rec->flags & FTRACE_FL_DIRECT));
51365131

5137-
WARN_ON(!(rec->flags & FTRACE_FL_DIRECT));
5138-
}
5132+
/* Passed in ip just needs to be on the call site */
5133+
*ip = rec->ip;
5134+
5135+
return entry;
5136+
}
5137+
5138+
int unregister_ftrace_direct(unsigned long ip, unsigned long addr)
5139+
{
5140+
struct ftrace_direct_func *direct;
5141+
struct ftrace_func_entry *entry;
5142+
int ret = -ENODEV;
5143+
5144+
mutex_lock(&direct_mutex);
5145+
5146+
entry = find_direct_entry(&ip);
5147+
if (!entry)
5148+
goto out_unlock;
51395149

51405150
if (direct_functions->count == 1)
51415151
unregister_ftrace_function(&direct_ops);
@@ -5187,24 +5197,13 @@ int modify_ftrace_direct(unsigned long ip,
51875197
unsigned long old_addr, unsigned long new_addr)
51885198
{
51895199
struct ftrace_func_entry *entry;
5190-
struct dyn_ftrace *rec;
51915200
int ret = -ENODEV;
51925201

51935202
mutex_lock(&direct_mutex);
5194-
entry = __ftrace_lookup_ip(direct_functions, ip);
5195-
if (!entry) {
5196-
/* OK if it is off by a little */
5197-
rec = lookup_rec(ip, ip);
5198-
if (!rec || rec->ip == ip)
5199-
goto out_unlock;
5200-
5201-
entry = __ftrace_lookup_ip(direct_functions, rec->ip);
5202-
if (!entry)
5203-
goto out_unlock;
52045203

5205-
ip = rec->ip;
5206-
WARN_ON(!(rec->flags & FTRACE_FL_DIRECT));
5207-
}
5204+
entry = find_direct_entry(&ip);
5205+
if (!entry)
5206+
goto out_unlock;
52085207

52095208
ret = -EINVAL;
52105209
if (entry->direct != old_addr)

0 commit comments

Comments
 (0)