diff options
author | Allan Stephens <allan.stephens@windriver.com> | 2011-10-07 09:25:12 -0400 |
---|---|---|
committer | Paul Gortmaker <paul.gortmaker@windriver.com> | 2011-12-27 11:13:06 -0500 |
commit | a31abe8daee5dd618aecb1484dbe9bf68c5c8a4a (patch) | |
tree | 1ebbadd93079b9caf5e7b9854e3cfe7554407d2e /net/tipc/bearer.c | |
parent | c79be4549ae39edc026aa67eb64a25424542943f (diff) |
tipc: Eliminate duplication of media structures
Changes TIPC's list of registered media types from an array of media
structures to an array of pointers to media structures. This eliminates
the need to copy of the contents of the structure passed in during media
registration.
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.c | 35 |
1 files changed, 15 insertions, 20 deletions
diff --git a/net/tipc/bearer.c b/net/tipc/bearer.c index 9ff89207846a..9012a3695b8a 100644 --- a/net/tipc/bearer.c +++ b/net/tipc/bearer.c | |||
@@ -41,7 +41,7 @@ | |||
41 | 41 | ||
42 | #define MAX_ADDR_STR 32 | 42 | #define MAX_ADDR_STR 32 |
43 | 43 | ||
44 | static struct media media_list[MAX_MEDIA]; | 44 | static struct media *media_list[MAX_MEDIA]; |
45 | static u32 media_count; | 45 | static u32 media_count; |
46 | 46 | ||
47 | struct tipc_bearer tipc_bearers[MAX_BEARERS]; | 47 | struct tipc_bearer tipc_bearers[MAX_BEARERS]; |
@@ -70,12 +70,11 @@ static int media_name_valid(const char *name) | |||
70 | 70 | ||
71 | static struct media *media_find(const char *name) | 71 | static struct media *media_find(const char *name) |
72 | { | 72 | { |
73 | struct media *m_ptr; | ||
74 | u32 i; | 73 | u32 i; |
75 | 74 | ||
76 | for (i = 0, m_ptr = media_list; i < media_count; i++, m_ptr++) { | 75 | for (i = 0; i < media_count; i++) { |
77 | if (!strcmp(m_ptr->name, name)) | 76 | if (!strcmp(media_list[i]->name, name)) |
78 | return m_ptr; | 77 | return media_list[i]; |
79 | } | 78 | } |
80 | return NULL; | 79 | return NULL; |
81 | } | 80 | } |
@@ -89,8 +88,8 @@ static struct media *media_find_id(u8 type) | |||
89 | u32 i; | 88 | u32 i; |
90 | 89 | ||
91 | for (i = 0; i < media_count; i++) { | 90 | for (i = 0; i < media_count; i++) { |
92 | if (media_list[i].type_id == type) | 91 | if (media_list[i]->type_id == type) |
93 | return &media_list[i]; | 92 | return media_list[i]; |
94 | } | 93 | } |
95 | return NULL; | 94 | return NULL; |
96 | } | 95 | } |
@@ -144,7 +143,7 @@ int tipc_register_media(struct media *m_ptr) | |||
144 | goto exit; | 143 | goto exit; |
145 | } | 144 | } |
146 | 145 | ||
147 | media_list[media_count] = *m_ptr; | 146 | media_list[media_count] = m_ptr; |
148 | media_count++; | 147 | media_count++; |
149 | res = 0; | 148 | res = 0; |
150 | exit: | 149 | exit: |
@@ -163,12 +162,9 @@ void tipc_media_addr_printf(struct print_buf *pb, struct tipc_media_addr *a) | |||
163 | u32 i; | 162 | u32 i; |
164 | 163 | ||
165 | media_type = ntohl(a->type); | 164 | media_type = ntohl(a->type); |
166 | for (i = 0, m_ptr = media_list; i < media_count; i++, m_ptr++) { | 165 | m_ptr = media_find_id(media_type); |
167 | if (m_ptr->type_id == media_type) | ||
168 | break; | ||
169 | } | ||
170 | 166 | ||
171 | if ((i < media_count) && (m_ptr->addr2str != NULL)) { | 167 | if (m_ptr && (m_ptr->addr2str != NULL)) { |
172 | char addr_str[MAX_ADDR_STR]; | 168 | char addr_str[MAX_ADDR_STR]; |
173 | 169 | ||
174 | tipc_printf(pb, "%s(%s)", m_ptr->name, | 170 | tipc_printf(pb, "%s(%s)", m_ptr->name, |
@@ -189,7 +185,6 @@ void tipc_media_addr_printf(struct print_buf *pb, struct tipc_media_addr *a) | |||
189 | struct sk_buff *tipc_media_get_names(void) | 185 | struct sk_buff *tipc_media_get_names(void) |
190 | { | 186 | { |
191 | struct sk_buff *buf; | 187 | struct sk_buff *buf; |
192 | struct media *m_ptr; | ||
193 | int i; | 188 | int i; |
194 | 189 | ||
195 | buf = tipc_cfg_reply_alloc(MAX_MEDIA * TLV_SPACE(TIPC_MAX_MEDIA_NAME)); | 190 | buf = tipc_cfg_reply_alloc(MAX_MEDIA * TLV_SPACE(TIPC_MAX_MEDIA_NAME)); |
@@ -197,9 +192,10 @@ struct sk_buff *tipc_media_get_names(void) | |||
197 | return NULL; | 192 | return NULL; |
198 | 193 | ||
199 | read_lock_bh(&tipc_net_lock); | 194 | read_lock_bh(&tipc_net_lock); |
200 | for (i = 0, m_ptr = media_list; i < media_count; i++, m_ptr++) { | 195 | for (i = 0; i < media_count; i++) { |
201 | tipc_cfg_append_tlv(buf, TIPC_TLV_MEDIA_NAME, m_ptr->name, | 196 | tipc_cfg_append_tlv(buf, TIPC_TLV_MEDIA_NAME, |
202 | strlen(m_ptr->name) + 1); | 197 | media_list[i]->name, |
198 | strlen(media_list[i]->name) + 1); | ||
203 | } | 199 | } |
204 | read_unlock_bh(&tipc_net_lock); | 200 | read_unlock_bh(&tipc_net_lock); |
205 | return buf; | 201 | return buf; |
@@ -300,7 +296,6 @@ struct tipc_bearer *tipc_bearer_find_interface(const char *if_name) | |||
300 | struct sk_buff *tipc_bearer_get_names(void) | 296 | struct sk_buff *tipc_bearer_get_names(void) |
301 | { | 297 | { |
302 | struct sk_buff *buf; | 298 | struct sk_buff *buf; |
303 | struct media *m_ptr; | ||
304 | struct tipc_bearer *b_ptr; | 299 | struct tipc_bearer *b_ptr; |
305 | int i, j; | 300 | int i, j; |
306 | 301 | ||
@@ -309,10 +304,10 @@ struct sk_buff *tipc_bearer_get_names(void) | |||
309 | return NULL; | 304 | return NULL; |
310 | 305 | ||
311 | read_lock_bh(&tipc_net_lock); | 306 | read_lock_bh(&tipc_net_lock); |
312 | for (i = 0, m_ptr = media_list; i < media_count; i++, m_ptr++) { | 307 | for (i = 0; i < media_count; i++) { |
313 | for (j = 0; j < MAX_BEARERS; j++) { | 308 | for (j = 0; j < MAX_BEARERS; j++) { |
314 | b_ptr = &tipc_bearers[j]; | 309 | b_ptr = &tipc_bearers[j]; |
315 | if (b_ptr->active && (b_ptr->media == m_ptr)) { | 310 | if (b_ptr->active && (b_ptr->media == media_list[i])) { |
316 | tipc_cfg_append_tlv(buf, TIPC_TLV_BEARER_NAME, | 311 | tipc_cfg_append_tlv(buf, TIPC_TLV_BEARER_NAME, |
317 | b_ptr->name, | 312 | b_ptr->name, |
318 | strlen(b_ptr->name) + 1); | 313 | strlen(b_ptr->name) + 1); |