aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAllan Stephens <allan.stephens@windriver.com>2011-10-24 10:29:26 -0400
committerPaul Gortmaker <paul.gortmaker@windriver.com>2011-12-27 11:33:47 -0500
commitc47e9b918844ab7bb139eada7b085c576ddf0afb (patch)
tree492e8ac4c1191b1c7be865efacc7833ebcb6fff9
parent945af1c39df00a1e5873e38145432ba752ec49a0 (diff)
tipc: Eliminate dynamic allocation of broadcast link data structures
Creates global variables to hold the broadcast link's pseudo-bearer and pseudo-link structures, rather than allocating them dynamically. There is only a single instance of each structure, and changing over to static allocation allows elimination of code to handle the cases where dynamic allocation was unsuccessful. The memset in the teardown code may look like they aren't used, but the same teardown code is run when there is a non-fatal error at init-time, so that stale data isn't present when the user fixes the cause of the soft error. Signed-off-by: Allan Stephens <allan.stephens@windriver.com> Signed-off-by: Paul Gortmaker <paul.gortmaker@windriver.com>
-rw-r--r--net/tipc/bcast.c37
-rw-r--r--net/tipc/bcast.h2
-rw-r--r--net/tipc/net.c5
3 files changed, 13 insertions, 31 deletions
diff --git a/net/tipc/bcast.c b/net/tipc/bcast.c
index 28908f54459e..738cb642d31b 100644
--- a/net/tipc/bcast.c
+++ b/net/tipc/bcast.c
@@ -98,10 +98,13 @@ struct bclink {
98 struct tipc_node *retransmit_to; 98 struct tipc_node *retransmit_to;
99}; 99};
100 100
101static struct bcbearer bcast_bearer;
102static struct bclink bcast_link;
103
104static struct bcbearer *bcbearer = &bcast_bearer;
105static struct bclink *bclink = &bcast_link;
106static struct link *bcl = &bcast_link.link;
101 107
102static struct bcbearer *bcbearer;
103static struct bclink *bclink;
104static struct link *bcl;
105static DEFINE_SPINLOCK(bc_lock); 108static DEFINE_SPINLOCK(bc_lock);
106 109
107/* broadcast-capable node map */ 110/* broadcast-capable node map */
@@ -752,25 +755,13 @@ int tipc_bclink_set_queue_limits(u32 limit)
752 return 0; 755 return 0;
753} 756}
754 757
755int tipc_bclink_init(void) 758void tipc_bclink_init(void)
756{ 759{
757 bcbearer = kzalloc(sizeof(*bcbearer), GFP_ATOMIC);
758 bclink = kzalloc(sizeof(*bclink), GFP_ATOMIC);
759 if (!bcbearer || !bclink) {
760 warn("Broadcast link creation failed, no memory\n");
761 kfree(bcbearer);
762 bcbearer = NULL;
763 kfree(bclink);
764 bclink = NULL;
765 return -ENOMEM;
766 }
767
768 INIT_LIST_HEAD(&bcbearer->bearer.cong_links); 760 INIT_LIST_HEAD(&bcbearer->bearer.cong_links);
769 bcbearer->bearer.media = &bcbearer->media; 761 bcbearer->bearer.media = &bcbearer->media;
770 bcbearer->media.send_msg = tipc_bcbearer_send; 762 bcbearer->media.send_msg = tipc_bcbearer_send;
771 sprintf(bcbearer->media.name, "tipc-broadcast"); 763 sprintf(bcbearer->media.name, "tipc-broadcast");
772 764
773 bcl = &bclink->link;
774 INIT_LIST_HEAD(&bcl->waiting_ports); 765 INIT_LIST_HEAD(&bcl->waiting_ports);
775 bcl->next_out_no = 1; 766 bcl->next_out_no = 1;
776 spin_lock_init(&bclink->node.lock); 767 spin_lock_init(&bclink->node.lock);
@@ -780,22 +771,16 @@ int tipc_bclink_init(void)
780 bcl->b_ptr = &bcbearer->bearer; 771 bcl->b_ptr = &bcbearer->bearer;
781 bcl->state = WORKING_WORKING; 772 bcl->state = WORKING_WORKING;
782 strlcpy(bcl->name, tipc_bclink_name, TIPC_MAX_LINK_NAME); 773 strlcpy(bcl->name, tipc_bclink_name, TIPC_MAX_LINK_NAME);
783
784 return 0;
785} 774}
786 775
787void tipc_bclink_stop(void) 776void tipc_bclink_stop(void)
788{ 777{
789 spin_lock_bh(&bc_lock); 778 spin_lock_bh(&bc_lock);
790 if (bcbearer) { 779 tipc_link_stop(bcl);
791 tipc_link_stop(bcl);
792 bcl = NULL;
793 kfree(bclink);
794 bclink = NULL;
795 kfree(bcbearer);
796 bcbearer = NULL;
797 }
798 spin_unlock_bh(&bc_lock); 780 spin_unlock_bh(&bc_lock);
781
782 memset(bclink, 0, sizeof(*bclink));
783 memset(bcbearer, 0, sizeof(*bcbearer));
799} 784}
800 785
801 786
diff --git a/net/tipc/bcast.h b/net/tipc/bcast.h
index 06740da5ae61..0b0444363b45 100644
--- a/net/tipc/bcast.h
+++ b/net/tipc/bcast.h
@@ -88,7 +88,7 @@ static inline int tipc_nmap_equal(struct tipc_node_map *nm_a, struct tipc_node_m
88void tipc_port_list_add(struct port_list *pl_ptr, u32 port); 88void tipc_port_list_add(struct port_list *pl_ptr, u32 port);
89void tipc_port_list_free(struct port_list *pl_ptr); 89void tipc_port_list_free(struct port_list *pl_ptr);
90 90
91int tipc_bclink_init(void); 91void tipc_bclink_init(void);
92void tipc_bclink_stop(void); 92void tipc_bclink_stop(void);
93struct tipc_node *tipc_bclink_retransmit_to(void); 93struct tipc_node *tipc_bclink_retransmit_to(void);
94void tipc_bclink_acknowledge(struct tipc_node *n_ptr, u32 acked); 94void tipc_bclink_acknowledge(struct tipc_node *n_ptr, u32 acked);
diff --git a/net/tipc/net.c b/net/tipc/net.c
index e13162fc61cf..61afee7e8291 100644
--- a/net/tipc/net.c
+++ b/net/tipc/net.c
@@ -174,7 +174,6 @@ void tipc_net_route_msg(struct sk_buff *buf)
174int tipc_net_start(u32 addr) 174int tipc_net_start(u32 addr)
175{ 175{
176 char addr_string[16]; 176 char addr_string[16];
177 int res;
178 177
179 if (tipc_mode != TIPC_NODE_MODE) 178 if (tipc_mode != TIPC_NODE_MODE)
180 return -ENOPROTOOPT; 179 return -ENOPROTOOPT;
@@ -187,9 +186,7 @@ int tipc_net_start(u32 addr)
187 tipc_named_reinit(); 186 tipc_named_reinit();
188 tipc_port_reinit(); 187 tipc_port_reinit();
189 188
190 res = tipc_bclink_init(); 189 tipc_bclink_init();
191 if (res)
192 return res;
193 190
194 tipc_k_signal((Handler)tipc_subscr_start, 0); 191 tipc_k_signal((Handler)tipc_subscr_start, 0);
195 tipc_k_signal((Handler)tipc_cfg_init, 0); 192 tipc_k_signal((Handler)tipc_cfg_init, 0);