|
From: Ying X. <yin...@wi...> - 2017-02-20 11:39:47
|
To make it more conventional to hold subscription refcount in timer,
its policy is adjusted as follows:
Before sub->timer is started, subscription refcount is held; when
sub->timer is expired, subscription refcount will be decreased at the
end of the timer timeout function; when the timer is stopped, refcount
also needs to be decreased if the timer is still active.
Signed-off-by: Ying Xue <yin...@wi...>
---
net/tipc/subscr.c | 12 ++++++++----
1 file changed, 8 insertions(+), 4 deletions(-)
diff --git a/net/tipc/subscr.c b/net/tipc/subscr.c
index 111d33c6..ffd7b9d 100644
--- a/net/tipc/subscr.c
+++ b/net/tipc/subscr.c
@@ -241,8 +241,10 @@ static void tipc_subscrp_delete(struct tipc_subscription *sub)
{
u32 timeout = htohl(sub->evt.s.timeout, sub->swap);
- if (timeout == TIPC_WAIT_FOREVER || del_timer(&sub->timer))
+ if (timeout != TIPC_WAIT_FOREVER && del_timer(&sub->timer))
tipc_subscrp_put(sub);
+
+ tipc_subscrp_put(sub);
}
static void tipc_subscrp_cancel(struct tipc_subscr *s,
@@ -303,16 +305,18 @@ static void tipc_subscrp_subscribe(struct net *net, struct tipc_subscr *s,
spin_lock_bh(&subscriber->lock);
list_add(&sub->subscrp_list, &subscriber->subscrp_list);
+ tipc_subscrb_get(subscriber);
sub->subscriber = subscriber;
+
tipc_nametbl_subscribe(sub);
- tipc_subscrb_get(subscriber);
spin_unlock_bh(&subscriber->lock);
setup_timer(&sub->timer, tipc_subscrp_timeout, (unsigned long)sub);
timeout = htohl(sub->evt.s.timeout, swap);
- if (timeout != TIPC_WAIT_FOREVER)
- mod_timer(&sub->timer, jiffies + msecs_to_jiffies(timeout));
+ if ((timeout != TIPC_WAIT_FOREVER) &&
+ !mod_timer(&sub->timer, jiffies + msecs_to_jiffies(timeout)))
+ tipc_subscrp_get(sub);
}
/* Handle one termination request for the subscriber */
--
2.7.4
|