Commit a31abe8d authored by Allan Stephens's avatar Allan Stephens Committed by Paul Gortmaker

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: default avatarAllan Stephens <allan.stephens@windriver.com>
Signed-off-by: default avatarPaul Gortmaker <paul.gortmaker@windriver.com>
parent c79be454
...@@ -41,7 +41,7 @@ ...@@ -41,7 +41,7 @@
#define MAX_ADDR_STR 32 #define MAX_ADDR_STR 32
static struct media media_list[MAX_MEDIA]; static struct media *media_list[MAX_MEDIA];
static u32 media_count; static u32 media_count;
struct tipc_bearer tipc_bearers[MAX_BEARERS]; struct tipc_bearer tipc_bearers[MAX_BEARERS];
...@@ -70,12 +70,11 @@ static int media_name_valid(const char *name) ...@@ -70,12 +70,11 @@ static int media_name_valid(const char *name)
static struct media *media_find(const char *name) static struct media *media_find(const char *name)
{ {
struct media *m_ptr;
u32 i; u32 i;
for (i = 0, m_ptr = media_list; i < media_count; i++, m_ptr++) { for (i = 0; i < media_count; i++) {
if (!strcmp(m_ptr->name, name)) if (!strcmp(media_list[i]->name, name))
return m_ptr; return media_list[i];
} }
return NULL; return NULL;
} }
...@@ -89,8 +88,8 @@ static struct media *media_find_id(u8 type) ...@@ -89,8 +88,8 @@ static struct media *media_find_id(u8 type)
u32 i; u32 i;
for (i = 0; i < media_count; i++) { for (i = 0; i < media_count; i++) {
if (media_list[i].type_id == type) if (media_list[i]->type_id == type)
return &media_list[i]; return media_list[i];
} }
return NULL; return NULL;
} }
...@@ -144,7 +143,7 @@ int tipc_register_media(struct media *m_ptr) ...@@ -144,7 +143,7 @@ int tipc_register_media(struct media *m_ptr)
goto exit; goto exit;
} }
media_list[media_count] = *m_ptr; media_list[media_count] = m_ptr;
media_count++; media_count++;
res = 0; res = 0;
exit: exit:
...@@ -163,12 +162,9 @@ void tipc_media_addr_printf(struct print_buf *pb, struct tipc_media_addr *a) ...@@ -163,12 +162,9 @@ void tipc_media_addr_printf(struct print_buf *pb, struct tipc_media_addr *a)
u32 i; u32 i;
media_type = ntohl(a->type); media_type = ntohl(a->type);
for (i = 0, m_ptr = media_list; i < media_count; i++, m_ptr++) { m_ptr = media_find_id(media_type);
if (m_ptr->type_id == media_type)
break;
}
if ((i < media_count) && (m_ptr->addr2str != NULL)) { if (m_ptr && (m_ptr->addr2str != NULL)) {
char addr_str[MAX_ADDR_STR]; char addr_str[MAX_ADDR_STR];
tipc_printf(pb, "%s(%s)", m_ptr->name, 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,7 +185,6 @@ void tipc_media_addr_printf(struct print_buf *pb, struct tipc_media_addr *a)
struct sk_buff *tipc_media_get_names(void) struct sk_buff *tipc_media_get_names(void)
{ {
struct sk_buff *buf; struct sk_buff *buf;
struct media *m_ptr;
int i; int i;
buf = tipc_cfg_reply_alloc(MAX_MEDIA * TLV_SPACE(TIPC_MAX_MEDIA_NAME)); 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,9 +192,10 @@ struct sk_buff *tipc_media_get_names(void)
return NULL; return NULL;
read_lock_bh(&tipc_net_lock); read_lock_bh(&tipc_net_lock);
for (i = 0, m_ptr = media_list; i < media_count; i++, m_ptr++) { for (i = 0; i < media_count; i++) {
tipc_cfg_append_tlv(buf, TIPC_TLV_MEDIA_NAME, m_ptr->name, tipc_cfg_append_tlv(buf, TIPC_TLV_MEDIA_NAME,
strlen(m_ptr->name) + 1); media_list[i]->name,
strlen(media_list[i]->name) + 1);
} }
read_unlock_bh(&tipc_net_lock); read_unlock_bh(&tipc_net_lock);
return buf; return buf;
...@@ -300,7 +296,6 @@ struct tipc_bearer *tipc_bearer_find_interface(const char *if_name) ...@@ -300,7 +296,6 @@ struct tipc_bearer *tipc_bearer_find_interface(const char *if_name)
struct sk_buff *tipc_bearer_get_names(void) struct sk_buff *tipc_bearer_get_names(void)
{ {
struct sk_buff *buf; struct sk_buff *buf;
struct media *m_ptr;
struct tipc_bearer *b_ptr; struct tipc_bearer *b_ptr;
int i, j; int i, j;
...@@ -309,10 +304,10 @@ struct sk_buff *tipc_bearer_get_names(void) ...@@ -309,10 +304,10 @@ struct sk_buff *tipc_bearer_get_names(void)
return NULL; return NULL;
read_lock_bh(&tipc_net_lock); read_lock_bh(&tipc_net_lock);
for (i = 0, m_ptr = media_list; i < media_count; i++, m_ptr++) { for (i = 0; i < media_count; i++) {
for (j = 0; j < MAX_BEARERS; j++) { for (j = 0; j < MAX_BEARERS; j++) {
b_ptr = &tipc_bearers[j]; b_ptr = &tipc_bearers[j];
if (b_ptr->active && (b_ptr->media == m_ptr)) { if (b_ptr->active && (b_ptr->media == media_list[i])) {
tipc_cfg_append_tlv(buf, TIPC_TLV_BEARER_NAME, tipc_cfg_append_tlv(buf, TIPC_TLV_BEARER_NAME,
b_ptr->name, b_ptr->name,
strlen(b_ptr->name) + 1); strlen(b_ptr->name) + 1);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment