Skip to content

Commit 9fe7ed4

Browse files
ying-xuedavem330
authored andcommitted
tipc: remove all enabled flags from all tipc components
When tipc module is inserted, many tipc components are initialized one by one. During the initialization period, if one of them is failed, tipc_core_stop() will be called to stop all components whatever corresponding components are created or not. To avoid to release uncreated ones, relevant components have to add necessary enabled flags indicating whether they are created or not. But in the initialization stage, if one component is unsuccessfully created, we will just destroy successfully created components before the failed component instead of all components. All enabled flags defined in components, in turn, become redundant. Additionally it's also unnecessary to identify whether table.types is NULL in tipc_nametbl_stop() because name stable has been definitely created successfully when tipc_nametbl_stop() is called. Cc: Jon Maloy <jon.maloy@ericsson.com> Cc: Erik Hugne <erik.hugne@ericsson.com> Signed-off-by: Ying Xue <ying.xue@windriver.com> Reviewed-by: Paul Gortmaker <paul.gortmaker@windriver.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 7cce3b7 commit 9fe7ed4

7 files changed

Lines changed: 50 additions & 50 deletions

File tree

‎net/tipc/core.c‎

Lines changed: 50 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -122,30 +122,59 @@ static void tipc_core_stop(void)
122122
*/
123123
static int tipc_core_start(void)
124124
{
125-
int res;
125+
int err;
126126

127127
get_random_bytes(&tipc_random, sizeof(tipc_random));
128128

129-
res = tipc_handler_start();
130-
if (!res)
131-
res = tipc_ref_table_init(tipc_max_ports, tipc_random);
132-
if (!res)
133-
res = tipc_nametbl_init();
134-
if (!res)
135-
res = tipc_netlink_start();
136-
if (!res)
137-
res = tipc_socket_init();
138-
if (!res)
139-
res = tipc_register_sysctl();
140-
if (!res)
141-
res = tipc_subscr_start();
142-
if (!res)
143-
res = tipc_cfg_init();
144-
if (res) {
145-
tipc_handler_stop();
146-
tipc_core_stop();
147-
}
148-
return res;
129+
err = tipc_handler_start();
130+
if (err)
131+
goto out_handler;
132+
133+
err = tipc_ref_table_init(tipc_max_ports, tipc_random);
134+
if (err)
135+
goto out_reftbl;
136+
137+
err = tipc_nametbl_init();
138+
if (err)
139+
goto out_nametbl;
140+
141+
err = tipc_netlink_start();
142+
if (err)
143+
goto out_netlink;
144+
145+
err = tipc_socket_init();
146+
if (err)
147+
goto out_socket;
148+
149+
err = tipc_register_sysctl();
150+
if (err)
151+
goto out_sysctl;
152+
153+
err = tipc_subscr_start();
154+
if (err)
155+
goto out_subscr;
156+
157+
err = tipc_cfg_init();
158+
if (err)
159+
goto out_cfg;
160+
161+
return 0;
162+
out_cfg:
163+
tipc_subscr_stop();
164+
out_subscr:
165+
tipc_unregister_sysctl();
166+
out_sysctl:
167+
tipc_socket_stop();
168+
out_socket:
169+
tipc_netlink_stop();
170+
out_netlink:
171+
tipc_nametbl_stop();
172+
out_nametbl:
173+
tipc_ref_table_stop();
174+
out_reftbl:
175+
tipc_handler_stop();
176+
out_handler:
177+
return err;
149178
}
150179

151180
static int __init tipc_init(void)

‎net/tipc/name_table.c‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -945,9 +945,6 @@ void tipc_nametbl_stop(void)
945945
{
946946
u32 i;
947947

948-
if (!table.types)
949-
return;
950-
951948
/* Verify name table is empty, then release it */
952949
write_lock_bh(&tipc_nametbl_lock);
953950
for (i = 0; i < TIPC_NAMETBL_SIZE; i++) {

‎net/tipc/netlink.c‎

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,6 @@ static struct genl_ops tipc_genl_ops[] = {
8383
},
8484
};
8585

86-
static int tipc_genl_family_registered;
87-
8886
int tipc_netlink_start(void)
8987
{
9088
int res;
@@ -94,16 +92,10 @@ int tipc_netlink_start(void)
9492
pr_err("Failed to register netlink interface\n");
9593
return res;
9694
}
97-
98-
tipc_genl_family_registered = 1;
9995
return 0;
10096
}
10197

10298
void tipc_netlink_stop(void)
10399
{
104-
if (!tipc_genl_family_registered)
105-
return;
106-
107100
genl_unregister_family(&tipc_genl_family);
108-
tipc_genl_family_registered = 0;
109101
}

‎net/tipc/ref.c‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,9 +126,6 @@ int tipc_ref_table_init(u32 requested_size, u32 start)
126126
*/
127127
void tipc_ref_table_stop(void)
128128
{
129-
if (!tipc_ref_table.entries)
130-
return;
131-
132129
vfree(tipc_ref_table.entries);
133130
tipc_ref_table.entries = NULL;
134131
}

‎net/tipc/server.c‎

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -573,7 +573,6 @@ int tipc_server_start(struct tipc_server *s)
573573
kmem_cache_destroy(s->rcvbuf_cache);
574574
return ret;
575575
}
576-
s->enabled = 1;
577576
return ret;
578577
}
579578

@@ -583,10 +582,6 @@ void tipc_server_stop(struct tipc_server *s)
583582
int total = 0;
584583
int id;
585584

586-
if (!s->enabled)
587-
return;
588-
589-
s->enabled = 0;
590585
spin_lock_bh(&s->idr_lock);
591586
for (id = 0; total < s->idr_in_use; id++) {
592587
con = idr_find(&s->conn_idr, id);

‎net/tipc/server.h‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@
5656
* @name: server name
5757
* @imp: message importance
5858
* @type: socket type
59-
* @enabled: identify whether server is launched or not
6059
*/
6160
struct tipc_server {
6261
struct idr conn_idr;
@@ -74,7 +73,6 @@ struct tipc_server {
7473
const char name[TIPC_SERVER_NAME_LEN];
7574
int imp;
7675
int type;
77-
int enabled;
7876
};
7977

8078
int tipc_conn_sendmsg(struct tipc_server *s, int conid,

‎net/tipc/socket.c‎

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,6 @@ static const struct proto_ops msg_ops;
7070
static struct proto tipc_proto;
7171
static struct proto tipc_proto_kern;
7272

73-
static int sockets_enabled;
74-
7573
/*
7674
* Revised TIPC socket locking policy:
7775
*
@@ -2027,8 +2025,6 @@ int tipc_socket_init(void)
20272025
proto_unregister(&tipc_proto);
20282026
goto out;
20292027
}
2030-
2031-
sockets_enabled = 1;
20322028
out:
20332029
return res;
20342030
}
@@ -2038,10 +2034,6 @@ int tipc_socket_init(void)
20382034
*/
20392035
void tipc_socket_stop(void)
20402036
{
2041-
if (!sockets_enabled)
2042-
return;
2043-
2044-
sockets_enabled = 0;
20452037
sock_unregister(tipc_family_ops.family);
20462038
proto_unregister(&tipc_proto);
20472039
}

0 commit comments

Comments
 (0)