aboutsummaryrefslogtreecommitdiffstats
path: root/fs/sysfs/group.c
diff options
context:
space:
mode:
Diffstat (limited to 'fs/sysfs/group.c')
-rw-r--r--fs/sysfs/group.c96
1 files changed, 48 insertions, 48 deletions
diff --git a/fs/sysfs/group.c b/fs/sysfs/group.c
index 7177532b8f7b..4d00d3996477 100644
--- a/fs/sysfs/group.c
+++ b/fs/sysfs/group.c
@@ -18,7 +18,7 @@
18#include "sysfs.h" 18#include "sysfs.h"
19 19
20 20
21static void remove_files(struct sysfs_dirent *dir_sd, struct kobject *kobj, 21static void remove_files(struct kernfs_node *parent, struct kobject *kobj,
22 const struct attribute_group *grp) 22 const struct attribute_group *grp)
23{ 23{
24 struct attribute *const *attr; 24 struct attribute *const *attr;
@@ -26,13 +26,13 @@ static void remove_files(struct sysfs_dirent *dir_sd, struct kobject *kobj,
26 26
27 if (grp->attrs) 27 if (grp->attrs)
28 for (attr = grp->attrs; *attr; attr++) 28 for (attr = grp->attrs; *attr; attr++)
29 kernfs_remove_by_name(dir_sd, (*attr)->name); 29 kernfs_remove_by_name(parent, (*attr)->name);
30 if (grp->bin_attrs) 30 if (grp->bin_attrs)
31 for (bin_attr = grp->bin_attrs; *bin_attr; bin_attr++) 31 for (bin_attr = grp->bin_attrs; *bin_attr; bin_attr++)
32 sysfs_remove_bin_file(kobj, *bin_attr); 32 sysfs_remove_bin_file(kobj, *bin_attr);
33} 33}
34 34
35static int create_files(struct sysfs_dirent *dir_sd, struct kobject *kobj, 35static int create_files(struct kernfs_node *parent, struct kobject *kobj,
36 const struct attribute_group *grp, int update) 36 const struct attribute_group *grp, int update)
37{ 37{
38 struct attribute *const *attr; 38 struct attribute *const *attr;
@@ -49,20 +49,20 @@ static int create_files(struct sysfs_dirent *dir_sd, struct kobject *kobj,
49 * re-adding (if required) the file. 49 * re-adding (if required) the file.
50 */ 50 */
51 if (update) 51 if (update)
52 kernfs_remove_by_name(dir_sd, (*attr)->name); 52 kernfs_remove_by_name(parent, (*attr)->name);
53 if (grp->is_visible) { 53 if (grp->is_visible) {
54 mode = grp->is_visible(kobj, *attr, i); 54 mode = grp->is_visible(kobj, *attr, i);
55 if (!mode) 55 if (!mode)
56 continue; 56 continue;
57 } 57 }
58 error = sysfs_add_file_mode_ns(dir_sd, *attr, false, 58 error = sysfs_add_file_mode_ns(parent, *attr, false,
59 (*attr)->mode | mode, 59 (*attr)->mode | mode,
60 NULL); 60 NULL);
61 if (unlikely(error)) 61 if (unlikely(error))
62 break; 62 break;
63 } 63 }
64 if (error) { 64 if (error) {
65 remove_files(dir_sd, kobj, grp); 65 remove_files(parent, kobj, grp);
66 goto exit; 66 goto exit;
67 } 67 }
68 } 68 }
@@ -76,7 +76,7 @@ static int create_files(struct sysfs_dirent *dir_sd, struct kobject *kobj,
76 break; 76 break;
77 } 77 }
78 if (error) 78 if (error)
79 remove_files(dir_sd, kobj, grp); 79 remove_files(parent, kobj, grp);
80 } 80 }
81exit: 81exit:
82 return error; 82 return error;
@@ -86,7 +86,7 @@ exit:
86static int internal_create_group(struct kobject *kobj, int update, 86static int internal_create_group(struct kobject *kobj, int update,
87 const struct attribute_group *grp) 87 const struct attribute_group *grp)
88{ 88{
89 struct sysfs_dirent *sd; 89 struct kernfs_node *kn;
90 int error; 90 int error;
91 91
92 BUG_ON(!kobj || (!update && !kobj->sd)); 92 BUG_ON(!kobj || (!update && !kobj->sd));
@@ -100,21 +100,21 @@ static int internal_create_group(struct kobject *kobj, int update,
100 return -EINVAL; 100 return -EINVAL;
101 } 101 }
102 if (grp->name) { 102 if (grp->name) {
103 sd = kernfs_create_dir(kobj->sd, grp->name, kobj); 103 kn = kernfs_create_dir(kobj->sd, grp->name, kobj);
104 if (IS_ERR(sd)) { 104 if (IS_ERR(kn)) {
105 if (PTR_ERR(sd) == -EEXIST) 105 if (PTR_ERR(kn) == -EEXIST)
106 sysfs_warn_dup(kobj->sd, grp->name); 106 sysfs_warn_dup(kobj->sd, grp->name);
107 return PTR_ERR(sd); 107 return PTR_ERR(kn);
108 } 108 }
109 } else 109 } else
110 sd = kobj->sd; 110 kn = kobj->sd;
111 kernfs_get(sd); 111 kernfs_get(kn);
112 error = create_files(sd, kobj, grp, update); 112 error = create_files(kn, kobj, grp, update);
113 if (error) { 113 if (error) {
114 if (grp->name) 114 if (grp->name)
115 kernfs_remove(sd); 115 kernfs_remove(kn);
116 } 116 }
117 kernfs_put(sd); 117 kernfs_put(kn);
118 return error; 118 return error;
119} 119}
120 120
@@ -204,27 +204,27 @@ EXPORT_SYMBOL_GPL(sysfs_update_group);
204void sysfs_remove_group(struct kobject *kobj, 204void sysfs_remove_group(struct kobject *kobj,
205 const struct attribute_group *grp) 205 const struct attribute_group *grp)
206{ 206{
207 struct sysfs_dirent *dir_sd = kobj->sd; 207 struct kernfs_node *parent = kobj->sd;
208 struct sysfs_dirent *sd; 208 struct kernfs_node *kn;
209 209
210 if (grp->name) { 210 if (grp->name) {
211 sd = kernfs_find_and_get(dir_sd, grp->name); 211 kn = kernfs_find_and_get(parent, grp->name);
212 if (!sd) { 212 if (!kn) {
213 WARN(!sd, KERN_WARNING 213 WARN(!kn, KERN_WARNING
214 "sysfs group %p not found for kobject '%s'\n", 214 "sysfs group %p not found for kobject '%s'\n",
215 grp, kobject_name(kobj)); 215 grp, kobject_name(kobj));
216 return; 216 return;
217 } 217 }
218 } else { 218 } else {
219 sd = dir_sd; 219 kn = parent;
220 kernfs_get(sd); 220 kernfs_get(kn);
221 } 221 }
222 222
223 remove_files(sd, kobj, grp); 223 remove_files(kn, kobj, grp);
224 if (grp->name) 224 if (grp->name)
225 kernfs_remove(sd); 225 kernfs_remove(kn);
226 226
227 kernfs_put(sd); 227 kernfs_put(kn);
228} 228}
229EXPORT_SYMBOL_GPL(sysfs_remove_group); 229EXPORT_SYMBOL_GPL(sysfs_remove_group);
230 230
@@ -260,22 +260,22 @@ EXPORT_SYMBOL_GPL(sysfs_remove_groups);
260int sysfs_merge_group(struct kobject *kobj, 260int sysfs_merge_group(struct kobject *kobj,
261 const struct attribute_group *grp) 261 const struct attribute_group *grp)
262{ 262{
263 struct sysfs_dirent *dir_sd; 263 struct kernfs_node *parent;
264 int error = 0; 264 int error = 0;
265 struct attribute *const *attr; 265 struct attribute *const *attr;
266 int i; 266 int i;
267 267
268 dir_sd = kernfs_find_and_get(kobj->sd, grp->name); 268 parent = kernfs_find_and_get(kobj->sd, grp->name);
269 if (!dir_sd) 269 if (!parent)
270 return -ENOENT; 270 return -ENOENT;
271 271
272 for ((i = 0, attr = grp->attrs); *attr && !error; (++i, ++attr)) 272 for ((i = 0, attr = grp->attrs); *attr && !error; (++i, ++attr))
273 error = sysfs_add_file(dir_sd, *attr, false); 273 error = sysfs_add_file(parent, *attr, false);
274 if (error) { 274 if (error) {
275 while (--i >= 0) 275 while (--i >= 0)
276 kernfs_remove_by_name(dir_sd, (*--attr)->name); 276 kernfs_remove_by_name(parent, (*--attr)->name);
277 } 277 }
278 kernfs_put(dir_sd); 278 kernfs_put(parent);
279 279
280 return error; 280 return error;
281} 281}
@@ -289,14 +289,14 @@ EXPORT_SYMBOL_GPL(sysfs_merge_group);
289void sysfs_unmerge_group(struct kobject *kobj, 289void sysfs_unmerge_group(struct kobject *kobj,
290 const struct attribute_group *grp) 290 const struct attribute_group *grp)
291{ 291{
292 struct sysfs_dirent *dir_sd; 292 struct kernfs_node *parent;
293 struct attribute *const *attr; 293 struct attribute *const *attr;
294 294
295 dir_sd = kernfs_find_and_get(kobj->sd, grp->name); 295 parent = kernfs_find_and_get(kobj->sd, grp->name);
296 if (dir_sd) { 296 if (parent) {
297 for (attr = grp->attrs; *attr; ++attr) 297 for (attr = grp->attrs; *attr; ++attr)
298 kernfs_remove_by_name(dir_sd, (*attr)->name); 298 kernfs_remove_by_name(parent, (*attr)->name);
299 kernfs_put(dir_sd); 299 kernfs_put(parent);
300 } 300 }
301} 301}
302EXPORT_SYMBOL_GPL(sysfs_unmerge_group); 302EXPORT_SYMBOL_GPL(sysfs_unmerge_group);
@@ -311,15 +311,15 @@ EXPORT_SYMBOL_GPL(sysfs_unmerge_group);
311int sysfs_add_link_to_group(struct kobject *kobj, const char *group_name, 311int sysfs_add_link_to_group(struct kobject *kobj, const char *group_name,
312 struct kobject *target, const char *link_name) 312 struct kobject *target, const char *link_name)
313{ 313{
314 struct sysfs_dirent *dir_sd; 314 struct kernfs_node *parent;
315 int error = 0; 315 int error = 0;
316 316
317 dir_sd = kernfs_find_and_get(kobj->sd, group_name); 317 parent = kernfs_find_and_get(kobj->sd, group_name);
318 if (!dir_sd) 318 if (!parent)
319 return -ENOENT; 319 return -ENOENT;
320 320
321 error = sysfs_create_link_sd(dir_sd, target, link_name); 321 error = sysfs_create_link_sd(parent, target, link_name);
322 kernfs_put(dir_sd); 322 kernfs_put(parent);
323 323
324 return error; 324 return error;
325} 325}
@@ -334,12 +334,12 @@ EXPORT_SYMBOL_GPL(sysfs_add_link_to_group);
334void sysfs_remove_link_from_group(struct kobject *kobj, const char *group_name, 334void sysfs_remove_link_from_group(struct kobject *kobj, const char *group_name,
335 const char *link_name) 335 const char *link_name)
336{ 336{
337 struct sysfs_dirent *dir_sd; 337 struct kernfs_node *parent;
338 338
339 dir_sd = kernfs_find_and_get(kobj->sd, group_name); 339 parent = kernfs_find_and_get(kobj->sd, group_name);
340 if (dir_sd) { 340 if (parent) {
341 kernfs_remove_by_name(dir_sd, link_name); 341 kernfs_remove_by_name(parent, link_name);
342 kernfs_put(dir_sd); 342 kernfs_put(parent);
343 } 343 }
344} 344}
345EXPORT_SYMBOL_GPL(sysfs_remove_link_from_group); 345EXPORT_SYMBOL_GPL(sysfs_remove_link_from_group);