summaryrefslogtreecommitdiff
path: root/drivers/net/tun.c
diff options
context:
space:
mode:
authorTakashi Iwai <tiwai@suse.de>2015-02-04 14:37:34 +0100
committerDavid S. Miller <davem@davemloft.net>2015-02-05 00:30:47 -0800
commitc4d33e24b650e3fc3659b8fafe3e88ead731b658 (patch)
tree6591c2d3ac17fe3961bc167bbd6195fdaae79e64 /drivers/net/tun.c
parent7061b2bdd620e4dda449d4d4db69de57751ab289 (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>
Diffstat (limited to 'drivers/net/tun.c')
-rw-r--r--drivers/net/tun.c17
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);
static DEVICE_ATTR(owner, 0444, tun_show_owner, NULL);
static DEVICE_ATTR(group, 0444, tun_show_group, NULL);
+static struct attribute *tun_dev_attrs[] = {
+ &dev_attr_tun_flags.attr,
+ &dev_attr_owner.attr,
+ &dev_attr_group.attr,
+ NULL
+};
+
+static const struct attribute_group tun_attr_group = {
+ .attrs = tun_dev_attrs
+};
+
static int tun_set_iff(struct net *net, struct file *file, struct ifreq *ifr)
{
struct tun_struct *tun;
@@ -1645,6 +1656,7 @@ static int tun_set_iff(struct net *net, struct file *file, struct ifreq *ifr)
dev_net_set(dev, net);
dev->rtnl_link_ops = &tun_link_ops;
dev->ifindex = tfile->ifindex;
+ dev->sysfs_groups[0] = &tun_attr_group;
tun = netdev_priv(dev);
tun->dev = dev;
@@ -1680,11 +1692,6 @@ static int tun_set_iff(struct net *net, struct file *file, struct ifreq *ifr)
err = register_netdevice(tun->dev);
if (err < 0)
goto err_detach;
-
- if (device_create_file(&tun->dev->dev, &dev_attr_tun_flags) ||
- device_create_file(&tun->dev->dev, &dev_attr_owner) ||
- device_create_file(&tun->dev->dev, &dev_attr_group))
- pr_err("Failed to create tun sysfs files\n");
}
netif_carrier_on(tun->dev);