Re: [RFC PATCH 4/12 v2] ptrace: introduce the empty "structptrace_context"

From: Oleg Nesterov
Date: Fri May 29 2009 - 07:57:58 EST


On 05/28, Roland McGrath wrote:
>
> > + task_lock(tsk);
> > + if (likely(!tsk->ptrace_ctx))
> > + tsk->ptrace_ctx = ptrace_ctx;
> > + else
> > + kfree(ptrace_ctx);
> > + task_unlock(tsk);
>
> I don't think it's kosher call kfree with task_lock() held.

Yes, it always makes sense to move as much as possible outside of
spin_lock/etc, but

> The kfree case is a very unlikely path,

Exactly, this kfree() "never" runs under task_lock(), but the code
looks a bit simpler and shorter.

> so it can be:
>
> task_lock(tsk);
> if (likely(!tsk->ptrace_ctx)) {
> tsk->ptrace_ctx = ptrace_ctx;
> task_unlock(tsk);
> return 0;
> }
>
> task_unlock(tsk);
> kfree(ptrace_ctx);

OK, will change.

Oleg.

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/