diff options
author | Takashi Iwai <tiwai@suse.de> | 2015-02-05 15:38:59 -0500 |
---|---|---|
committer | David Vrabel <david.vrabel@citrix.com> | 2015-03-16 10:49:13 -0400 |
commit | b6a473a7e1d4f81fc3e355c95982820bb8eae97d (patch) | |
tree | 86ff95a319a255aee35e12cbbbea52add3c56e6e /drivers/xen/xen-balloon.c | |
parent | 4644e5ab06dda96f7080569992202e1aec8d3b07 (diff) |
xen: balloon: Use static attribute groups for sysfs entries
Instead of manual calls of device_create_file(), device_remove_file()
and sysfs_create_group(), assign static attribute groups to the device
to register. This simplifies the code and avoids possible races.
Signed-off-by: Takashi Iwai <tiwai@suse.de>
Signed-off-by: David Vrabel <david.vrabel@citrix.com>
Diffstat (limited to 'drivers/xen/xen-balloon.c')
-rw-r--r-- | drivers/xen/xen-balloon.c | 45 |
1 files changed, 20 insertions, 25 deletions
diff --git a/drivers/xen/xen-balloon.c b/drivers/xen/xen-balloon.c index e555845d61fa..39e7ef8d3957 100644 --- a/drivers/xen/xen-balloon.c +++ b/drivers/xen/xen-balloon.c | |||
@@ -193,13 +193,18 @@ static DEVICE_ATTR(target, S_IRUGO | S_IWUSR, | |||
193 | show_target, store_target); | 193 | show_target, store_target); |
194 | 194 | ||
195 | 195 | ||
196 | static struct device_attribute *balloon_attrs[] = { | 196 | static struct attribute *balloon_attrs[] = { |
197 | &dev_attr_target_kb, | 197 | &dev_attr_target_kb.attr, |
198 | &dev_attr_target, | 198 | &dev_attr_target.attr, |
199 | &dev_attr_schedule_delay.attr, | 199 | &dev_attr_schedule_delay.attr.attr, |
200 | &dev_attr_max_schedule_delay.attr, | 200 | &dev_attr_max_schedule_delay.attr.attr, |
201 | &dev_attr_retry_count.attr, | 201 | &dev_attr_retry_count.attr.attr, |
202 | &dev_attr_max_retry_count.attr | 202 | &dev_attr_max_retry_count.attr.attr, |
203 | NULL | ||
204 | }; | ||
205 | |||
206 | static const struct attribute_group balloon_group = { | ||
207 | .attrs = balloon_attrs | ||
203 | }; | 208 | }; |
204 | 209 | ||
205 | static struct attribute *balloon_info_attrs[] = { | 210 | static struct attribute *balloon_info_attrs[] = { |
@@ -214,6 +219,12 @@ static const struct attribute_group balloon_info_group = { | |||
214 | .attrs = balloon_info_attrs | 219 | .attrs = balloon_info_attrs |
215 | }; | 220 | }; |
216 | 221 | ||
222 | static const struct attribute_group *balloon_groups[] = { | ||
223 | &balloon_group, | ||
224 | &balloon_info_group, | ||
225 | NULL | ||
226 | }; | ||
227 | |||
217 | static struct bus_type balloon_subsys = { | 228 | static struct bus_type balloon_subsys = { |
218 | .name = BALLOON_CLASS_NAME, | 229 | .name = BALLOON_CLASS_NAME, |
219 | .dev_name = BALLOON_CLASS_NAME, | 230 | .dev_name = BALLOON_CLASS_NAME, |
@@ -221,7 +232,7 @@ static struct bus_type balloon_subsys = { | |||
221 | 232 | ||
222 | static int register_balloon(struct device *dev) | 233 | static int register_balloon(struct device *dev) |
223 | { | 234 | { |
224 | int i, error; | 235 | int error; |
225 | 236 | ||
226 | error = subsys_system_register(&balloon_subsys, NULL); | 237 | error = subsys_system_register(&balloon_subsys, NULL); |
227 | if (error) | 238 | if (error) |
@@ -229,6 +240,7 @@ static int register_balloon(struct device *dev) | |||
229 | 240 | ||
230 | dev->id = 0; | 241 | dev->id = 0; |
231 | dev->bus = &balloon_subsys; | 242 | dev->bus = &balloon_subsys; |
243 | dev->groups = balloon_groups; | ||
232 | 244 | ||
233 | error = device_register(dev); | 245 | error = device_register(dev); |
234 | if (error) { | 246 | if (error) { |
@@ -236,24 +248,7 @@ static int register_balloon(struct device *dev) | |||
236 | return error; | 248 | return error; |
237 | } | 249 | } |
238 | 250 | ||
239 | for (i = 0; i < ARRAY_SIZE(balloon_attrs); i++) { | ||
240 | error = device_create_file(dev, balloon_attrs[i]); | ||
241 | if (error) | ||
242 | goto fail; | ||
243 | } | ||
244 | |||
245 | error = sysfs_create_group(&dev->kobj, &balloon_info_group); | ||
246 | if (error) | ||
247 | goto fail; | ||
248 | |||
249 | return 0; | 251 | return 0; |
250 | |||
251 | fail: | ||
252 | while (--i >= 0) | ||
253 | device_remove_file(dev, balloon_attrs[i]); | ||
254 | device_unregister(dev); | ||
255 | bus_unregister(&balloon_subsys); | ||
256 | return error; | ||
257 | } | 252 | } |
258 | 253 | ||
259 | MODULE_LICENSE("GPL"); | 254 | MODULE_LICENSE("GPL"); |