Skip to content

Commit

Permalink
net: constify netdev->dev_addr
Browse files Browse the repository at this point in the history
Commit 406f42f ("net-next: When a bond have a massive amount
of VLANs...") introduced a rbtree for faster Ethernet address look
up. We converted all users to make modifications via appropriate
helpers, make netdev->dev_addr const.

The update helpers need to upcast from the buffer to
struct netdev_hw_addr.

Signed-off-by: Jakub Kicinski <[email protected]>
Signed-off-by: David S. Miller <[email protected]>
  • Loading branch information
kuba-moo authored and davem330 committed Nov 20, 2021
1 parent c9646a1 commit adeef3e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
14 changes: 5 additions & 9 deletions include/linux/netdevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -2117,7 +2117,7 @@ struct net_device {
* Cache lines mostly used on receive path (including eth_type_trans())
*/
/* Interface address info used in eth_type_trans() */
unsigned char *dev_addr;
const unsigned char *dev_addr;

struct netdev_rx_queue *_rx;
unsigned int num_rx_queues;
Expand Down Expand Up @@ -4268,24 +4268,20 @@ void __hw_addr_unsync_dev(struct netdev_hw_addr_list *list,
void __hw_addr_init(struct netdev_hw_addr_list *list);

/* Functions used for device addresses handling */
void dev_addr_mod(struct net_device *dev, unsigned int offset,
const void *addr, size_t len);

static inline void
__dev_addr_set(struct net_device *dev, const void *addr, size_t len)
{
memcpy(dev->dev_addr, addr, len);
dev_addr_mod(dev, 0, addr, len);
}

static inline void dev_addr_set(struct net_device *dev, const u8 *addr)
{
__dev_addr_set(dev, addr, dev->addr_len);
}

static inline void
dev_addr_mod(struct net_device *dev, unsigned int offset,
const void *addr, size_t len)
{
memcpy(&dev->dev_addr[offset], addr, len);
}

int dev_addr_add(struct net_device *dev, const unsigned char *addr,
unsigned char addr_type);
int dev_addr_del(struct net_device *dev, const unsigned char *addr,
Expand Down
10 changes: 10 additions & 0 deletions net/core/dev_addr_lists.c
Original file line number Diff line number Diff line change
Expand Up @@ -549,6 +549,16 @@ int dev_addr_init(struct net_device *dev)
}
EXPORT_SYMBOL(dev_addr_init);

void dev_addr_mod(struct net_device *dev, unsigned int offset,
const void *addr, size_t len)
{
struct netdev_hw_addr *ha;

ha = container_of(dev->dev_addr, struct netdev_hw_addr, addr[0]);
memcpy(&ha->addr[offset], addr, len);
}
EXPORT_SYMBOL(dev_addr_mod);

/**
* dev_addr_add - Add a device address
* @dev: device
Expand Down

0 comments on commit adeef3e

Please sign in to comment.