Message ID | 1405596491-5881-2-git-send-email-vfalico@gmail.com |
---|---|
State | Changes Requested, archived |
Headers | show |
On Thu, Jul 17, 2014 at 1:28 PM, Veaceslav Falico <vfalico@gmail.com> wrote: > e() 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. The only caveat is that the device still has a name of type "eth%d", in > which case we cannot use this name as it'll change in the nearest future, > thus return "unnamed net_device". There are also cases when the name is set to emptystring before being populated with the real name later on. You may want to check for that too. Cheers, Tom -- To unsubscribe from this list: send the line "unsubscribe netdev" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
On Thu, Jul 17, 2014 at 03:48:45PM +0200, Tom Gundersen wrote: >On Thu, Jul 17, 2014 at 1:28 PM, Veaceslav Falico <vfalico@gmail.com> wrote: >> e() 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. The only caveat is that the device still has a name of type "eth%d", in >> which case we cannot use this name as it'll change in the nearest future, >> thus return "unnamed net_device". > >There are also cases when the name is set to emptystring before being >populated with the real name later on. You may want to check for that >too. Sure, it'd be easy enough. Out of curiosity - can you point me to where it's an empty string? I'll send v2 now. Thank you! > >Cheers, > >Tom -- To unsubscribe from this list: send the line "unsubscribe netdev" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
On Thu, Jul 17, 2014 at 4:01 PM, Veaceslav Falico <vfalico@gmail.com> wrote: > On Thu, Jul 17, 2014 at 03:48:45PM +0200, Tom Gundersen wrote: >> >> On Thu, Jul 17, 2014 at 1:28 PM, Veaceslav Falico <vfalico@gmail.com> >> wrote: >>> >>> e() 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. The only caveat is that the device still has a name of type "eth%d", >>> in >>> which case we cannot use this name as it'll change in the nearest future, >>> thus return "unnamed net_device". >> >> >> There are also cases when the name is set to emptystring before being >> populated with the real name later on. You may want to check for that >> too. > > > Sure, it'd be easy enough. > > Out of curiosity - can you point me to where it's an empty string? Only a handfull places (and I didn't check if those actually use the print functions before setting the real name): $ git grep alloc_netdev | grep \"\" drivers/net/hamradio/dmascc.c: info->dev[0] = alloc_netdev(0, "", NET_NAME_UNKNOWN, dev_setup); drivers/net/hamradio/dmascc.c: info->dev[1] = alloc_netdev(0, "", NET_NAME_UNKNOWN, dev_setup); drivers/net/ppp/ppp_generic.c: dev = alloc_netdev(sizeof(struct ppp), "", NET_NAME_UNKNOWN, drivers/net/wireless/airo.c: dev = alloc_netdev(sizeof(*ai), "", NET_NAME_UNKNOWN, ether_setup); net/atm/clip.c: dev = alloc_netdev(sizeof(struct clip_priv), "", NET_NAME_UNKNOWN, Cheers, Tom -- To unsubscribe from this list: send the line "unsubscribe netdev" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
On Thu, Jul 17, 2014 at 04:29:21PM +0200, Tom Gundersen wrote: >On Thu, Jul 17, 2014 at 4:01 PM, Veaceslav Falico <vfalico@gmail.com> wrote: >> On Thu, Jul 17, 2014 at 03:48:45PM +0200, Tom Gundersen wrote: >>> >>> On Thu, Jul 17, 2014 at 1:28 PM, Veaceslav Falico <vfalico@gmail.com> >>> wrote: >>>> >>>> e() 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. The only caveat is that the device still has a name of type "eth%d", >>>> in >>>> which case we cannot use this name as it'll change in the nearest future, >>>> thus return "unnamed net_device". >>> >>> >>> There are also cases when the name is set to emptystring before being >>> populated with the real name later on. You may want to check for that >>> too. >> >> >> Sure, it'd be easy enough. >> >> Out of curiosity - can you point me to where it's an empty string? > >Only a handfull places (and I didn't check if those actually use the >print functions before setting the real name): Yeah, indeed, missed those. Sent v2. Thanks a lot! > >$ git grep alloc_netdev | grep \"\" >drivers/net/hamradio/dmascc.c: info->dev[0] = alloc_netdev(0, "", >NET_NAME_UNKNOWN, dev_setup); >drivers/net/hamradio/dmascc.c: info->dev[1] = alloc_netdev(0, "", >NET_NAME_UNKNOWN, dev_setup); >drivers/net/ppp/ppp_generic.c: dev = alloc_netdev(sizeof(struct >ppp), "", NET_NAME_UNKNOWN, >drivers/net/wireless/airo.c: dev = alloc_netdev(sizeof(*ai), "", >NET_NAME_UNKNOWN, ether_setup); >net/atm/clip.c: dev = alloc_netdev(sizeof(struct clip_priv), "", >NET_NAME_UNKNOWN, > >Cheers, > >Tom -- To unsubscribe from this list: send the line "unsubscribe netdev" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h index 15ed750..cde12a3 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 (strchr(dev->name, '%')) + return "(unnamed net_device)"; return dev->name; }
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. The only caveat is that the device still has a name of type "eth%d", in which case we cannot use this name as it'll change in the nearest future, thus return "unnamed net_device". CC: "David S. Miller" <davem@davemloft.net> Signed-off-by: Veaceslav Falico <vfalico@gmail.com> --- include/linux/netdevice.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)