Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 5bdb05f9 authored by Darren Hart's avatar Darren Hart Committed by Thomas Gleixner
Browse files

futex: Add futex_q static initializer



The futex_q struct has grown considerably over the last couple years. I
believe it now merits a static initializer to avoid uninitialized data
errors (having spent more time than I care to admit debugging an uninitialized
q.bitset in an experimental new op code).

With the key initializer built in, several of the FUTEX_KEY_INIT calls can
be removed.

V2: use a static variable instead of an init macro.
    use a C99 initializer and don't rely on variable ordering in the struct.
V3: make futex_q_init const

Signed-off-by: default avatarDarren Hart <dvhart@linux.intel.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Eric Dumazet <eric.dumazet@gmail.com>
Cc: John Kacur <jkacur@redhat.com>
Cc: Ingo Molnar <mingo@elte.hu>
LKML-Reference: <1289252428-18383-1-git-send-email-dvhart@linux.intel.com>
Signed-off-by: default avatarThomas Gleixner <tglx@linutronix.de>
parent b41277dc
Loading
Loading
Loading
Loading
+10 −15
Original line number Original line Diff line number Diff line
@@ -131,6 +131,12 @@ struct futex_q {
	u32 bitset;
	u32 bitset;
};
};


static const struct futex_q futex_q_init = {
	/* list gets initialized in queue_me()*/
	.key = FUTEX_KEY_INIT,
	.bitset = FUTEX_BITSET_MATCH_ANY
};

/*
/*
 * Hash buckets are shared by all the futex_keys that hash to the same
 * Hash buckets are shared by all the futex_keys that hash to the same
 * location.  Each key may have multiple futex_q structures, one for each task
 * location.  Each key may have multiple futex_q structures, one for each task
@@ -1750,7 +1756,6 @@ static int futex_wait_setup(u32 __user *uaddr, u32 val, unsigned int flags,
	 * rare, but normal.
	 * rare, but normal.
	 */
	 */
retry:
retry:
	q->key = FUTEX_KEY_INIT;
	ret = get_futex_key(uaddr, flags & FLAGS_SHARED, &q->key);
	ret = get_futex_key(uaddr, flags & FLAGS_SHARED, &q->key);
	if (unlikely(ret != 0))
	if (unlikely(ret != 0))
		return ret;
		return ret;
@@ -1791,16 +1796,12 @@ static int futex_wait(u32 __user *uaddr, unsigned int flags, u32 val,
	struct hrtimer_sleeper timeout, *to = NULL;
	struct hrtimer_sleeper timeout, *to = NULL;
	struct restart_block *restart;
	struct restart_block *restart;
	struct futex_hash_bucket *hb;
	struct futex_hash_bucket *hb;
	struct futex_q q;
	struct futex_q q = futex_q_init;
	int ret;
	int ret;


	if (!bitset)
	if (!bitset)
		return -EINVAL;
		return -EINVAL;

	q.pi_state = NULL;
	q.bitset = bitset;
	q.bitset = bitset;
	q.rt_waiter = NULL;
	q.requeue_pi_key = NULL;


	if (abs_time) {
	if (abs_time) {
		to = &timeout;
		to = &timeout;
@@ -1891,7 +1892,7 @@ static int futex_lock_pi(u32 __user *uaddr, unsigned int flags, int detect,
{
{
	struct hrtimer_sleeper timeout, *to = NULL;
	struct hrtimer_sleeper timeout, *to = NULL;
	struct futex_hash_bucket *hb;
	struct futex_hash_bucket *hb;
	struct futex_q q;
	struct futex_q q = futex_q_init;
	int res, ret;
	int res, ret;


	if (refill_pi_state_cache())
	if (refill_pi_state_cache())
@@ -1905,11 +1906,7 @@ static int futex_lock_pi(u32 __user *uaddr, unsigned int flags, int detect,
		hrtimer_set_expires(&to->timer, *time);
		hrtimer_set_expires(&to->timer, *time);
	}
	}


	q.pi_state = NULL;
	q.rt_waiter = NULL;
	q.requeue_pi_key = NULL;
retry:
retry:
	q.key = FUTEX_KEY_INIT;
	ret = get_futex_key(uaddr, flags & FLAGS_SHARED, &q.key);
	ret = get_futex_key(uaddr, flags & FLAGS_SHARED, &q.key);
	if (unlikely(ret != 0))
	if (unlikely(ret != 0))
		goto out;
		goto out;
@@ -2197,8 +2194,8 @@ static int futex_wait_requeue_pi(u32 __user *uaddr, unsigned int flags,
	struct rt_mutex_waiter rt_waiter;
	struct rt_mutex_waiter rt_waiter;
	struct rt_mutex *pi_mutex = NULL;
	struct rt_mutex *pi_mutex = NULL;
	struct futex_hash_bucket *hb;
	struct futex_hash_bucket *hb;
	union futex_key key2;
	union futex_key key2 = FUTEX_KEY_INIT;
	struct futex_q q;
	struct futex_q q = futex_q_init;
	int res, ret;
	int res, ret;


	if (!bitset)
	if (!bitset)
@@ -2221,12 +2218,10 @@ static int futex_wait_requeue_pi(u32 __user *uaddr, unsigned int flags,
	debug_rt_mutex_init_waiter(&rt_waiter);
	debug_rt_mutex_init_waiter(&rt_waiter);
	rt_waiter.task = NULL;
	rt_waiter.task = NULL;


	key2 = FUTEX_KEY_INIT;
	ret = get_futex_key(uaddr2, flags & FLAGS_SHARED, &key2);
	ret = get_futex_key(uaddr2, flags & FLAGS_SHARED, &key2);
	if (unlikely(ret != 0))
	if (unlikely(ret != 0))
		goto out;
		goto out;


	q.pi_state = NULL;
	q.bitset = bitset;
	q.bitset = bitset;
	q.rt_waiter = &rt_waiter;
	q.rt_waiter = &rt_waiter;
	q.requeue_pi_key = &key2;
	q.requeue_pi_key = &key2;