diff options
author | Takashi Iwai <tiwai@suse.de> | 2015-02-04 08:37:34 -0500 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2015-02-05 03:30:47 -0500 |
commit | c4d33e24b650e3fc3659b8fafe3e88ead731b658 (patch) | |
tree | 6591c2d3ac17fe3961bc167bbd6195fdaae79e64 | |
parent | 7061b2bdd620e4dda449d4d4db69de57751ab289 (diff) |
tun: Use static attribute groups for sysfs entries
Instead of manual calls of device_create_file() and
device_remove_files(), assign the static attribute groups to netdev
groups array. This simplifies the code and avoids the possible
races.
Signed-off-by: Takashi Iwai <tiwai@suse.de>
Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r-- | drivers/net/tun.c | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/drivers/net/tun.c b/drivers/net/tun.c index be196e89ab6c..3ff8cd7bf74d 100644 --- a/drivers/net/tun.c +++ b/drivers/net/tun.c | |||
@@ -1565,6 +1565,17 @@ static DEVICE_ATTR(tun_flags, 0444, tun_show_flags, NULL); | |||
1565 | static DEVICE_ATTR(owner, 0444, tun_show_owner, NULL); | 1565 | static DEVICE_ATTR(owner, 0444, tun_show_owner, NULL); |
1566 | static DEVICE_ATTR(group, 0444, tun_show_group, NULL); | 1566 | static DEVICE_ATTR(group, 0444, tun_show_group, NULL); |
1567 | 1567 | ||
1568 | static struct attribute *tun_dev_attrs[] = { | ||
1569 | &dev_attr_tun_flags.attr, | ||
1570 | &dev_attr_owner.attr, | ||
1571 | &dev_attr_group.attr, | ||
1572 | NULL | ||
1573 | }; | ||
1574 | |||
1575 | static const struct attribute_group tun_attr_group = { | ||
1576 | .attrs = tun_dev_attrs | ||
1577 | }; | ||
1578 | |||
1568 | static int tun_set_iff(struct net *net, struct file *file, struct ifreq *ifr) | 1579 | static int tun_set_iff(struct net *net, struct file *file, struct ifreq *ifr) |
1569 | { | 1580 | { |
1570 | struct tun_struct *tun; | 1581 | struct tun_struct *tun; |
@@ -1645,6 +1656,7 @@ static int tun_set_iff(struct net *net, struct file *file, struct ifreq *ifr) | |||
1645 | dev_net_set(dev, net); | 1656 | dev_net_set(dev, net); |
1646 | dev->rtnl_link_ops = &tun_link_ops; | 1657 | dev->rtnl_link_ops = &tun_link_ops; |
1647 | dev->ifindex = tfile->ifindex; | 1658 | dev->ifindex = tfile->ifindex; |
1659 | dev->sysfs_groups[0] = &tun_attr_group; | ||
1648 | 1660 | ||
1649 | tun = netdev_priv(dev); | 1661 | tun = netdev_priv(dev); |
1650 | tun->dev = dev; | 1662 | tun->dev = dev; |
@@ -1680,11 +1692,6 @@ static int tun_set_iff(struct net *net, struct file *file, struct ifreq *ifr) | |||
1680 | err = register_netdevice(tun->dev); | 1692 | err = register_netdevice(tun->dev); |
1681 | if (err < 0) | 1693 | if (err < 0) |
1682 | goto err_detach; | 1694 | goto err_detach; |
1683 | |||
1684 | if (device_create_file(&tun->dev->dev, &dev_attr_tun_flags) || | ||
1685 | device_create_file(&tun->dev->dev, &dev_attr_owner) || | ||
1686 | device_create_file(&tun->dev->dev, &dev_attr_group)) | ||
1687 | pr_err("Failed to create tun sysfs files\n"); | ||
1688 | } | 1695 | } |
1689 | 1696 | ||
1690 | netif_carrier_on(tun->dev); | 1697 | netif_carrier_on(tun->dev); |