[PATCH net-next v2 3/8] net: s/dev_get_mac_address/netif_get_mac_address/

Stanislav Fomichev
2025-06-30T16:42:28Z

netif_get_mac_address is used only by tun/tap, so move it into
NETDEV_INTERNAL namespace.

Signed-off-by: Stanislav Fomichev <sdf@fomichev.me>
---
drivers/net/tap.c | 6 ++++--
drivers/net/tun.c | 4 +++-
include/linux/netdevice.h | 2 +-
net/core/dev.c | 4 ++--
net/core/dev_ioctl.c | 3 ++-
net/core/net-sysfs.c | 2 +-
6 files changed, 13 insertions(+), 8 deletions(-)

diff --git a/drivers/net/tap.c b/drivers/net/tap.c
index bdf0788d8e66..4c85770c809b 100644
--- a/drivers/net/tap.c
+++ b/drivers/net/tap.c
@@ -28,6 +28,8 @@

#include "tun_vnet.h"

+MODULE_IMPORT_NS("NETDEV_INTERNAL");
+
#define TAP_IFFEATURES (IFF_VNET_HDR | IFF_MULTI_QUEUE)

static struct proto tap_proto = {
@@ -1000,8 +1002,8 @@ static long tap_ioctl(struct file *file, unsigned int cmd,
return -ENOLINK;
}
ret = 0;
- dev_get_mac_address((struct sockaddr *)&ss, dev_net(tap->dev),
- tap->dev->name);
+ netif_get_mac_address((struct sockaddr *)&ss, dev_net(tap->dev),
+ tap->dev->name);
if (copy_to_user(&ifr->ifr_name, tap->dev->name, IFNAMSIZ) ||
copy_to_user(&ifr->ifr_hwaddr, &ss, sizeof(ifr->ifr_hwaddr)))
ret = -EFAULT;
diff --git a/drivers/net/tun.c b/drivers/net/tun.c
index f8c5e2fd04df..4509ae68decf 100644
--- a/drivers/net/tun.c
+++ b/drivers/net/tun.c
@@ -85,6 +85,8 @@

#include "tun_vnet.h"

+MODULE_IMPORT_NS("NETDEV_INTERNAL");
+
static void tun_default_link_ksettings(struct net_device *dev,
struct ethtool_link_ksettings *cmd);

@@ -3186,7 +3188,7 @@ static long __tun_chr_ioctl(struct file *file, unsigned int cmd,

case SIOCGIFHWADDR:
/* Get hw address */
- dev_get_mac_address(&ifr.ifr_hwaddr, net, tun->dev->name);
+ netif_get_mac_address(&ifr.ifr_hwaddr, net, tun->dev->name);
if (copy_to_user(argp, &ifr, ifreq_len))
ret = -EFAULT;
break;
diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
index ac6b9e68e858..2f3fba5c67c2 100644
--- a/include/linux/netdevice.h
+++ b/include/linux/netdevice.h
@@ -4221,7 +4221,7 @@ int dev_set_mac_address(struct net_device *dev, struct sockaddr_storage *ss,
struct netlink_ext_ack *extack);
int dev_set_mac_address_user(struct net_device *dev, struct sockaddr_storage *ss,
struct netlink_ext_ack *extack);
-int dev_get_mac_address(struct sockaddr *sa, struct net *net, char *dev_name);
+int netif_get_mac_address(struct sockaddr *sa, struct net *net, char *dev_name);
int netif_get_port_parent_id(struct net_device *dev,
struct netdev_phys_item_id *ppid, bool recurse);
bool netdev_port_same_parent_id(struct net_device *a, struct net_device *b);
diff --git a/net/core/dev.c b/net/core/dev.c
index 7d38d080efe0..ff7fde1a1ac9 100644
--- a/net/core/dev.c
+++ b/net/core/dev.c
@@ -9737,7 +9737,7 @@ int netif_set_mac_address(struct net_device *dev, struct sockaddr_storage *ss,
DECLARE_RWSEM(dev_addr_sem);

/* "sa" is a true struct sockaddr with limited "sa_data" member. */
-int dev_get_mac_address(struct sockaddr *sa, struct net *net, char *dev_name)
+int netif_get_mac_address(struct sockaddr *sa, struct net *net, char *dev_name)
{
size_t size = sizeof(sa->sa_data_min);
struct net_device *dev;
@@ -9763,7 +9763,7 @@ int dev_get_mac_address(struct sockaddr *sa, struct net *net, char *dev_name)
up_read(&dev_addr_sem);
return ret;
}
-EXPORT_SYMBOL(dev_get_mac_address);
+EXPORT_SYMBOL_NS_GPL(netif_get_mac_address, "NETDEV_INTERNAL");

int netif_change_carrier(struct net_device *dev, bool new_carrier)
{
diff --git a/net/core/dev_ioctl.c b/net/core/dev_ioctl.c
index 616479e71466..ceb2d63a818a 100644
--- a/net/core/dev_ioctl.c
+++ b/net/core/dev_ioctl.c
@@ -728,7 +728,8 @@ int dev_ioctl(struct net *net, unsigned int cmd, struct ifreq *ifr,
switch (cmd) {
case SIOCGIFHWADDR:
dev_load(net, ifr->ifr_name);
- ret = dev_get_mac_address(&ifr->ifr_hwaddr, net, ifr->ifr_name);
+ ret = netif_get_mac_address(&ifr->ifr_hwaddr, net,
+ ifr->ifr_name);
if (colon)
*colon = ':';
return ret;
diff --git a/net/core/net-sysfs.c b/net/core/net-sysfs.c
index ebb5a6a11bb8..c2783323b589 100644
--- a/net/core/net-sysfs.c
+++ b/net/core/net-sysfs.c
@@ -256,7 +256,7 @@ static ssize_t name_assign_type_show(struct device *dev,
}
static DEVICE_ATTR_RO(name_assign_type);

-/* use same locking rules as GIFHWADDR ioctl's (dev_get_mac_address()) */
+/* use same locking rules as GIFHWADDR ioctl's (netif_get_mac_address()) */
static ssize_t address_show(struct device *dev, struct device_attribute *attr,
char *buf)
{
--
2.49.0