Commit 5702dbab authored by Jon Paul Maloy's avatar Jon Paul Maloy Committed by David S. Miller

tipc: initiate media type array at compile time

Communication media types are abstracted through the struct 'tipc_media',
one per media type. These structs are allocated statically inside their
respective media file.

Furthermore, in order to be able to reach all instances from a central
location, we keep a static array with pointers to these structs. This
array is currently initialized at runtime, under protection of
tipc_net_lock. However, since the contents of the array itself never
changes after initialization, we can just as well initialize it at
compile time and make it 'const', at the same time making it obvious
that no lock protection is needed here.

This commit makes the array constant and removes the redundant lock
protection.
Signed-off-by: default avatarYing Xue <ying.xue@windriver.com>
Reviewed-by: default avatarPaul Gortmaker <paul.gortmaker@windriver.com>
Signed-off-by: default avatarJon Maloy <jon.maloy@ericsson.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent d77b3831
/* /*
* net/tipc/bearer.c: TIPC bearer code * net/tipc/bearer.c: TIPC bearer code
* *
* Copyright (c) 1996-2006, Ericsson AB * Copyright (c) 1996-2006, 2013, Ericsson AB
* Copyright (c) 2004-2006, 2010-2011, Wind River Systems * Copyright (c) 2004-2006, 2010-2011, Wind River Systems
* All rights reserved. * All rights reserved.
* *
...@@ -41,8 +41,13 @@ ...@@ -41,8 +41,13 @@
#define MAX_ADDR_STR 60 #define MAX_ADDR_STR 60
static struct tipc_media *media_list[MAX_MEDIA]; static struct tipc_media * const media_list[] = {
static u32 media_count; &eth_media_info,
#ifdef CONFIG_TIPC_MEDIA_IB
&ib_media_info,
#endif
NULL
};
struct tipc_bearer tipc_bearers[MAX_BEARERS]; struct tipc_bearer tipc_bearers[MAX_BEARERS];
...@@ -55,11 +60,11 @@ struct tipc_media *tipc_media_find(const char *name) ...@@ -55,11 +60,11 @@ struct tipc_media *tipc_media_find(const char *name)
{ {
u32 i; u32 i;
for (i = 0; i < media_count; i++) { for (i = 0; media_list[i] != NULL; i++) {
if (!strcmp(media_list[i]->name, name)) if (!strcmp(media_list[i]->name, name))
return media_list[i]; break;
} }
return NULL; return media_list[i];
} }
/** /**
...@@ -69,44 +74,11 @@ static struct tipc_media *media_find_id(u8 type) ...@@ -69,44 +74,11 @@ static struct tipc_media *media_find_id(u8 type)
{ {
u32 i; u32 i;
for (i = 0; i < media_count; i++) { for (i = 0; media_list[i] != NULL; i++) {
if (media_list[i]->type_id == type) if (media_list[i]->type_id == type)
return media_list[i]; break;
} }
return NULL; return media_list[i];
}
/**
* tipc_register_media - register a media type
*
* Bearers for this media type must be activated separately at a later stage.
*/
int tipc_register_media(struct tipc_media *m_ptr)
{
int res = -EINVAL;
write_lock_bh(&tipc_net_lock);
if ((strlen(m_ptr->name) + 1) > TIPC_MAX_MEDIA_NAME)
goto exit;
if (m_ptr->priority > TIPC_MAX_LINK_PRI)
goto exit;
if ((m_ptr->tolerance < TIPC_MIN_LINK_TOL) ||
(m_ptr->tolerance > TIPC_MAX_LINK_TOL))
goto exit;
if (media_count >= MAX_MEDIA)
goto exit;
if (tipc_media_find(m_ptr->name) || media_find_id(m_ptr->type_id))
goto exit;
media_list[media_count] = m_ptr;
media_count++;
res = 0;
exit:
write_unlock_bh(&tipc_net_lock);
if (res)
pr_warn("Media <%s> registration error\n", m_ptr->name);
return res;
} }
/** /**
...@@ -144,13 +116,11 @@ struct sk_buff *tipc_media_get_names(void) ...@@ -144,13 +116,11 @@ struct sk_buff *tipc_media_get_names(void)
if (!buf) if (!buf)
return NULL; return NULL;
read_lock_bh(&tipc_net_lock); for (i = 0; media_list[i] != NULL; i++) {
for (i = 0; i < media_count; i++) {
tipc_cfg_append_tlv(buf, TIPC_TLV_MEDIA_NAME, tipc_cfg_append_tlv(buf, TIPC_TLV_MEDIA_NAME,
media_list[i]->name, media_list[i]->name,
strlen(media_list[i]->name) + 1); strlen(media_list[i]->name) + 1);
} }
read_unlock_bh(&tipc_net_lock);
return buf; return buf;
} }
...@@ -247,7 +217,7 @@ struct sk_buff *tipc_bearer_get_names(void) ...@@ -247,7 +217,7 @@ 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; i < media_count; i++) { for (i = 0; media_list[i] != NULL; 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 == media_list[i])) { if (b_ptr->active && (b_ptr->media == media_list[i])) {
...@@ -472,5 +442,4 @@ void tipc_bearer_stop(void) ...@@ -472,5 +442,4 @@ void tipc_bearer_stop(void)
if (tipc_bearers[i].active) if (tipc_bearers[i].active)
bearer_disable(&tipc_bearers[i]); bearer_disable(&tipc_bearers[i]);
} }
media_count = 0;
} }
/* /*
* net/tipc/bearer.h: Include file for TIPC bearer code * net/tipc/bearer.h: Include file for TIPC bearer code
* *
* Copyright (c) 1996-2006, Ericsson AB * Copyright (c) 1996-2006, 2013, Ericsson AB
* Copyright (c) 2005, 2010-2011, Wind River Systems * Copyright (c) 2005, 2010-2011, Wind River Systems
* All rights reserved. * All rights reserved.
* *
...@@ -157,7 +157,6 @@ extern struct tipc_bearer tipc_bearers[]; ...@@ -157,7 +157,6 @@ extern struct tipc_bearer tipc_bearers[];
/* /*
* TIPC routines available to supported media types * TIPC routines available to supported media types
*/ */
int tipc_register_media(struct tipc_media *m_ptr);
void tipc_recv_msg(struct sk_buff *buf, struct tipc_bearer *tb_ptr); void tipc_recv_msg(struct sk_buff *buf, struct tipc_bearer *tb_ptr);
...@@ -171,10 +170,12 @@ int tipc_disable_bearer(const char *name); ...@@ -171,10 +170,12 @@ int tipc_disable_bearer(const char *name);
*/ */
int tipc_eth_media_start(void); int tipc_eth_media_start(void);
void tipc_eth_media_stop(void); void tipc_eth_media_stop(void);
extern struct tipc_media eth_media_info;
#ifdef CONFIG_TIPC_MEDIA_IB #ifdef CONFIG_TIPC_MEDIA_IB
int tipc_ib_media_start(void); int tipc_ib_media_start(void);
void tipc_ib_media_stop(void); void tipc_ib_media_stop(void);
extern struct tipc_media ib_media_info;
#else #else
static inline int tipc_ib_media_start(void) { return 0; } static inline int tipc_ib_media_start(void) { return 0; }
static inline void tipc_ib_media_stop(void) { return; } static inline void tipc_ib_media_stop(void) { return; }
......
/* /*
* net/tipc/eth_media.c: Ethernet bearer support for TIPC * net/tipc/eth_media.c: Ethernet bearer support for TIPC
* *
* Copyright (c) 2001-2007, Ericsson AB * Copyright (c) 2001-2007, 2013, Ericsson AB
* Copyright (c) 2005-2008, 2011-2013, Wind River Systems * Copyright (c) 2005-2008, 2011-2013, Wind River Systems
* All rights reserved. * All rights reserved.
* *
...@@ -57,7 +57,7 @@ struct eth_media { ...@@ -57,7 +57,7 @@ struct eth_media {
struct work_struct cleanup; struct work_struct cleanup;
}; };
static struct tipc_media eth_media_info;
static struct eth_media eth_media_array[MAX_ETH_MEDIA]; static struct eth_media eth_media_array[MAX_ETH_MEDIA];
static int eth_started; static int eth_started;
...@@ -315,7 +315,7 @@ static int eth_msg2addr(const struct tipc_bearer *tb_ptr, ...@@ -315,7 +315,7 @@ static int eth_msg2addr(const struct tipc_bearer *tb_ptr,
/* /*
* Ethernet media registration info * Ethernet media registration info
*/ */
static struct tipc_media eth_media_info = { struct tipc_media eth_media_info = {
.send_msg = send_msg, .send_msg = send_msg,
.enable_media = enable_media, .enable_media = enable_media,
.disable_media = disable_media, .disable_media = disable_media,
...@@ -342,10 +342,6 @@ int tipc_eth_media_start(void) ...@@ -342,10 +342,6 @@ int tipc_eth_media_start(void)
if (eth_started) if (eth_started)
return -EINVAL; return -EINVAL;
res = tipc_register_media(&eth_media_info);
if (res)
return res;
res = register_netdevice_notifier(&notifier); res = register_netdevice_notifier(&notifier);
if (!res) if (!res)
eth_started = 1; eth_started = 1;
......
...@@ -60,7 +60,6 @@ struct ib_media { ...@@ -60,7 +60,6 @@ struct ib_media {
struct work_struct cleanup; struct work_struct cleanup;
}; };
static struct tipc_media ib_media_info;
static struct ib_media ib_media_array[MAX_IB_MEDIA]; static struct ib_media ib_media_array[MAX_IB_MEDIA];
static int ib_started; static int ib_started;
...@@ -311,7 +310,7 @@ static int ib_msg2addr(const struct tipc_bearer *tb_ptr, ...@@ -311,7 +310,7 @@ static int ib_msg2addr(const struct tipc_bearer *tb_ptr,
/* /*
* InfiniBand media registration info * InfiniBand media registration info
*/ */
static struct tipc_media ib_media_info = { struct tipc_media ib_media_info = {
.send_msg = send_msg, .send_msg = send_msg,
.enable_media = enable_media, .enable_media = enable_media,
.disable_media = disable_media, .disable_media = disable_media,
...@@ -338,10 +337,6 @@ int tipc_ib_media_start(void) ...@@ -338,10 +337,6 @@ int tipc_ib_media_start(void)
if (ib_started) if (ib_started)
return -EINVAL; return -EINVAL;
res = tipc_register_media(&ib_media_info);
if (res)
return res;
res = register_netdevice_notifier(&notifier); res = register_netdevice_notifier(&notifier);
if (!res) if (!res)
ib_started = 1; ib_started = 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