Skip to content

Commit

Permalink
net: remove single-byte netdev->dev_addr writes
Browse files Browse the repository at this point in the history
Make the drivers which use single-byte netdev addresses
(netdev->addr_len == 1) use the appropriate address setting
helpers.

arcnet copies from int variables and io reads a lot, so
add a helper for arcnet drivers to use.

Similar helper could be reused for phonet and appletalk
but there isn't any good central location where we could
put it, and netdevice.h is already very crowded.

Acked-by: Sebastian Reichel <sebastian.reichel@collabora.com> # for HSI
Link: https://lore.kernel.org/r/20211012142757.4124842-1-kuba@kernel.org
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
  • Loading branch information
Jakub Kicinski committed Oct 13, 2021
1 parent 400f17d commit 13b5ffa
Show file tree
Hide file tree
Showing 13 changed files with 28 additions and 15 deletions.
4 changes: 3 additions & 1 deletion drivers/hsi/clients/ssi_protocol.c
Original file line number Diff line number Diff line change
Expand Up @@ -1055,14 +1055,16 @@ static const struct net_device_ops ssip_pn_ops = {

static void ssip_pn_setup(struct net_device *dev)
{
static const u8 addr = PN_MEDIA_SOS;

dev->features = 0;
dev->netdev_ops = &ssip_pn_ops;
dev->type = ARPHRD_PHONET;
dev->flags = IFF_POINTOPOINT | IFF_NOARP;
dev->mtu = SSIP_DEFAULT_MTU;
dev->hard_header_len = 1;
dev->dev_addr[0] = PN_MEDIA_SOS;
dev->addr_len = 1;
dev_addr_set(dev, &addr);
dev->tx_queue_len = SSIP_TXQUEUE_LEN;

dev->needs_free_netdev = true;
Expand Down
2 changes: 1 addition & 1 deletion drivers/net/appletalk/cops.c
Original file line number Diff line number Diff line change
Expand Up @@ -945,8 +945,8 @@ static int cops_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
dev->broadcast[0] = 0xFF;

/* Set hardware address. */
dev->dev_addr[0] = aa->s_node;
dev->addr_len = 1;
dev_addr_set(dev, &aa->s_node);
return 0;

case SIOCGIFADDR:
Expand Down
3 changes: 1 addition & 2 deletions drivers/net/appletalk/ltpc.c
Original file line number Diff line number Diff line change
Expand Up @@ -846,9 +846,8 @@ static int ltpc_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
set_30 (dev,ltflags);

dev->broadcast[0] = 0xFF;
dev->dev_addr[0] = aa->s_node;

dev->addr_len=1;
dev_addr_set(dev, &aa->s_node);

return 0;

Expand Down
5 changes: 3 additions & 2 deletions drivers/net/arcnet/arc-rimi.c
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,8 @@ static int __init arcrimi_found(struct net_device *dev)
}

/* get and check the station ID from offset 1 in shmem */
dev->dev_addr[0] = arcnet_readb(lp->mem_start, COM9026_REG_R_STATION);
arcnet_set_addr(dev, arcnet_readb(lp->mem_start,
COM9026_REG_R_STATION));

arc_printk(D_NORMAL, dev, "ARCnet RIM I: station %02Xh found at IRQ %d, ShMem %lXh (%ld*%d bytes)\n",
dev->dev_addr[0],
Expand Down Expand Up @@ -324,7 +325,7 @@ static int __init arc_rimi_init(void)
return -ENOMEM;

if (node && node != 0xff)
dev->dev_addr[0] = node;
arcnet_set_addr(dev, node);

dev->mem_start = io;
dev->irq = irq;
Expand Down
5 changes: 5 additions & 0 deletions drivers/net/arcnet/arcdevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,11 @@ netdev_tx_t arcnet_send_packet(struct sk_buff *skb,
struct net_device *dev);
void arcnet_timeout(struct net_device *dev, unsigned int txqueue);

static inline void arcnet_set_addr(struct net_device *dev, u8 addr)
{
dev_addr_set(dev, &addr);
}

/* I/O equivalents */

#ifdef CONFIG_SA1100_CT6001
Expand Down
2 changes: 1 addition & 1 deletion drivers/net/arcnet/com20020-isa.c
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ static int __init com20020_init(void)
return -ENOMEM;

if (node && node != 0xff)
dev->dev_addr[0] = node;
arcnet_set_addr(dev, node);

dev->netdev_ops = &com20020_netdev_ops;

Expand Down
2 changes: 1 addition & 1 deletion drivers/net/arcnet/com20020-pci.c
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ static int com20020pci_probe(struct pci_dev *pdev,

SET_NETDEV_DEV(dev, &pdev->dev);
dev->base_addr = ioaddr;
dev->dev_addr[0] = node;
arcnet_set_addr(dev, node);
dev->sysfs_groups[0] = &com20020_state_group;
dev->irq = pdev->irq;
lp->card_name = "PCI COM20020";
Expand Down
4 changes: 2 additions & 2 deletions drivers/net/arcnet/com20020.c
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ static int com20020_set_hwaddr(struct net_device *dev, void *addr)
struct arcnet_local *lp = netdev_priv(dev);
struct sockaddr *hwaddr = addr;

memcpy(dev->dev_addr, hwaddr->sa_data, 1);
dev_addr_set(dev, hwaddr->sa_data);
com20020_set_subaddress(lp, ioaddr, SUB_NODE);
arcnet_outb(dev->dev_addr[0], ioaddr, COM20020_REG_W_XREG);

Expand Down Expand Up @@ -220,7 +220,7 @@ int com20020_found(struct net_device *dev, int shared)

/* FIXME: do this some other way! */
if (!dev->dev_addr[0])
dev->dev_addr[0] = arcnet_inb(ioaddr, 8);
arcnet_set_addr(dev, arcnet_inb(ioaddr, 8));

com20020_set_subaddress(lp, ioaddr, SUB_SETUP1);
arcnet_outb(lp->setup, ioaddr, COM20020_REG_W_XREG);
Expand Down
2 changes: 1 addition & 1 deletion drivers/net/arcnet/com20020_cs.c
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ static int com20020_probe(struct pcmcia_device *p_dev)
lp->hw.owner = THIS_MODULE;

/* fill in our module parameters as defaults */
dev->dev_addr[0] = node;
arcnet_set_addr(dev, node);

p_dev->resource[0]->flags |= IO_DATA_PATH_WIDTH_8;
p_dev->resource[0]->end = 16;
Expand Down
2 changes: 1 addition & 1 deletion drivers/net/arcnet/com90io.c
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ static int __init com90io_found(struct net_device *dev)

/* get and check the station ID from offset 1 in shmem */

dev->dev_addr[0] = get_buffer_byte(dev, 1);
arcnet_set_addr(dev, get_buffer_byte(dev, 1));

err = register_netdev(dev);
if (err) {
Expand Down
3 changes: 2 additions & 1 deletion drivers/net/arcnet/com90xx.c
Original file line number Diff line number Diff line change
Expand Up @@ -531,7 +531,8 @@ static int __init com90xx_found(int ioaddr, int airq, u_long shmem,
}

/* get and check the station ID from offset 1 in shmem */
dev->dev_addr[0] = arcnet_readb(lp->mem_start, COM9026_REG_R_STATION);
arcnet_set_addr(dev, arcnet_readb(lp->mem_start,
COM9026_REG_R_STATION));

dev->base_addr = ioaddr;

Expand Down
4 changes: 3 additions & 1 deletion drivers/net/usb/cdc-phonet.c
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,8 @@ static const struct net_device_ops usbpn_ops = {

static void usbpn_setup(struct net_device *dev)
{
const u8 addr = PN_MEDIA_USB;

dev->features = 0;
dev->netdev_ops = &usbpn_ops;
dev->header_ops = &phonet_header_ops;
Expand All @@ -284,8 +286,8 @@ static void usbpn_setup(struct net_device *dev)
dev->min_mtu = PHONET_MIN_MTU;
dev->max_mtu = PHONET_MAX_MTU;
dev->hard_header_len = 1;
dev->dev_addr[0] = PN_MEDIA_USB;
dev->addr_len = 1;
dev_addr_set(dev, &addr);
dev->tx_queue_len = 3;

dev->needs_free_netdev = true;
Expand Down
5 changes: 4 additions & 1 deletion drivers/usb/gadget/function/f_phonet.c
Original file line number Diff line number Diff line change
Expand Up @@ -267,15 +267,18 @@ static const struct net_device_ops pn_netdev_ops = {

static void pn_net_setup(struct net_device *dev)
{
const u8 addr = PN_MEDIA_USB;

dev->features = 0;
dev->type = ARPHRD_PHONET;
dev->flags = IFF_POINTOPOINT | IFF_NOARP;
dev->mtu = PHONET_DEV_MTU;
dev->min_mtu = PHONET_MIN_MTU;
dev->max_mtu = PHONET_MAX_MTU;
dev->hard_header_len = 1;
dev->dev_addr[0] = PN_MEDIA_USB;
dev->addr_len = 1;
dev_addr_set(dev, &addr);

dev->tx_queue_len = 1;

dev->netdev_ops = &pn_netdev_ops;
Expand Down

0 comments on commit 13b5ffa

Please sign in to comment.