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

Commit a13683f2 authored by Ying Xue's avatar Ying Xue Committed by David S. Miller
Browse files

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: default avatarYing Xue <ying.xue@windriver.com>
Reviewed-by: default avatarJon Maloy <jon.maloy@ericson.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 00bc00a9
Loading
Loading
Loading
Loading
+4 −2
Original line number Original line Diff line number Diff line
@@ -201,6 +201,7 @@ static void tipc_subscrp_cancel(struct tipc_subscr *s,
{
{
	struct tipc_subscription *sub, *temp;
	struct tipc_subscription *sub, *temp;


	spin_lock_bh(&subscriber->lock);
	/* Find first matching subscription, exit if not found */
	/* Find first matching subscription, exit if not found */
	list_for_each_entry_safe(sub, temp, &subscriber->subscrp_list,
	list_for_each_entry_safe(sub, temp, &subscriber->subscrp_list,
				 subscrp_list) {
				 subscrp_list) {
@@ -212,6 +213,7 @@ static void tipc_subscrp_cancel(struct tipc_subscr *s,
			break;
			break;
		}
		}
	}
	}
	spin_unlock_bh(&subscriber->lock);
}
}


static int tipc_subscrp_create(struct net *net, struct tipc_subscr *s,
static int tipc_subscrp_create(struct net *net, struct tipc_subscr *s,
@@ -260,7 +262,9 @@ static int tipc_subscrp_create(struct net *net, struct tipc_subscr *s,
		kfree(sub);
		kfree(sub);
		return -EINVAL;
		return -EINVAL;
	}
	}
	spin_lock_bh(&subscriber->lock);
	list_add(&sub->subscrp_list, &subscriber->subscrp_list);
	list_add(&sub->subscrp_list, &subscriber->subscrp_list);
	spin_unlock_bh(&subscriber->lock);
	sub->subscriber = subscriber;
	sub->subscriber = subscriber;
	sub->swap = swap;
	sub->swap = swap;
	memcpy(&sub->evt.s, s, sizeof(*s));
	memcpy(&sub->evt.s, s, sizeof(*s));
@@ -289,13 +293,11 @@ static void tipc_subscrb_rcv_cb(struct net *net, int conid,
	struct tipc_subscription *sub = NULL;
	struct tipc_subscription *sub = NULL;
	struct tipc_net *tn = net_generic(net, tipc_net_id);
	struct tipc_net *tn = net_generic(net, tipc_net_id);


	spin_lock_bh(&subscriber->lock);
	tipc_subscrp_create(net, (struct tipc_subscr *)buf, subscriber, &sub);
	tipc_subscrp_create(net, (struct tipc_subscr *)buf, subscriber, &sub);
	if (sub)
	if (sub)
		tipc_nametbl_subscribe(sub);
		tipc_nametbl_subscribe(sub);
	else
	else
		tipc_conn_terminate(tn->topsrv, subscriber->conid);
		tipc_conn_terminate(tn->topsrv, subscriber->conid);
	spin_unlock_bh(&subscriber->lock);
}
}


/* Handle one request to establish a new subscriber */
/* Handle one request to establish a new subscriber */