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

tipc: Improve handling of media address printing errors

Enhances conversion of a media address to printable form so that an
unconvertable address will be displayed as a string of hex digits,
rather than not being displayed at all. (Also removes a pointless check
for the existence of the media-specific address conversion routine,
since the routine is not optional.)
Signed-off-by: default avatarAllan Stephens <allan.stephens@windriver.com>
Signed-off-by: default avatarPaul Gortmaker <paul.gortmaker@windriver.com>
parent 6c349210
...@@ -136,20 +136,18 @@ int tipc_register_media(struct media *m_ptr) ...@@ -136,20 +136,18 @@ int tipc_register_media(struct media *m_ptr)
void tipc_media_addr_printf(struct print_buf *pb, struct tipc_media_addr *a) void tipc_media_addr_printf(struct print_buf *pb, struct tipc_media_addr *a)
{ {
char addr_str[MAX_ADDR_STR];
struct media *m_ptr; struct media *m_ptr;
u32 media_type; u32 media_type;
u32 i;
media_type = ntohl(a->type); media_type = ntohl(a->type);
m_ptr = media_find_id(media_type); m_ptr = media_find_id(media_type);
if (m_ptr && (m_ptr->addr2str != NULL)) { if (m_ptr && !m_ptr->addr2str(a, addr_str, sizeof(addr_str)))
char addr_str[MAX_ADDR_STR]; tipc_printf(pb, "%s(%s)", m_ptr->name, addr_str);
else {
tipc_printf(pb, "%s(%s)", m_ptr->name,
m_ptr->addr2str(a, addr_str, sizeof(addr_str)));
} else {
unchar *addr = (unchar *)&a->dev_addr; unchar *addr = (unchar *)&a->dev_addr;
u32 i;
tipc_printf(pb, "UNKNOWN(%u)", media_type); tipc_printf(pb, "UNKNOWN(%u)", media_type);
for (i = 0; i < (sizeof(*a) - sizeof(a->type)); i++) for (i = 0; i < (sizeof(*a) - sizeof(a->type)); i++)
......
...@@ -83,8 +83,7 @@ struct media { ...@@ -83,8 +83,7 @@ struct media {
struct tipc_media_addr *dest); struct tipc_media_addr *dest);
int (*enable_bearer)(struct tipc_bearer *b_ptr); int (*enable_bearer)(struct tipc_bearer *b_ptr);
void (*disable_bearer)(struct tipc_bearer *b_ptr); void (*disable_bearer)(struct tipc_bearer *b_ptr);
char *(*addr2str)(struct tipc_media_addr *a, int (*addr2str)(struct tipc_media_addr *a, char *str_buf, int str_size);
char *str_buf, int str_size);
struct tipc_media_addr bcast_addr; struct tipc_media_addr bcast_addr;
u32 priority; u32 priority;
u32 tolerance; u32 tolerance;
......
...@@ -243,15 +243,15 @@ static int recv_notification(struct notifier_block *nb, unsigned long evt, ...@@ -243,15 +243,15 @@ static int recv_notification(struct notifier_block *nb, unsigned long evt,
* eth_addr2str - convert Ethernet address to string * eth_addr2str - convert Ethernet address to string
*/ */
static char *eth_addr2str(struct tipc_media_addr *a, char *str_buf, int str_size) static int eth_addr2str(struct tipc_media_addr *a, char *str_buf, int str_size)
{ {
unchar *addr = (unchar *)&a->dev_addr; unchar *addr = (unchar *)&a->dev_addr;
if (str_size < 18) if (str_size < 18) /* 18 = strlen("aa:bb:cc:dd:ee:ff\0") */
*str_buf = '\0'; return 1;
else
sprintf(str_buf, "%pM", addr); sprintf(str_buf, "%pM", addr);
return str_buf; return 0;
} }
/* /*
......
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