diff options
author | Takashi Iwai <tiwai@suse.de> | 2015-02-05 15:38:58 -0500 |
---|---|---|
committer | David Vrabel <david.vrabel@citrix.com> | 2015-03-16 10:49:13 -0400 |
commit | 4644e5ab06dda96f7080569992202e1aec8d3b07 (patch) | |
tree | 5352e490833cbc5b9c374c5c6957d42b2f924fbc /drivers/xen/pcpu.c | |
parent | 06e5801b8cb3fc057d88cb4dc03c0b64b2744cda (diff) |
xen: pcpu: Use static attribute groups for sysfs entry
Instead of manual calls of device_create_file() and
device_remove_file(), assign the static attribute groups to the device
to register. The conditional build of sysfs is done in is_visible
callback instead.
Signed-off-by: Takashi Iwai <tiwai@suse.de>
Signed-off-by: David Vrabel <david.vrabel@citrix.com>
Diffstat (limited to 'drivers/xen/pcpu.c')
-rw-r--r-- | drivers/xen/pcpu.c | 44 |
1 files changed, 28 insertions, 16 deletions
diff --git a/drivers/xen/pcpu.c b/drivers/xen/pcpu.c index 0aac403d53fd..49e88f2ce7a1 100644 --- a/drivers/xen/pcpu.c +++ b/drivers/xen/pcpu.c | |||
@@ -132,6 +132,33 @@ static ssize_t __ref store_online(struct device *dev, | |||
132 | } | 132 | } |
133 | static DEVICE_ATTR(online, S_IRUGO | S_IWUSR, show_online, store_online); | 133 | static DEVICE_ATTR(online, S_IRUGO | S_IWUSR, show_online, store_online); |
134 | 134 | ||
135 | static struct attribute *pcpu_dev_attrs[] = { | ||
136 | &dev_attr_online.attr, | ||
137 | NULL | ||
138 | }; | ||
139 | |||
140 | static umode_t pcpu_dev_is_visible(struct kobject *kobj, | ||
141 | struct attribute *attr, int idx) | ||
142 | { | ||
143 | struct device *dev = kobj_to_dev(kobj); | ||
144 | /* | ||
145 | * Xen never offline cpu0 due to several restrictions | ||
146 | * and assumptions. This basically doesn't add a sys control | ||
147 | * to user, one cannot attempt to offline BSP. | ||
148 | */ | ||
149 | return dev->id ? attr->mode : 0; | ||
150 | } | ||
151 | |||
152 | static const struct attribute_group pcpu_dev_group = { | ||
153 | .attrs = pcpu_dev_attrs, | ||
154 | .is_visible = pcpu_dev_is_visible, | ||
155 | }; | ||
156 | |||
157 | static const struct attribute_group *pcpu_dev_groups[] = { | ||
158 | &pcpu_dev_group, | ||
159 | NULL | ||
160 | }; | ||
161 | |||
135 | static bool xen_pcpu_online(uint32_t flags) | 162 | static bool xen_pcpu_online(uint32_t flags) |
136 | { | 163 | { |
137 | return !!(flags & XEN_PCPU_FLAGS_ONLINE); | 164 | return !!(flags & XEN_PCPU_FLAGS_ONLINE); |
@@ -181,9 +208,6 @@ static void unregister_and_remove_pcpu(struct pcpu *pcpu) | |||
181 | return; | 208 | return; |
182 | 209 | ||
183 | dev = &pcpu->dev; | 210 | dev = &pcpu->dev; |
184 | if (dev->id) | ||
185 | device_remove_file(dev, &dev_attr_online); | ||
186 | |||
187 | /* pcpu remove would be implicitly done */ | 211 | /* pcpu remove would be implicitly done */ |
188 | device_unregister(dev); | 212 | device_unregister(dev); |
189 | } | 213 | } |
@@ -200,6 +224,7 @@ static int register_pcpu(struct pcpu *pcpu) | |||
200 | dev->bus = &xen_pcpu_subsys; | 224 | dev->bus = &xen_pcpu_subsys; |
201 | dev->id = pcpu->cpu_id; | 225 | dev->id = pcpu->cpu_id; |
202 | dev->release = pcpu_release; | 226 | dev->release = pcpu_release; |
227 | dev->groups = pcpu_dev_groups; | ||
203 | 228 | ||
204 | err = device_register(dev); | 229 | err = device_register(dev); |
205 | if (err) { | 230 | if (err) { |
@@ -207,19 +232,6 @@ static int register_pcpu(struct pcpu *pcpu) | |||
207 | return err; | 232 | return err; |
208 | } | 233 | } |
209 | 234 | ||
210 | /* | ||
211 | * Xen never offline cpu0 due to several restrictions | ||
212 | * and assumptions. This basically doesn't add a sys control | ||
213 | * to user, one cannot attempt to offline BSP. | ||
214 | */ | ||
215 | if (dev->id) { | ||
216 | err = device_create_file(dev, &dev_attr_online); | ||
217 | if (err) { | ||
218 | device_unregister(dev); | ||
219 | return err; | ||
220 | } | ||
221 | } | ||
222 | |||
223 | return 0; | 235 | return 0; |
224 | } | 236 | } |
225 | 237 | ||