diff options
author | Takashi Iwai <tiwai@suse.de> | 2015-02-04 08:38:55 -0500 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2015-02-05 03:31:12 -0500 |
commit | 27b917e54bed7156c2b0249969ace34a5f585626 (patch) | |
tree | 5a54f17e61dfbe649e5922af19ad61867850369e /drivers/net/xen-netfront.c | |
parent | c4d33e24b650e3fc3659b8fafe3e88ead731b658 (diff) |
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>
Diffstat (limited to 'drivers/net/xen-netfront.c')
-rw-r--r-- | drivers/net/xen-netfront.c | 62 |
1 files changed, 16 insertions, 46 deletions
diff --git a/drivers/net/xen-netfront.c b/drivers/net/xen-netfront.c index 7cfa6c027c0c..e9b960f0ff32 100644 --- a/drivers/net/xen-netfront.c +++ b/drivers/net/xen-netfront.c | |||
@@ -219,11 +219,7 @@ static grant_ref_t xennet_get_rx_ref(struct netfront_queue *queue, | |||
219 | } | 219 | } |
220 | 220 | ||
221 | #ifdef CONFIG_SYSFS | 221 | #ifdef CONFIG_SYSFS |
222 | static int xennet_sysfs_addif(struct net_device *netdev); | 222 | static const struct attribute_group xennet_dev_group; |
223 | static void xennet_sysfs_delif(struct net_device *netdev); | ||
224 | #else /* !CONFIG_SYSFS */ | ||
225 | #define xennet_sysfs_addif(dev) (0) | ||
226 | #define xennet_sysfs_delif(dev) do { } while (0) | ||
227 | #endif | 223 | #endif |
228 | 224 | ||
229 | static bool xennet_can_sg(struct net_device *dev) | 225 | static bool xennet_can_sg(struct net_device *dev) |
@@ -1317,20 +1313,15 @@ static int netfront_probe(struct xenbus_device *dev, | |||
1317 | 1313 | ||
1318 | info = netdev_priv(netdev); | 1314 | info = netdev_priv(netdev); |
1319 | dev_set_drvdata(&dev->dev, info); | 1315 | dev_set_drvdata(&dev->dev, info); |
1320 | 1316 | #ifdef CONFIG_SYSFS | |
1317 | info->netdev->sysfs_groups[0] = &xennet_dev_group; | ||
1318 | #endif | ||
1321 | err = register_netdev(info->netdev); | 1319 | err = register_netdev(info->netdev); |
1322 | if (err) { | 1320 | if (err) { |
1323 | pr_warn("%s: register_netdev err=%d\n", __func__, err); | 1321 | pr_warn("%s: register_netdev err=%d\n", __func__, err); |
1324 | goto fail; | 1322 | goto fail; |
1325 | } | 1323 | } |
1326 | 1324 | ||
1327 | err = xennet_sysfs_addif(info->netdev); | ||
1328 | if (err) { | ||
1329 | unregister_netdev(info->netdev); | ||
1330 | pr_warn("%s: add sysfs failed err=%d\n", __func__, err); | ||
1331 | goto fail; | ||
1332 | } | ||
1333 | |||
1334 | return 0; | 1325 | return 0; |
1335 | 1326 | ||
1336 | fail: | 1327 | fail: |
@@ -2094,39 +2085,20 @@ static ssize_t store_rxbuf(struct device *dev, | |||
2094 | return len; | 2085 | return len; |
2095 | } | 2086 | } |
2096 | 2087 | ||
2097 | static struct device_attribute xennet_attrs[] = { | 2088 | static DEVICE_ATTR(rxbuf_min, S_IRUGO|S_IWUSR, show_rxbuf, store_rxbuf); |
2098 | __ATTR(rxbuf_min, S_IRUGO|S_IWUSR, show_rxbuf, store_rxbuf), | 2089 | static DEVICE_ATTR(rxbuf_max, S_IRUGO|S_IWUSR, show_rxbuf, store_rxbuf); |
2099 | __ATTR(rxbuf_max, S_IRUGO|S_IWUSR, show_rxbuf, store_rxbuf), | 2090 | static DEVICE_ATTR(rxbuf_cur, S_IRUGO, show_rxbuf, NULL); |
2100 | __ATTR(rxbuf_cur, S_IRUGO, show_rxbuf, NULL), | ||
2101 | }; | ||
2102 | 2091 | ||
2103 | static int xennet_sysfs_addif(struct net_device *netdev) | 2092 | static struct attribute *xennet_dev_attrs[] = { |
2104 | { | 2093 | &dev_attr_rxbuf_min.attr, |
2105 | int i; | 2094 | &dev_attr_rxbuf_max.attr, |
2106 | int err; | 2095 | &dev_attr_rxbuf_cur.attr, |
2107 | 2096 | NULL | |
2108 | for (i = 0; i < ARRAY_SIZE(xennet_attrs); i++) { | 2097 | }; |
2109 | err = device_create_file(&netdev->dev, | ||
2110 | &xennet_attrs[i]); | ||
2111 | if (err) | ||
2112 | goto fail; | ||
2113 | } | ||
2114 | return 0; | ||
2115 | |||
2116 | fail: | ||
2117 | while (--i >= 0) | ||
2118 | device_remove_file(&netdev->dev, &xennet_attrs[i]); | ||
2119 | return err; | ||
2120 | } | ||
2121 | |||
2122 | static void xennet_sysfs_delif(struct net_device *netdev) | ||
2123 | { | ||
2124 | int i; | ||
2125 | |||
2126 | for (i = 0; i < ARRAY_SIZE(xennet_attrs); i++) | ||
2127 | device_remove_file(&netdev->dev, &xennet_attrs[i]); | ||
2128 | } | ||
2129 | 2098 | ||
2099 | static const struct attribute_group xennet_dev_group = { | ||
2100 | .attrs = xennet_dev_attrs | ||
2101 | }; | ||
2130 | #endif /* CONFIG_SYSFS */ | 2102 | #endif /* CONFIG_SYSFS */ |
2131 | 2103 | ||
2132 | static int xennet_remove(struct xenbus_device *dev) | 2104 | static int xennet_remove(struct xenbus_device *dev) |
@@ -2140,8 +2112,6 @@ static int xennet_remove(struct xenbus_device *dev) | |||
2140 | 2112 | ||
2141 | xennet_disconnect_backend(info); | 2113 | xennet_disconnect_backend(info); |
2142 | 2114 | ||
2143 | xennet_sysfs_delif(info->netdev); | ||
2144 | |||
2145 | unregister_netdev(info->netdev); | 2115 | unregister_netdev(info->netdev); |
2146 | 2116 | ||
2147 | for (i = 0; i < num_queues; ++i) { | 2117 | for (i = 0; i < num_queues; ++i) { |