netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Paul Gortmaker <paul.gortmaker@windriver.com>
To: davem@davemloft.net
Cc: netdev@vger.kernel.org, allan.stephens@windriver.com,
	ying.xue@windriver.com,
	Paul Gortmaker <paul.gortmaker@windriver.com>
Subject: [PATCH net-next 06/23] tipc: Improve handling of media address printing errors
Date: Tue, 27 Dec 2011 12:39:25 -0500	[thread overview]
Message-ID: <1325007582-31610-7-git-send-email-paul.gortmaker@windriver.com> (raw)
In-Reply-To: <1325007582-31610-1-git-send-email-paul.gortmaker@windriver.com>

From: Allan Stephens <allan.stephens@windriver.com>

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: Allan Stephens <allan.stephens@windriver.com>
Signed-off-by: Paul Gortmaker <paul.gortmaker@windriver.com>
---
 net/tipc/bearer.c    |   12 +++++-------
 net/tipc/bearer.h    |    3 +--
 net/tipc/eth_media.c |   12 ++++++------
 3 files changed, 12 insertions(+), 15 deletions(-)

diff --git a/net/tipc/bearer.c b/net/tipc/bearer.c
index f908b80..17652f2 100644
--- a/net/tipc/bearer.c
+++ b/net/tipc/bearer.c
@@ -136,20 +136,18 @@ exit:
 
 void tipc_media_addr_printf(struct print_buf *pb, struct tipc_media_addr *a)
 {
+	char addr_str[MAX_ADDR_STR];
 	struct media *m_ptr;
 	u32 media_type;
-	u32 i;
 
 	media_type = ntohl(a->type);
 	m_ptr = media_find_id(media_type);
 
-	if (m_ptr && (m_ptr->addr2str != NULL)) {
-		char addr_str[MAX_ADDR_STR];
-
-		tipc_printf(pb, "%s(%s)", m_ptr->name,
-			    m_ptr->addr2str(a, addr_str, sizeof(addr_str)));
-	} else {
+	if (m_ptr && !m_ptr->addr2str(a, addr_str, sizeof(addr_str)))
+		tipc_printf(pb, "%s(%s)", m_ptr->name, addr_str);
+	else {
 		unchar *addr = (unchar *)&a->dev_addr;
+		u32 i;
 
 		tipc_printf(pb, "UNKNOWN(%u)", media_type);
 		for (i = 0; i < (sizeof(*a) - sizeof(a->type)); i++)
diff --git a/net/tipc/bearer.h b/net/tipc/bearer.h
index 148ed04..4e9367f 100644
--- a/net/tipc/bearer.h
+++ b/net/tipc/bearer.h
@@ -83,8 +83,7 @@ struct media {
 			struct tipc_media_addr *dest);
 	int (*enable_bearer)(struct tipc_bearer *b_ptr);
 	void (*disable_bearer)(struct tipc_bearer *b_ptr);
-	char *(*addr2str)(struct tipc_media_addr *a,
-			  char *str_buf, int str_size);
+	int (*addr2str)(struct tipc_media_addr *a, char *str_buf, int str_size);
 	struct tipc_media_addr bcast_addr;
 	u32 priority;
 	u32 tolerance;
diff --git a/net/tipc/eth_media.c b/net/tipc/eth_media.c
index 15c685b..67f616a 100644
--- a/net/tipc/eth_media.c
+++ b/net/tipc/eth_media.c
@@ -243,15 +243,15 @@ static int recv_notification(struct notifier_block *nb, unsigned long evt,
  * 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;
 
-	if (str_size < 18)
-		*str_buf = '\0';
-	else
-		sprintf(str_buf, "%pM", addr);
-	return str_buf;
+	if (str_size < 18)	/* 18 = strlen("aa:bb:cc:dd:ee:ff\0") */
+		return 1;
+
+	sprintf(str_buf, "%pM", addr);
+	return 0;
 }
 
 /*
-- 
1.7.4.4

  parent reply	other threads:[~2011-12-27 17:39 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-12-27 17:39 [PATCH net-next 00/23] TIPC: Updates for what will be v3.3 Paul Gortmaker
2011-12-27 17:39 ` [PATCH net-next 01/23] tipc: Enable use by containers having their own network namespace Paul Gortmaker
2011-12-27 17:39 ` [PATCH net-next 02/23] tipc: Register new media using pre-compiled structure Paul Gortmaker
2011-12-27 17:39 ` [PATCH net-next 03/23] tipc: Optimize detection of duplicate media registration Paul Gortmaker
2011-12-27 17:39 ` [PATCH net-next 04/23] tipc: Eliminate duplication of media structures Paul Gortmaker
2011-12-27 17:39 ` [PATCH net-next 05/23] tipc: Streamline media registration error checking Paul Gortmaker
2011-12-27 17:39 ` Paul Gortmaker [this message]
2011-12-27 17:39 ` [PATCH net-next 07/23] tipc: Add new address conversion routines for Ethernet media Paul Gortmaker
2011-12-27 17:39 ` [PATCH net-next 08/23] tipc: Hide media-specific addressing details from generic bearer code Paul Gortmaker
2011-12-27 17:39 ` [PATCH net-next 09/23] tipc: Ignore neighbor discovery messages containing invalid address Paul Gortmaker
2011-12-27 17:39 ` [PATCH net-next 10/23] tipc: Allow run-time alteration of default link settings Paul Gortmaker
2011-12-27 17:39 ` [PATCH net-next 11/23] tipc: Revise comment justifying release of configuration spinlock Paul Gortmaker
2011-12-27 17:39 ` [PATCH net-next 12/23] tipc: Minor optimization to deactivation of Ethernet media suppot Paul Gortmaker
2011-12-27 17:39 ` [PATCH net-next 13/23] tipc: Do timely cleanup of disabled Ethernet bearer resources Paul Gortmaker
2011-12-27 17:39 ` [PATCH net-next 14/23] tipc: Eliminate useless memset operations in Ethernet media support Paul Gortmaker
2011-12-27 17:39 ` [PATCH net-next 15/23] tipc: Minor correction to TIPC module unloading Paul Gortmaker
2011-12-27 17:39 ` [PATCH net-next 16/23] tipc: Eliminate useless check when network address is assigned Paul Gortmaker
2011-12-27 17:39 ` [PATCH net-next 17/23] tipc: Eliminate dynamic allocation of broadcast link data structures Paul Gortmaker
2011-12-27 17:39 ` [PATCH net-next 18/23] tipc: Ensure broadcast link spinlock is held when updating node map Paul Gortmaker
2011-12-27 17:39 ` [PATCH net-next 19/23] tipc: Handle broadcast attempt when no neighboring nodes exist Paul Gortmaker
2011-12-27 17:39 ` [PATCH net-next 20/23] tipc: Minor optimization of broadcast link transmit queue statistic Paul Gortmaker
2011-12-27 17:39 ` [PATCH net-next 21/23] tipc: Flush unsent broadcast messages when contact with last node is lost Paul Gortmaker
2011-12-27 17:39 ` [PATCH net-next 22/23] tipc: Ignore broadcast acknowledgements that are out-of-range Paul Gortmaker
2011-12-27 17:39 ` [PATCH net-next 23/23] tipc: Allow use of buf_seqno() helper routine by unicast links Paul Gortmaker
2011-12-27 18:08 ` [PATCH net-next 00/23] TIPC: Updates for what will be v3.3 David Miller
2011-12-28  2:16   ` Paul Gortmaker

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1325007582-31610-7-git-send-email-paul.gortmaker@windriver.com \
    --to=paul.gortmaker@windriver.com \
    --cc=allan.stephens@windriver.com \
    --cc=davem@davemloft.net \
    --cc=netdev@vger.kernel.org \
    --cc=ying.xue@windriver.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).