Re: [PATCH 2/3] rtmutex: Add rt_mutex_init_waiter helper

From: Peter Zijlstra
Date: Mon Mar 14 2016 - 09:16:35 EST


On Tue, Mar 08, 2016 at 10:20:22AM -0800, Davidlohr Bueso wrote:

> +++ b/kernel/futex.c
> @@ -2778,10 +2778,7 @@ static int futex_wait_requeue_pi(u32 __user *uaddr, unsigned int flags,
> * The waiter is allocated on our stack, manipulated by the requeue
> * code while we sleep on uaddr.
> */
> - debug_rt_mutex_init_waiter(&rt_waiter);
> - RB_CLEAR_NODE(&rt_waiter.pi_tree_entry);
> - RB_CLEAR_NODE(&rt_waiter.tree_entry);
> - rt_waiter.task = NULL;
> + rt_mutex_init_waiter(&rt_waiter);
>
> ret = get_futex_key(uaddr2, flags & FLAGS_SHARED, &key2, VERIFY_WRITE);
> if (unlikely(ret != 0))


> +static inline void
> +rt_mutex_init_waiter(struct rt_mutex_waiter *waiter)
> +{
> + debug_rt_mutex_init_waiter(waiter);
> +
> + RB_CLEAR_NODE(&waiter->pi_tree_entry);
> + RB_CLEAR_NODE(&waiter->tree_entry);
> + waiter->task = NULL;
> +}


Just thinking, would not something like:

#define DEFINE_RT_WAITER(name) \
struct rt_mutex_waiter name = { \
.tree_entry = __INIT_RB_NODE(name.tree_entry), \
.pi_tree_entry = __INIT_RB_NODE(name.pi_tree_entry), \
__INIT_RT_WAITER_DEBUG(name) \
}

Be nicer? That way we're sure the whole structure is initialized.