From fbe0d04d5c63435b5a0c198e28055cbb24f05490 Mon Sep 17 00:00:00 2001 From: Arnaldo Carvalho de Melo Date: Tue, 28 Oct 2003 20:20:49 -0800 Subject: [PATCH] [NET]: Introduce dev_getbyfirsthwtype. --- include/linux/netdevice.h | 2 ++ net/core/dev.c | 26 ++++++++++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h index 2533f7b9c7017..1d79d6e496727 100644 --- a/include/linux/netdevice.h +++ b/include/linux/netdevice.h @@ -498,6 +498,8 @@ extern void probe_old_netdevs(void); extern int netdev_boot_setup_add(char *name, struct ifmap *map); extern int netdev_boot_setup_check(struct net_device *dev); extern struct net_device *dev_getbyhwaddr(unsigned short type, char *hwaddr); +extern struct net_device *__dev_getfirstbyhwtype(unsigned short type); +extern struct net_device *dev_getfirstbyhwtype(unsigned short type); extern void dev_add_pack(struct packet_type *pt); extern void dev_remove_pack(struct packet_type *pt); extern void __dev_remove_pack(struct packet_type *pt); diff --git a/net/core/dev.c b/net/core/dev.c index f336cf2e1e847..78eea438fe074 100644 --- a/net/core/dev.c +++ b/net/core/dev.c @@ -550,6 +550,32 @@ struct net_device *dev_getbyhwaddr(unsigned short type, char *ha) return dev; } +struct net_device *__dev_getfirstbyhwtype(unsigned short type) +{ + struct net_device *dev; + + for (dev = dev_base; dev; dev = dev->next) + if (dev->type == type) + break; + return dev; +} + +EXPORT_SYMBOL(__dev_getfirstbyhwtype); + +struct net_device *dev_getfirstbyhwtype(unsigned short type) +{ + struct net_device *dev; + + rtnl_lock(); + dev = __dev_getfirstbyhwtype(type); + if (dev) + dev_hold(dev); + rtnl_unlock(); + return dev; +} + +EXPORT_SYMBOL(dev_getfirstbyhwtype); + /** * dev_get_by_flags - find any device with given flags * @if_flags: IFF_* values -- 2.53.0