Skip to content

Commit

Permalink
ptrace_get_task_struct: s/tasklist/rcu/, make it static
Browse files Browse the repository at this point in the history
- Use rcu_read_lock() instead of tasklist_lock to find/get the task
  in ptrace_get_task_struct().

- Make it static, it has no callers outside of ptrace.c.

- The comment doesn't match the reality, this helper does not do
  any checks. Beacuse it is really trivial and static I removed the
  whole comment.

Signed-off-by: Oleg Nesterov <[email protected]>
Acked-by: Roland McGrath <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
oleg-nesterov authored and torvalds committed Jun 18, 2009
1 parent 4b105cb commit 8053bdd
Showing 2 changed files with 3 additions and 14 deletions.
1 change: 0 additions & 1 deletion include/linux/ptrace.h
Original file line number Diff line number Diff line change
@@ -81,7 +81,6 @@


extern long arch_ptrace(struct task_struct *child, long request, long addr, long data);
extern struct task_struct *ptrace_get_task_struct(pid_t pid);
extern int ptrace_traceme(void);
extern int ptrace_readdata(struct task_struct *tsk, unsigned long src, char __user *dst, int len);
extern int ptrace_writedata(struct task_struct *tsk, char __user *src, unsigned long dst, int len);
16 changes: 3 additions & 13 deletions kernel/ptrace.c
Original file line number Diff line number Diff line change
@@ -581,26 +581,16 @@ int ptrace_request(struct task_struct *child, long request,
return ret;
}

/**
* ptrace_get_task_struct -- grab a task struct reference for ptrace
* @pid: process id to grab a task_struct reference of
*
* This function is a helper for ptrace implementations. It checks
* permissions and then grabs a task struct for use of the actual
* ptrace implementation.
*
* Returns the task_struct for @pid or an ERR_PTR() on failure.
*/
struct task_struct *ptrace_get_task_struct(pid_t pid)
static struct task_struct *ptrace_get_task_struct(pid_t pid)
{
struct task_struct *child;

read_lock(&tasklist_lock);
rcu_read_lock();
child = find_task_by_vpid(pid);
if (child)
get_task_struct(child);
rcu_read_unlock();

read_unlock(&tasklist_lock);
if (!child)
return ERR_PTR(-ESRCH);
return child;

0 comments on commit 8053bdd

Please sign in to comment.