mirror of
https://github.com/FEX-Emu/linux.git
synced 2025-01-14 21:48:49 +00:00
xen-netfront: 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> Acked-by: David Vrabel <david.vrabel@citrix.com> Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
parent
c4d33e24b6
commit
27b917e54b
@ -219,11 +219,7 @@ static grant_ref_t xennet_get_rx_ref(struct netfront_queue *queue,
|
|||||||
}
|
}
|
||||||
|
|
||||||
#ifdef CONFIG_SYSFS
|
#ifdef CONFIG_SYSFS
|
||||||
static int xennet_sysfs_addif(struct net_device *netdev);
|
static const struct attribute_group xennet_dev_group;
|
||||||
static void xennet_sysfs_delif(struct net_device *netdev);
|
|
||||||
#else /* !CONFIG_SYSFS */
|
|
||||||
#define xennet_sysfs_addif(dev) (0)
|
|
||||||
#define xennet_sysfs_delif(dev) do { } while (0)
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static bool xennet_can_sg(struct net_device *dev)
|
static bool xennet_can_sg(struct net_device *dev)
|
||||||
@ -1317,20 +1313,15 @@ static int netfront_probe(struct xenbus_device *dev,
|
|||||||
|
|
||||||
info = netdev_priv(netdev);
|
info = netdev_priv(netdev);
|
||||||
dev_set_drvdata(&dev->dev, info);
|
dev_set_drvdata(&dev->dev, info);
|
||||||
|
#ifdef CONFIG_SYSFS
|
||||||
|
info->netdev->sysfs_groups[0] = &xennet_dev_group;
|
||||||
|
#endif
|
||||||
err = register_netdev(info->netdev);
|
err = register_netdev(info->netdev);
|
||||||
if (err) {
|
if (err) {
|
||||||
pr_warn("%s: register_netdev err=%d\n", __func__, err);
|
pr_warn("%s: register_netdev err=%d\n", __func__, err);
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
err = xennet_sysfs_addif(info->netdev);
|
|
||||||
if (err) {
|
|
||||||
unregister_netdev(info->netdev);
|
|
||||||
pr_warn("%s: add sysfs failed err=%d\n", __func__, err);
|
|
||||||
goto fail;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
fail:
|
fail:
|
||||||
@ -2094,39 +2085,20 @@ static ssize_t store_rxbuf(struct device *dev,
|
|||||||
return len;
|
return len;
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct device_attribute xennet_attrs[] = {
|
static DEVICE_ATTR(rxbuf_min, S_IRUGO|S_IWUSR, show_rxbuf, store_rxbuf);
|
||||||
__ATTR(rxbuf_min, S_IRUGO|S_IWUSR, show_rxbuf, store_rxbuf),
|
static DEVICE_ATTR(rxbuf_max, S_IRUGO|S_IWUSR, show_rxbuf, store_rxbuf);
|
||||||
__ATTR(rxbuf_max, S_IRUGO|S_IWUSR, show_rxbuf, store_rxbuf),
|
static DEVICE_ATTR(rxbuf_cur, S_IRUGO, show_rxbuf, NULL);
|
||||||
__ATTR(rxbuf_cur, S_IRUGO, show_rxbuf, NULL),
|
|
||||||
|
static struct attribute *xennet_dev_attrs[] = {
|
||||||
|
&dev_attr_rxbuf_min.attr,
|
||||||
|
&dev_attr_rxbuf_max.attr,
|
||||||
|
&dev_attr_rxbuf_cur.attr,
|
||||||
|
NULL
|
||||||
};
|
};
|
||||||
|
|
||||||
static int xennet_sysfs_addif(struct net_device *netdev)
|
static const struct attribute_group xennet_dev_group = {
|
||||||
{
|
.attrs = xennet_dev_attrs
|
||||||
int i;
|
};
|
||||||
int err;
|
|
||||||
|
|
||||||
for (i = 0; i < ARRAY_SIZE(xennet_attrs); i++) {
|
|
||||||
err = device_create_file(&netdev->dev,
|
|
||||||
&xennet_attrs[i]);
|
|
||||||
if (err)
|
|
||||||
goto fail;
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
fail:
|
|
||||||
while (--i >= 0)
|
|
||||||
device_remove_file(&netdev->dev, &xennet_attrs[i]);
|
|
||||||
return err;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void xennet_sysfs_delif(struct net_device *netdev)
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
|
|
||||||
for (i = 0; i < ARRAY_SIZE(xennet_attrs); i++)
|
|
||||||
device_remove_file(&netdev->dev, &xennet_attrs[i]);
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif /* CONFIG_SYSFS */
|
#endif /* CONFIG_SYSFS */
|
||||||
|
|
||||||
static int xennet_remove(struct xenbus_device *dev)
|
static int xennet_remove(struct xenbus_device *dev)
|
||||||
@ -2140,8 +2112,6 @@ static int xennet_remove(struct xenbus_device *dev)
|
|||||||
|
|
||||||
xennet_disconnect_backend(info);
|
xennet_disconnect_backend(info);
|
||||||
|
|
||||||
xennet_sysfs_delif(info->netdev);
|
|
||||||
|
|
||||||
unregister_netdev(info->netdev);
|
unregister_netdev(info->netdev);
|
||||||
|
|
||||||
for (i = 0; i < num_queues; ++i) {
|
for (i = 0; i < num_queues; ++i) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user