Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

xfrm: remove useless hash_resize_mutex locks

In xfrm_state.c, hash_resize_mutex is defined as a local variable
and only used in xfrm_hash_resize() which is declared as a work
handler of xfrm.state_hash_work. But when the xfrm.state_hash_work
work is put in the global workqueue(system_wq) with schedule_work(),
the work will be really inserted in the global workqueue if it was
not already queued, otherwise, it is still left in the same position
on the the global workqueue. This means the xfrm_hash_resize() work
handler is only executed once at any time no matter how many times
its work is scheduled, that is, xfrm_hash_resize() is not called
concurrently at all, so hash_resize_mutex is redundant for us.

Cc: Christophe Gouault <christophe.gouault@6wind.com>
Cc: Steffen Klassert <steffen.klassert@secunet.com>
Signed-off-by: Ying Xue <ying.xue@windriver.com>
Acked-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Steffen Klassert <steffen.klassert@secunet.com>

authored by

Ying Xue and committed by
Steffen Klassert
0244790c a3d12146

+3 -10
+3 -10
net/xfrm/xfrm_state.c
··· 97 97 return ((state_hmask + 1) << 1) * sizeof(struct hlist_head); 98 98 } 99 99 100 - static DEFINE_MUTEX(hash_resize_mutex); 101 - 102 100 static void xfrm_hash_resize(struct work_struct *work) 103 101 { 104 102 struct net *net = container_of(work, struct net, xfrm.state_hash_work); ··· 105 107 unsigned int nhashmask, ohashmask; 106 108 int i; 107 109 108 - mutex_lock(&hash_resize_mutex); 109 - 110 110 nsize = xfrm_hash_new_size(net->xfrm.state_hmask); 111 111 ndst = xfrm_hash_alloc(nsize); 112 112 if (!ndst) 113 - goto out_unlock; 113 + return; 114 114 nsrc = xfrm_hash_alloc(nsize); 115 115 if (!nsrc) { 116 116 xfrm_hash_free(ndst, nsize); 117 - goto out_unlock; 117 + return; 118 118 } 119 119 nspi = xfrm_hash_alloc(nsize); 120 120 if (!nspi) { 121 121 xfrm_hash_free(ndst, nsize); 122 122 xfrm_hash_free(nsrc, nsize); 123 - goto out_unlock; 123 + return; 124 124 } 125 125 126 126 spin_lock_bh(&net->xfrm.xfrm_state_lock); ··· 144 148 xfrm_hash_free(odst, osize); 145 149 xfrm_hash_free(osrc, osize); 146 150 xfrm_hash_free(ospi, osize); 147 - 148 - out_unlock: 149 - mutex_unlock(&hash_resize_mutex); 150 151 } 151 152 152 153 static DEFINE_SPINLOCK(xfrm_state_afinfo_lock);