Re: + syscalls-x86-add-__nr_kcmp-syscall-v8.patch added to -mm tree

From: Oleg Nesterov
Date: Thu Feb 16 2012 - 09:58:04 EST


On 02/16, Cyrill Gorcunov wrote:
>
> +static int access_trylock(struct task_struct *task)
> +{
> + if (!mutex_trylock(&task->signal->cred_guard_mutex))
> + return -EBUSY;
> +
> + if (!ptrace_may_access(task, PTRACE_MODE_READ)) {
> + mutex_unlock(&task->signal->cred_guard_mutex);
> + return -EPERM;
> + }
> +
> + return 0;
> +}

OK, this looks correct, but I don't really understand _trylock.
This means the caller should always retry if -EBUSY, and
kcmp(pid, pid) can never succeed. Sure, kcmp() doesn't make
a lot of sense if pid1 == pid2, but this looks a bit strange.

You could simply do

int mutex_double_lock_killable(struct mutex *m1, struct mutex *m2)
{
int err;

if (m2 > m1)
swap(m1, m2);

err = mutex_lock_killable(m1);

if (!err && likely(m1 != m2)) {
err = mutex_lock_killable_nested(m2);
if (err)
mutex_unlock(m1);
}

return err;
}

but I won't unsist.

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/