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

tipc: adjust locking policy of subscription

Currently subscriber's lock protects not only subscriber's subscription
list but also all subscriptions linked into the list. However, as all
members of subscription are never changed after they are initialized,
it's unnecessary for subscription to be protected under subscriber's
lock. If the lock is used to only protect subscriber's subscription
list, the adjustment not only makes the locking policy simpler, but
also helps to avoid a deadlock which may happen once creating a
subscription is failed.

Signed-off-by: Ying Xue <ying.xue@windriver.com>
Reviewed-by: Jon Maloy <jon.maloy@ericson.com>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by

Ying Xue and committed by
David S. Miller
a13683f2 00bc00a9

+4 -2
+4 -2
net/tipc/subscr.c
··· 201 201 { 202 202 struct tipc_subscription *sub, *temp; 203 203 204 + spin_lock_bh(&subscriber->lock); 204 205 /* Find first matching subscription, exit if not found */ 205 206 list_for_each_entry_safe(sub, temp, &subscriber->subscrp_list, 206 207 subscrp_list) { ··· 213 212 break; 214 213 } 215 214 } 215 + spin_unlock_bh(&subscriber->lock); 216 216 } 217 217 218 218 static int tipc_subscrp_create(struct net *net, struct tipc_subscr *s, ··· 262 260 kfree(sub); 263 261 return -EINVAL; 264 262 } 263 + spin_lock_bh(&subscriber->lock); 265 264 list_add(&sub->subscrp_list, &subscriber->subscrp_list); 265 + spin_unlock_bh(&subscriber->lock); 266 266 sub->subscriber = subscriber; 267 267 sub->swap = swap; 268 268 memcpy(&sub->evt.s, s, sizeof(*s)); ··· 293 289 struct tipc_subscription *sub = NULL; 294 290 struct tipc_net *tn = net_generic(net, tipc_net_id); 295 291 296 - spin_lock_bh(&subscriber->lock); 297 292 tipc_subscrp_create(net, (struct tipc_subscr *)buf, subscriber, &sub); 298 293 if (sub) 299 294 tipc_nametbl_subscribe(sub); 300 295 else 301 296 tipc_conn_terminate(tn->topsrv, subscriber->conid); 302 - spin_unlock_bh(&subscriber->lock); 303 297 } 304 298 305 299 /* Handle one request to establish a new subscriber */