Skip to content

Commit 242e82c

Browse files
Jon Maloydavem330
authored andcommitted
tipc: collapse subscription creation functions
After the previous changes it becomes logical to collapse the two-level creation of subscription instances into one. We do that here. We also rename the creation and deletion functions for more consistency. Acked-by: Ying Xue <[email protected]> Signed-off-by: Jon Maloy <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 8985ecc commit 242e82c

File tree

4 files changed

+22
-43
lines changed

4 files changed

+22
-43
lines changed

net/tipc/server.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ static void tipc_con_delete_sub(struct tipc_conn *con, struct tipc_subscr *s)
203203
spin_lock_bh(&con->sub_lock);
204204
list_for_each_entry_safe(sub, tmp, sub_list, subscrp_list) {
205205
if (!s || !memcmp(s, &sub->evt.s, sizeof(*s)))
206-
tipc_sub_delete(sub);
206+
tipc_sub_unsubscribe(sub);
207207
else if (s)
208208
break;
209209
}
@@ -278,7 +278,7 @@ static int tipc_con_rcv_sub(struct tipc_server *srv,
278278
tipc_con_delete_sub(con, s);
279279
return 0;
280280
}
281-
sub = tipc_subscrp_subscribe(srv, s, con->conid);
281+
sub = tipc_sub_subscribe(srv, s, con->conid);
282282
if (!sub)
283283
return -1;
284284

net/tipc/server.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
* net/tipc/server.h: Include file for TIPC server code
33
*
44
* Copyright (c) 2012-2013, Wind River Systems
5+
* Copyright (c) 2017, Ericsson AB
56
* All rights reserved.
67
*
78
* Redistribution and use in source and binary forms, with or without

net/tipc/subscr.c

Lines changed: 12 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -134,58 +134,36 @@ void tipc_subscrp_get(struct tipc_subscription *subscription)
134134
kref_get(&subscription->kref);
135135
}
136136

137-
static struct tipc_subscription *tipc_subscrp_create(struct tipc_server *srv,
138-
struct tipc_subscr *s,
139-
int conid)
137+
struct tipc_subscription *tipc_sub_subscribe(struct tipc_server *srv,
138+
struct tipc_subscr *s,
139+
int conid)
140140
{
141141
struct tipc_net *tn = tipc_net(srv->net);
142142
struct tipc_subscription *sub;
143143
u32 filter = tipc_sub_read(s, filter);
144+
u32 timeout;
144145

145-
/* Refuse subscription if global limit exceeded */
146-
if (atomic_read(&tn->subscription_count) >= TIPC_MAX_SUBSCRIPTIONS) {
147-
pr_warn("Subscription rejected, limit reached (%u)\n",
148-
TIPC_MAX_SUBSCRIPTIONS);
146+
if (atomic_read(&tn->subscription_count) >= TIPC_MAX_SUBSCR) {
147+
pr_warn("Subscription rejected, max (%u)\n", TIPC_MAX_SUBSCR);
148+
return NULL;
149+
}
150+
if ((filter & TIPC_SUB_PORTS && filter & TIPC_SUB_SERVICE) ||
151+
(tipc_sub_read(s, seq.lower) > tipc_sub_read(s, seq.upper))) {
152+
pr_warn("Subscription rejected, illegal request\n");
149153
return NULL;
150154
}
151-
152-
/* Allocate subscription object */
153155
sub = kmalloc(sizeof(*sub), GFP_ATOMIC);
154156
if (!sub) {
155157
pr_warn("Subscription rejected, no memory\n");
156158
return NULL;
157159
}
158-
159-
/* Initialize subscription object */
160-
if (filter & TIPC_SUB_PORTS && filter & TIPC_SUB_SERVICE)
161-
goto err;
162-
if (tipc_sub_read(s, seq.lower) > tipc_sub_read(s, seq.upper))
163-
goto err;
164160
sub->server = srv;
165161
sub->conid = conid;
166162
sub->inactive = false;
167163
memcpy(&sub->evt.s, s, sizeof(*s));
168164
spin_lock_init(&sub->lock);
169165
atomic_inc(&tn->subscription_count);
170166
kref_init(&sub->kref);
171-
return sub;
172-
err:
173-
pr_warn("Subscription rejected, illegal request\n");
174-
kfree(sub);
175-
return NULL;
176-
}
177-
178-
struct tipc_subscription *tipc_subscrp_subscribe(struct tipc_server *srv,
179-
struct tipc_subscr *s,
180-
int conid)
181-
{
182-
struct tipc_subscription *sub = NULL;
183-
u32 timeout;
184-
185-
sub = tipc_subscrp_create(srv, s, conid);
186-
if (!sub)
187-
return NULL;
188-
189167
tipc_nametbl_subscribe(sub);
190168
timer_setup(&sub->timer, tipc_subscrp_timeout, 0);
191169
timeout = tipc_sub_read(&sub->evt.s, timeout);
@@ -194,7 +172,7 @@ struct tipc_subscription *tipc_subscrp_subscribe(struct tipc_server *srv,
194172
return sub;
195173
}
196174

197-
void tipc_sub_delete(struct tipc_subscription *sub)
175+
void tipc_sub_unsubscribe(struct tipc_subscription *sub)
198176
{
199177
tipc_nametbl_unsubscribe(sub);
200178
if (sub->evt.s.timeout != TIPC_WAIT_FOREVER)

net/tipc/subscr.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* net/tipc/subscr.h: Include file for TIPC network topology service
33
*
4-
* Copyright (c) 2003-2006, Ericsson AB
4+
* Copyright (c) 2003-2017, Ericsson AB
55
* Copyright (c) 2005-2007, 2012-2013, Wind River Systems
66
* All rights reserved.
77
*
@@ -39,8 +39,8 @@
3939

4040
#include "server.h"
4141

42-
#define TIPC_MAX_SUBSCRIPTIONS 65535
43-
#define TIPC_MAX_PUBLICATIONS 65535
42+
#define TIPC_MAX_SUBSCR 65535
43+
#define TIPC_MAX_PUBLICATIONS 65535
4444

4545
struct tipc_subscription;
4646
struct tipc_conn;
@@ -66,10 +66,10 @@ struct tipc_subscription {
6666
spinlock_t lock; /* serialize up/down and timer events */
6767
};
6868

69-
struct tipc_subscription *tipc_subscrp_subscribe(struct tipc_server *srv,
70-
struct tipc_subscr *s,
71-
int conid);
72-
void tipc_sub_delete(struct tipc_subscription *sub);
69+
struct tipc_subscription *tipc_sub_subscribe(struct tipc_server *srv,
70+
struct tipc_subscr *s,
71+
int conid);
72+
void tipc_sub_unsubscribe(struct tipc_subscription *sub);
7373

7474
int tipc_subscrp_check_overlap(struct tipc_name_seq *seq, u32 found_lower,
7575
u32 found_upper);

0 commit comments

Comments
 (0)