netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Veaceslav Falico <vfalico@gmail.com>
To: netdev@vger.kernel.org
Cc: Veaceslav Falico <vfalico@gmail.com>,
	"David S. Miller" <davem@davemloft.net>,
	Tom Gundersen <teg@jklm.no>
Subject: [PATCH v3 net-next 1/2] net: use dev->name in netdev_pr* when it's available
Date: Thu, 17 Jul 2014 19:46:09 +0200	[thread overview]
Message-ID: <1405619171-18172-2-git-send-email-vfalico@gmail.com> (raw)
In-Reply-To: <1405619171-18172-1-git-send-email-vfalico@gmail.com>

netdev_name() returns dev->name only when the net_device is in
NETREG_REGISTERED state.

However, dev->name is always populated on creation, so we can easily use
it.

There are two cases when there's no real name - when it's an empty string
or when the name is in form of "eth%d", then netdev_name() returns "unnamed
net_device".

CC: "David S. Miller" <davem@davemloft.net>
CC: Tom Gundersen <teg@jklm.no>
Signed-off-by: Veaceslav Falico <vfalico@gmail.com>
---

Notes:
    v1->v2:
    Also account for an empty string, as Tom Gundersen suggested.

 include/linux/netdevice.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
index 15ed750..70256aa 100644
--- a/include/linux/netdevice.h
+++ b/include/linux/netdevice.h
@@ -3383,8 +3383,8 @@ extern struct pernet_operations __net_initdata loopback_net_ops;
 
 static inline const char *netdev_name(const struct net_device *dev)
 {
-	if (dev->reg_state != NETREG_REGISTERED)
-		return "(unregistered net_device)";
+	if (!dev->name[0] || strchr(dev->name, '%'))
+		return "(unnamed net_device)";
 	return dev->name;
 }
 
-- 
1.8.4

  reply	other threads:[~2014-07-17 17:50 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-07-17 17:46 [PATCH v3 net-next 0/2] net: print net_device name/state more often Veaceslav Falico
2014-07-17 17:46 ` Veaceslav Falico [this message]
2014-07-18  9:01   ` [PATCH v3 net-next 1/2] net: use dev->name in netdev_pr* when it's available Tom Gundersen
2014-07-17 17:46 ` [PATCH v3 net-next 2/2] net: print net_device reg_state in netdev_* unless it's registered Veaceslav Falico
2014-07-17 19:21   ` Joe Perches
2014-07-17 19:39     ` Veaceslav Falico
2014-07-21  3:39 ` [PATCH v3 net-next 0/2] net: print net_device name/state more often David Miller

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=1405619171-18172-2-git-send-email-vfalico@gmail.com \
    --to=vfalico@gmail.com \
    --cc=davem@davemloft.net \
    --cc=netdev@vger.kernel.org \
    --cc=teg@jklm.no \
    /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).