Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Takashi Iwai and committed by
David S. Miller
27b917e5 c4d33e24

+16 -46
+16 -46
drivers/net/xen-netfront.c
··· 219 219 } 220 220 221 221 #ifdef CONFIG_SYSFS 222 - static int xennet_sysfs_addif(struct net_device *netdev); 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) 222 + static const struct attribute_group xennet_dev_group; 227 223 #endif 228 224 229 225 static bool xennet_can_sg(struct net_device *dev) ··· 1313 1317 1314 1318 info = netdev_priv(netdev); 1315 1319 dev_set_drvdata(&dev->dev, info); 1316 - 1320 + #ifdef CONFIG_SYSFS 1321 + info->netdev->sysfs_groups[0] = &xennet_dev_group; 1322 + #endif 1317 1323 err = register_netdev(info->netdev); 1318 1324 if (err) { 1319 1325 pr_warn("%s: register_netdev err=%d\n", __func__, err); 1320 - goto fail; 1321 - } 1322 - 1323 - err = xennet_sysfs_addif(info->netdev); 1324 - if (err) { 1325 - unregister_netdev(info->netdev); 1326 - pr_warn("%s: add sysfs failed err=%d\n", __func__, err); 1327 1326 goto fail; 1328 1327 } 1329 1328 ··· 2085 2094 return len; 2086 2095 } 2087 2096 2088 - static struct device_attribute xennet_attrs[] = { 2089 - __ATTR(rxbuf_min, S_IRUGO|S_IWUSR, show_rxbuf, store_rxbuf), 2090 - __ATTR(rxbuf_max, S_IRUGO|S_IWUSR, show_rxbuf, store_rxbuf), 2091 - __ATTR(rxbuf_cur, S_IRUGO, show_rxbuf, NULL), 2097 + static DEVICE_ATTR(rxbuf_min, S_IRUGO|S_IWUSR, show_rxbuf, store_rxbuf); 2098 + static DEVICE_ATTR(rxbuf_max, S_IRUGO|S_IWUSR, show_rxbuf, store_rxbuf); 2099 + static DEVICE_ATTR(rxbuf_cur, S_IRUGO, show_rxbuf, NULL); 2100 + 2101 + static struct attribute *xennet_dev_attrs[] = { 2102 + &dev_attr_rxbuf_min.attr, 2103 + &dev_attr_rxbuf_max.attr, 2104 + &dev_attr_rxbuf_cur.attr, 2105 + NULL 2092 2106 }; 2093 2107 2094 - static int xennet_sysfs_addif(struct net_device *netdev) 2095 - { 2096 - int i; 2097 - int err; 2098 - 2099 - for (i = 0; i < ARRAY_SIZE(xennet_attrs); i++) { 2100 - err = device_create_file(&netdev->dev, 2101 - &xennet_attrs[i]); 2102 - if (err) 2103 - goto fail; 2104 - } 2105 - return 0; 2106 - 2107 - fail: 2108 - while (--i >= 0) 2109 - device_remove_file(&netdev->dev, &xennet_attrs[i]); 2110 - return err; 2111 - } 2112 - 2113 - static void xennet_sysfs_delif(struct net_device *netdev) 2114 - { 2115 - int i; 2116 - 2117 - for (i = 0; i < ARRAY_SIZE(xennet_attrs); i++) 2118 - device_remove_file(&netdev->dev, &xennet_attrs[i]); 2119 - } 2120 - 2108 + static const struct attribute_group xennet_dev_group = { 2109 + .attrs = xennet_dev_attrs 2110 + }; 2121 2111 #endif /* CONFIG_SYSFS */ 2122 2112 2123 2113 static int xennet_remove(struct xenbus_device *dev) ··· 2111 2139 dev_dbg(&dev->dev, "%s\n", dev->nodename); 2112 2140 2113 2141 xennet_disconnect_backend(info); 2114 - 2115 - xennet_sysfs_delif(info->netdev); 2116 2142 2117 2143 unregister_netdev(info->netdev); 2118 2144