Skip to content

Commit

Permalink
[TIPC]: Enhanced & cleaned up system messages; fixed 2 obscure memory…
Browse files Browse the repository at this point in the history
… leaks.

Signed-off-by: Allan Stephens <[email protected]>
Signed-off-by: Per Liden <[email protected]>
Signed-off-by: David S. Miller <[email protected]>
  • Loading branch information
ajstephens authored and davem330 committed Jun 26, 2006
1 parent f131072 commit a10bd92
Show file tree
Hide file tree
Showing 13 changed files with 149 additions and 126 deletions.
2 changes: 1 addition & 1 deletion net/tipc/bcast.c
Original file line number Diff line number Diff line change
Expand Up @@ -785,7 +785,7 @@ int tipc_bclink_init(void)
bclink = kmalloc(sizeof(*bclink), GFP_ATOMIC);
if (!bcbearer || !bclink) {
nomem:
warn("Memory squeeze; Failed to create multicast link\n");
warn("Multicast link creation failed, no memory\n");
kfree(bcbearer);
bcbearer = NULL;
kfree(bclink);
Expand Down
2 changes: 1 addition & 1 deletion net/tipc/bcast.h
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ static inline void tipc_port_list_add(struct port_list *pl_ptr, u32 port)
if (!item->next) {
item->next = kmalloc(sizeof(*item), GFP_ATOMIC);
if (!item->next) {
warn("Memory squeeze: multicast destination port list is incomplete\n");
warn("Incomplete multicast delivery, no memory\n");
return;
}
item->next->next = NULL;
Expand Down
70 changes: 39 additions & 31 deletions net/tipc/bearer.c
Original file line number Diff line number Diff line change
Expand Up @@ -112,39 +112,42 @@ int tipc_register_media(u32 media_type,
goto exit;

if (!media_name_valid(name)) {
warn("Media registration error: illegal name <%s>\n", name);
warn("Media <%s> rejected, illegal name\n", name);
goto exit;
}
if (!bcast_addr) {
warn("Media registration error: no broadcast address supplied\n");
warn("Media <%s> rejected, no broadcast address\n", name);
goto exit;
}
if ((bearer_priority < TIPC_MIN_LINK_PRI) &&
(bearer_priority > TIPC_MAX_LINK_PRI)) {
warn("Media registration error: priority %u\n", bearer_priority);
warn("Media <%s> rejected, illegal priority (%u)\n", name,
bearer_priority);
goto exit;
}
if ((link_tolerance < TIPC_MIN_LINK_TOL) ||
(link_tolerance > TIPC_MAX_LINK_TOL)) {
warn("Media registration error: tolerance %u\n", link_tolerance);
warn("Media <%s> rejected, illegal tolerance (%u)\n", name,
link_tolerance);
goto exit;
}

media_id = media_count++;
if (media_id >= MAX_MEDIA) {
warn("Attempt to register more than %u media\n", MAX_MEDIA);
warn("Media <%s> rejected, media limit reached (%u)\n", name,
MAX_MEDIA);
media_count--;
goto exit;
}
for (i = 0; i < media_id; i++) {
if (media_list[i].type_id == media_type) {
warn("Attempt to register second media with type %u\n",
warn("Media <%s> rejected, duplicate type (%u)\n", name,
media_type);
media_count--;
goto exit;
}
if (!strcmp(name, media_list[i].name)) {
warn("Attempt to re-register media name <%s>\n", name);
warn("Media <%s> rejected, duplicate name\n", name);
media_count--;
goto exit;
}
Expand Down Expand Up @@ -283,6 +286,9 @@ static struct bearer *bearer_find(const char *name)
struct bearer *b_ptr;
u32 i;

if (tipc_mode != TIPC_NET_MODE)
return NULL;

for (i = 0, b_ptr = tipc_bearers; i < MAX_BEARERS; i++, b_ptr++) {
if (b_ptr->active && (!strcmp(b_ptr->publ.name, name)))
return b_ptr;
Expand Down Expand Up @@ -475,26 +481,33 @@ int tipc_enable_bearer(const char *name, u32 bcast_scope, u32 priority)
u32 i;
int res = -EINVAL;

if (tipc_mode != TIPC_NET_MODE)
if (tipc_mode != TIPC_NET_MODE) {
warn("Bearer <%s> rejected, not supported in standalone mode\n",
name);
return -ENOPROTOOPT;

if (!bearer_name_validate(name, &b_name) ||
!tipc_addr_domain_valid(bcast_scope) ||
!in_scope(bcast_scope, tipc_own_addr))
}
if (!bearer_name_validate(name, &b_name)) {
warn("Bearer <%s> rejected, illegal name\n", name);
return -EINVAL;

}
if (!tipc_addr_domain_valid(bcast_scope) ||
!in_scope(bcast_scope, tipc_own_addr)) {
warn("Bearer <%s> rejected, illegal broadcast scope\n", name);
return -EINVAL;
}
if ((priority < TIPC_MIN_LINK_PRI ||
priority > TIPC_MAX_LINK_PRI) &&
(priority != TIPC_MEDIA_LINK_PRI))
(priority != TIPC_MEDIA_LINK_PRI)) {
warn("Bearer <%s> rejected, illegal priority\n", name);
return -EINVAL;
}

write_lock_bh(&tipc_net_lock);
if (!tipc_bearers)
goto failed;

m_ptr = media_find(b_name.media_name);
if (!m_ptr) {
warn("No media <%s>\n", b_name.media_name);
warn("Bearer <%s> rejected, media <%s> not registered\n", name,
b_name.media_name);
goto failed;
}

Expand All @@ -510,23 +523,24 @@ int tipc_enable_bearer(const char *name, u32 bcast_scope, u32 priority)
continue;
}
if (!strcmp(name, tipc_bearers[i].publ.name)) {
warn("Bearer <%s> already enabled\n", name);
warn("Bearer <%s> rejected, already enabled\n", name);
goto failed;
}
if ((tipc_bearers[i].priority == priority) &&
(++with_this_prio > 2)) {
if (priority-- == 0) {
warn("Third bearer <%s> with priority %u, unable to lower to %u\n",
name, priority + 1, priority);
warn("Bearer <%s> rejected, duplicate priority\n",
name);
goto failed;
}
warn("Third bearer <%s> with priority %u, lowering to %u\n",
warn("Bearer <%s> priority adjustment required %u->%u\n",
name, priority + 1, priority);
goto restart;
}
}
if (bearer_id >= MAX_BEARERS) {
warn("Attempt to enable more than %d bearers\n", MAX_BEARERS);
warn("Bearer <%s> rejected, bearer limit reached (%u)\n",
name, MAX_BEARERS);
goto failed;
}

Expand All @@ -536,7 +550,7 @@ int tipc_enable_bearer(const char *name, u32 bcast_scope, u32 priority)
strcpy(b_ptr->publ.name, name);
res = m_ptr->enable_bearer(&b_ptr->publ);
if (res) {
warn("Failed to enable bearer <%s>\n", name);
warn("Bearer <%s> rejected, enable failure (%d)\n", name, -res);
goto failed;
}

Expand Down Expand Up @@ -573,9 +587,6 @@ int tipc_block_bearer(const char *name)
struct link *l_ptr;
struct link *temp_l_ptr;

if (tipc_mode != TIPC_NET_MODE)
return -ENOPROTOOPT;

read_lock_bh(&tipc_net_lock);
b_ptr = bearer_find(name);
if (!b_ptr) {
Expand All @@ -584,6 +595,7 @@ int tipc_block_bearer(const char *name)
return -EINVAL;
}

info("Blocking bearer <%s>\n", name);
spin_lock_bh(&b_ptr->publ.lock);
b_ptr->publ.blocked = 1;
list_for_each_entry_safe(l_ptr, temp_l_ptr, &b_ptr->links, link_list) {
Expand All @@ -595,7 +607,6 @@ int tipc_block_bearer(const char *name)
}
spin_unlock_bh(&b_ptr->publ.lock);
read_unlock_bh(&tipc_net_lock);
info("Blocked bearer <%s>\n", name);
return TIPC_OK;
}

Expand All @@ -611,15 +622,13 @@ static int bearer_disable(const char *name)
struct link *l_ptr;
struct link *temp_l_ptr;

if (tipc_mode != TIPC_NET_MODE)
return -ENOPROTOOPT;

b_ptr = bearer_find(name);
if (!b_ptr) {
warn("Attempt to disable unknown bearer <%s>\n", name);
return -EINVAL;
}

info("Disabling bearer <%s>\n", name);
tipc_disc_stop_link_req(b_ptr->link_req);
spin_lock_bh(&b_ptr->publ.lock);
b_ptr->link_req = NULL;
Expand All @@ -635,7 +644,6 @@ static int bearer_disable(const char *name)
tipc_link_delete(l_ptr);
}
spin_unlock_bh(&b_ptr->publ.lock);
info("Disabled bearer <%s>\n", name);
memset(b_ptr, 0, sizeof(struct bearer));
return TIPC_OK;
}
Expand Down
22 changes: 13 additions & 9 deletions net/tipc/cluster.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,10 @@ struct cluster *tipc_cltr_create(u32 addr)
int alloc;

c_ptr = (struct cluster *)kmalloc(sizeof(*c_ptr), GFP_ATOMIC);
if (c_ptr == NULL)
if (c_ptr == NULL) {
warn("Cluster creation failure, no memory\n");
return NULL;
}
memset(c_ptr, 0, sizeof(*c_ptr));

c_ptr->addr = tipc_addr(tipc_zone(addr), tipc_cluster(addr), 0);
Expand All @@ -70,30 +72,32 @@ struct cluster *tipc_cltr_create(u32 addr)
else
max_nodes = tipc_max_nodes + 1;
alloc = sizeof(void *) * (max_nodes + 1);

c_ptr->nodes = (struct node **)kmalloc(alloc, GFP_ATOMIC);
if (c_ptr->nodes == NULL) {
warn("Cluster creation failure, no memory for node area\n");
kfree(c_ptr);
return NULL;
}
memset(c_ptr->nodes, 0, alloc);
memset(c_ptr->nodes, 0, alloc);

if (in_own_cluster(addr))
tipc_local_nodes = c_ptr->nodes;
c_ptr->highest_slave = LOWEST_SLAVE - 1;
c_ptr->highest_node = 0;

z_ptr = tipc_zone_find(tipc_zone(addr));
if (z_ptr == NULL) {
if (!z_ptr) {
z_ptr = tipc_zone_create(addr);
}
if (z_ptr != NULL) {
tipc_zone_attach_cluster(z_ptr, c_ptr);
c_ptr->owner = z_ptr;
}
else {
if (!z_ptr) {
kfree(c_ptr->nodes);
kfree(c_ptr);
c_ptr = NULL;
return NULL;
}

tipc_zone_attach_cluster(z_ptr, c_ptr);
c_ptr->owner = z_ptr;
return c_ptr;
}

Expand Down
2 changes: 1 addition & 1 deletion net/tipc/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -642,7 +642,7 @@ static void cfg_named_msg_event(void *userdata,
if ((size < sizeof(*req_hdr)) ||
(size != TCM_ALIGN(ntohl(req_hdr->tcm_len))) ||
(ntohs(req_hdr->tcm_flags) != TCM_F_REQUEST)) {
warn("discarded invalid configuration message\n");
warn("Invalid configuration message discarded\n");
return;
}

Expand Down
7 changes: 2 additions & 5 deletions net/tipc/discover.c
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,6 @@ void tipc_disc_recv_msg(struct sk_buff *buf)
n_ptr = tipc_node_create(orig);
}
if (n_ptr == NULL) {
warn("Memory squeeze; Failed to create node\n");
return;
}
spin_lock_bh(&n_ptr->lock);
Expand All @@ -191,10 +190,8 @@ void tipc_disc_recv_msg(struct sk_buff *buf)
}
addr = &link->media_addr;
if (memcmp(addr, &media_addr, sizeof(*addr))) {
char addr_string[16];

warn("New bearer address for %s\n",
addr_string_fill(addr_string, orig));
warn("Resetting link <%s>, peer interface address changed\n",
link->name);
memcpy(addr, &media_addr, sizeof(*addr));
tipc_link_reset(link);
}
Expand Down
Loading

0 comments on commit a10bd92

Please sign in to comment.