aboutsummaryrefslogtreecommitdiffstats
path: root/kernel/futex.c
diff options
context:
space:
mode:
authorDarren Hart <dvhart@linux.intel.com>2010-11-08 16:40:28 -0500
committerThomas Gleixner <tglx@linutronix.de>2010-11-10 09:01:34 -0500
commit5bdb05f91b27b9361c4f348a4e05999f597df72e (patch)
tree23d68ff7cdd469a6138b95aff37e6990b395eae9 /kernel/futex.c
parentb41277dc7a18ee332d9e8078e978bacdf6e76157 (diff)
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: Darren 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: Thomas Gleixner <tglx@linutronix.de>
Diffstat (limited to 'kernel/futex.c')
-rw-r--r--kernel/futex.c25
1 files changed, 10 insertions, 15 deletions
diff --git a/kernel/futex.c b/kernel/futex.c
index 87ad28746e17..3019b92e6917 100644
--- a/kernel/futex.c
+++ b/kernel/futex.c
@@ -131,6 +131,12 @@ struct futex_q {
131 u32 bitset; 131 u32 bitset;
132}; 132};
133 133
134static const struct futex_q futex_q_init = {
135 /* list gets initialized in queue_me()*/
136 .key = FUTEX_KEY_INIT,
137 .bitset = FUTEX_BITSET_MATCH_ANY
138};
139
134/* 140/*
135 * Hash buckets are shared by all the futex_keys that hash to the same 141 * Hash buckets are shared by all the futex_keys that hash to the same
136 * location. Each key may have multiple futex_q structures, one for each task 142 * 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,
1750 * rare, but normal. 1756 * rare, but normal.
1751 */ 1757 */
1752retry: 1758retry:
1753 q->key = FUTEX_KEY_INIT;
1754 ret = get_futex_key(uaddr, flags & FLAGS_SHARED, &q->key); 1759 ret = get_futex_key(uaddr, flags & FLAGS_SHARED, &q->key);
1755 if (unlikely(ret != 0)) 1760 if (unlikely(ret != 0))
1756 return ret; 1761 return ret;
@@ -1791,16 +1796,12 @@ static int futex_wait(u32 __user *uaddr, unsigned int flags, u32 val,
1791 struct hrtimer_sleeper timeout, *to = NULL; 1796 struct hrtimer_sleeper timeout, *to = NULL;
1792 struct restart_block *restart; 1797 struct restart_block *restart;
1793 struct futex_hash_bucket *hb; 1798 struct futex_hash_bucket *hb;
1794 struct futex_q q; 1799 struct futex_q q = futex_q_init;
1795 int ret; 1800 int ret;
1796 1801
1797 if (!bitset) 1802 if (!bitset)
1798 return -EINVAL; 1803 return -EINVAL;
1799
1800 q.pi_state = NULL;
1801 q.bitset = bitset; 1804 q.bitset = bitset;
1802 q.rt_waiter = NULL;
1803 q.requeue_pi_key = NULL;
1804 1805
1805 if (abs_time) { 1806 if (abs_time) {
1806 to = &timeout; 1807 to = &timeout;
@@ -1891,7 +1892,7 @@ static int futex_lock_pi(u32 __user *uaddr, unsigned int flags, int detect,
1891{ 1892{
1892 struct hrtimer_sleeper timeout, *to = NULL; 1893 struct hrtimer_sleeper timeout, *to = NULL;
1893 struct futex_hash_bucket *hb; 1894 struct futex_hash_bucket *hb;
1894 struct futex_q q; 1895 struct futex_q q = futex_q_init;
1895 int res, ret; 1896 int res, ret;
1896 1897
1897 if (refill_pi_state_cache()) 1898 if (refill_pi_state_cache())
@@ -1905,11 +1906,7 @@ static int futex_lock_pi(u32 __user *uaddr, unsigned int flags, int detect,
1905 hrtimer_set_expires(&to->timer, *time); 1906 hrtimer_set_expires(&to->timer, *time);
1906 } 1907 }
1907 1908
1908 q.pi_state = NULL;
1909 q.rt_waiter = NULL;
1910 q.requeue_pi_key = NULL;
1911retry: 1909retry:
1912 q.key = FUTEX_KEY_INIT;
1913 ret = get_futex_key(uaddr, flags & FLAGS_SHARED, &q.key); 1910 ret = get_futex_key(uaddr, flags & FLAGS_SHARED, &q.key);
1914 if (unlikely(ret != 0)) 1911 if (unlikely(ret != 0))
1915 goto out; 1912 goto out;
@@ -2197,8 +2194,8 @@ static int futex_wait_requeue_pi(u32 __user *uaddr, unsigned int flags,
2197 struct rt_mutex_waiter rt_waiter; 2194 struct rt_mutex_waiter rt_waiter;
2198 struct rt_mutex *pi_mutex = NULL; 2195 struct rt_mutex *pi_mutex = NULL;
2199 struct futex_hash_bucket *hb; 2196 struct futex_hash_bucket *hb;
2200 union futex_key key2; 2197 union futex_key key2 = FUTEX_KEY_INIT;
2201 struct futex_q q; 2198 struct futex_q q = futex_q_init;
2202 int res, ret; 2199 int res, ret;
2203 2200
2204 if (!bitset) 2201 if (!bitset)
@@ -2221,12 +2218,10 @@ static int futex_wait_requeue_pi(u32 __user *uaddr, unsigned int flags,
2221 debug_rt_mutex_init_waiter(&rt_waiter); 2218 debug_rt_mutex_init_waiter(&rt_waiter);
2222 rt_waiter.task = NULL; 2219 rt_waiter.task = NULL;
2223 2220
2224 key2 = FUTEX_KEY_INIT;
2225 ret = get_futex_key(uaddr2, flags & FLAGS_SHARED, &key2); 2221 ret = get_futex_key(uaddr2, flags & FLAGS_SHARED, &key2);
2226 if (unlikely(ret != 0)) 2222 if (unlikely(ret != 0))
2227 goto out; 2223 goto out;
2228 2224
2229 q.pi_state = NULL;
2230 q.bitset = bitset; 2225 q.bitset = bitset;
2231 q.rt_waiter = &rt_waiter; 2226 q.rt_waiter = &rt_waiter;
2232 q.requeue_pi_key = &key2; 2227 q.requeue_pi_key = &key2;