aboutsummaryrefslogtreecommitdiffstats
path: root/net/tipc/bearer.c
diff options
context:
space:
mode:
authorAllan Stephens <allan.stephens@windriver.com>2011-10-06 16:40:55 -0400
committerPaul Gortmaker <paul.gortmaker@windriver.com>2011-12-27 11:13:06 -0500
commitc79be4549ae39edc026aa67eb64a25424542943f (patch)
treeb0ad99587a85cf9335ae2bff9a7dd94729d3ef4b /net/tipc/bearer.c
parent706767da1bd0726d8fbc62e4818cb29193676a74 (diff)
tipc: Optimize detection of duplicate media registration
Streamlines the detection of an attempt to register a TIPC media structure using an already registered name or type identifier. The revised logic now reuses an existing routine to detect an existing name and no longer unnecessarily manipulates the media type counter during an unsuccessful registration attempt. Signed-off-by: Allan Stephens <allan.stephens@windriver.com> Signed-off-by: Paul Gortmaker <paul.gortmaker@windriver.com>
Diffstat (limited to 'net/tipc/bearer.c')
-rw-r--r--net/tipc/bearer.c40
1 files changed, 21 insertions, 19 deletions
diff --git a/net/tipc/bearer.c b/net/tipc/bearer.c
index 75af271b9cfa..9ff89207846a 100644
--- a/net/tipc/bearer.c
+++ b/net/tipc/bearer.c
@@ -81,6 +81,21 @@ static struct media *media_find(const char *name)
81} 81}
82 82
83/** 83/**
84 * media_find_id - locates specified media object by type identifier
85 */
86
87static struct media *media_find_id(u8 type)
88{
89 u32 i;
90
91 for (i = 0; i < media_count; i++) {
92 if (media_list[i].type_id == type)
93 return &media_list[i];
94 }
95 return NULL;
96}
97
98/**
84 * tipc_register_media - register a media type 99 * tipc_register_media - register a media type
85 * 100 *
86 * Bearers for this media type must be activated separately at a later stage. 101 * Bearers for this media type must be activated separately at a later stage.
@@ -88,8 +103,6 @@ static struct media *media_find(const char *name)
88 103
89int tipc_register_media(struct media *m_ptr) 104int tipc_register_media(struct media *m_ptr)
90{ 105{
91 u32 media_id;
92 u32 i;
93 int res = -EINVAL; 106 int res = -EINVAL;
94 107
95 write_lock_bh(&tipc_net_lock); 108 write_lock_bh(&tipc_net_lock);
@@ -121,29 +134,18 @@ int tipc_register_media(struct media *m_ptr)
121 goto exit; 134 goto exit;
122 } 135 }
123 136
124 media_id = media_count++; 137 if (media_count >= MAX_MEDIA) {
125 if (media_id >= MAX_MEDIA) {
126 warn("Media <%s> rejected, media limit reached (%u)\n", 138 warn("Media <%s> rejected, media limit reached (%u)\n",
127 m_ptr->name, MAX_MEDIA); 139 m_ptr->name, MAX_MEDIA);
128 media_count--;
129 goto exit; 140 goto exit;
130 } 141 }
131 for (i = 0; i < media_id; i++) { 142 if (media_find(m_ptr->name) || media_find_id(m_ptr->type_id)) {
132 if (media_list[i].type_id == m_ptr->type_id) { 143 warn("Media <%s> rejected, already registered\n", m_ptr->name);
133 warn("Media <%s> rejected, duplicate type (%u)\n", 144 goto exit;
134 m_ptr->name, m_ptr->type_id);
135 media_count--;
136 goto exit;
137 }
138 if (!strcmp(m_ptr->name, media_list[i].name)) {
139 warn("Media <%s> rejected, duplicate name\n",
140 m_ptr->name);
141 media_count--;
142 goto exit;
143 }
144 } 145 }
145 146
146 media_list[media_id] = *m_ptr; 147 media_list[media_count] = *m_ptr;
148 media_count++;
147 res = 0; 149 res = 0;
148exit: 150exit:
149 write_unlock_bh(&tipc_net_lock); 151 write_unlock_bh(&tipc_net_lock);