Skip to content

Commit 388975c

Browse files
htejungregkh
authored andcommitted
sysfs: clean up sysfs_get_dirent()
The pre-existing sysfs interfaces which take explicit namespace argument are weird in that they place the optional @ns in front of @name which is contrary to the established convention. For example, we end up forcing vast majority of sysfs_get_dirent() users to do sysfs_get_dirent(parent, NULL, name), which is silly and error-prone especially as @ns and @name may be interchanged without causing compilation warning. This renames sysfs_get_dirent() to sysfs_get_dirent_ns() and swap the positions of @name and @ns, and sysfs_get_dirent() is now a wrapper around sysfs_get_dirent_ns(). This makes confusions a lot less likely. There are other interfaces which take @ns before @name. They'll be updated by following patches. This patch doesn't introduce any functional changes. v2: EXPORT_SYMBOL_GPL() wasn't updated leading to undefined symbol error on module builds. Reported by build test robot. Fixed. Signed-off-by: Tejun Heo <tj@kernel.org> Cc: Eric W. Biederman <ebiederm@xmission.com> Cc: Kay Sievers <kay@vrfy.org> Cc: Fengguang Wu <fengguang.wu@intel.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent cb26a31 commit 388975c

10 files changed

Lines changed: 31 additions & 28 deletions

File tree

‎drivers/gpio/gpiolib.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,7 @@ static int gpio_setup_irq(struct gpio_desc *desc, struct device *dev,
408408
IRQF_TRIGGER_FALLING : IRQF_TRIGGER_RISING;
409409

410410
if (!value_sd) {
411-
value_sd = sysfs_get_dirent(dev->kobj.sd, NULL, "value");
411+
value_sd = sysfs_get_dirent(dev->kobj.sd, "value");
412412
if (!value_sd) {
413413
ret = -ENODEV;
414414
goto err_out;

‎drivers/md/bitmap.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1654,9 +1654,9 @@ int bitmap_create(struct mddev *mddev)
16541654
bitmap->mddev = mddev;
16551655

16561656
if (mddev->kobj.sd)
1657-
bm = sysfs_get_dirent(mddev->kobj.sd, NULL, "bitmap");
1657+
bm = sysfs_get_dirent(mddev->kobj.sd, "bitmap");
16581658
if (bm) {
1659-
bitmap->sysfs_can_clear = sysfs_get_dirent(bm, NULL, "can_clear");
1659+
bitmap->sysfs_can_clear = sysfs_get_dirent(bm, "can_clear");
16601660
sysfs_put(bm);
16611661
} else
16621662
bitmap->sysfs_can_clear = NULL;

‎drivers/md/md.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3555,7 +3555,7 @@ level_store(struct mddev *mddev, const char *buf, size_t len)
35553555
printk(KERN_WARNING
35563556
"md: cannot register extra attributes for %s\n",
35573557
mdname(mddev));
3558-
mddev->sysfs_action = sysfs_get_dirent(mddev->kobj.sd, NULL, "sync_action");
3558+
mddev->sysfs_action = sysfs_get_dirent(mddev->kobj.sd, "sync_action");
35593559
}
35603560
if (mddev->pers->sync_request != NULL &&
35613561
pers->sync_request == NULL) {

‎drivers/md/md.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -501,7 +501,7 @@ extern struct attribute_group md_bitmap_group;
501501
static inline struct sysfs_dirent *sysfs_get_dirent_safe(struct sysfs_dirent *sd, char *name)
502502
{
503503
if (sd)
504-
return sysfs_get_dirent(sd, NULL, name);
504+
return sysfs_get_dirent(sd, name);
505505
return sd;
506506
}
507507
static inline void sysfs_notify_dirent_safe(struct sysfs_dirent *sd)

‎fs/sysfs/dir.c‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -630,9 +630,10 @@ struct sysfs_dirent *sysfs_find_dirent(struct sysfs_dirent *parent_sd,
630630
}
631631

632632
/**
633-
* sysfs_get_dirent - find and get sysfs_dirent with the given name
633+
* sysfs_get_dirent_ns - find and get sysfs_dirent with the given name
634634
* @parent_sd: sysfs_dirent to search under
635635
* @name: name to look for
636+
* @ns: the namespace tag to use
636637
*
637638
* Look for sysfs_dirent with name @name under @parent_sd and get
638639
* it if found.
@@ -643,9 +644,9 @@ struct sysfs_dirent *sysfs_find_dirent(struct sysfs_dirent *parent_sd,
643644
* RETURNS:
644645
* Pointer to sysfs_dirent if found, NULL if not.
645646
*/
646-
struct sysfs_dirent *sysfs_get_dirent(struct sysfs_dirent *parent_sd,
647-
const void *ns,
648-
const unsigned char *name)
647+
struct sysfs_dirent *sysfs_get_dirent_ns(struct sysfs_dirent *parent_sd,
648+
const unsigned char *name,
649+
const void *ns)
649650
{
650651
struct sysfs_dirent *sd;
651652

@@ -656,7 +657,7 @@ struct sysfs_dirent *sysfs_get_dirent(struct sysfs_dirent *parent_sd,
656657

657658
return sd;
658659
}
659-
EXPORT_SYMBOL_GPL(sysfs_get_dirent);
660+
EXPORT_SYMBOL_GPL(sysfs_get_dirent_ns);
660661

661662
static int create_dir(struct kobject *kobj, struct sysfs_dirent *parent_sd,
662663
const void *ns, const char *name, struct sysfs_dirent **p_sd)

‎fs/sysfs/file.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -563,7 +563,7 @@ int sysfs_add_file_to_group(struct kobject *kobj,
563563
int error;
564564

565565
if (group)
566-
dir_sd = sysfs_get_dirent(kobj->sd, NULL, group);
566+
dir_sd = sysfs_get_dirent(kobj->sd, group);
567567
else
568568
dir_sd = sysfs_get(kobj->sd);
569569

@@ -645,7 +645,7 @@ void sysfs_remove_file_from_group(struct kobject *kobj,
645645
struct sysfs_dirent *dir_sd;
646646

647647
if (group)
648-
dir_sd = sysfs_get_dirent(kobj->sd, NULL, group);
648+
dir_sd = sysfs_get_dirent(kobj->sd, group);
649649
else
650650
dir_sd = sysfs_get(kobj->sd);
651651
if (dir_sd) {

‎fs/sysfs/group.c‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ void sysfs_remove_group(struct kobject *kobj,
207207
struct sysfs_dirent *sd;
208208

209209
if (grp->name) {
210-
sd = sysfs_get_dirent(dir_sd, NULL, grp->name);
210+
sd = sysfs_get_dirent(dir_sd, grp->name);
211211
if (!sd) {
212212
WARN(!sd, KERN_WARNING
213213
"sysfs group %p not found for kobject '%s'\n",
@@ -262,7 +262,7 @@ int sysfs_merge_group(struct kobject *kobj,
262262
struct attribute *const *attr;
263263
int i;
264264

265-
dir_sd = sysfs_get_dirent(kobj->sd, NULL, grp->name);
265+
dir_sd = sysfs_get_dirent(kobj->sd, grp->name);
266266
if (!dir_sd)
267267
return -ENOENT;
268268

@@ -289,7 +289,7 @@ void sysfs_unmerge_group(struct kobject *kobj,
289289
struct sysfs_dirent *dir_sd;
290290
struct attribute *const *attr;
291291

292-
dir_sd = sysfs_get_dirent(kobj->sd, NULL, grp->name);
292+
dir_sd = sysfs_get_dirent(kobj->sd, grp->name);
293293
if (dir_sd) {
294294
for (attr = grp->attrs; *attr; ++attr)
295295
sysfs_hash_and_remove(dir_sd, NULL, (*attr)->name);
@@ -311,7 +311,7 @@ int sysfs_add_link_to_group(struct kobject *kobj, const char *group_name,
311311
struct sysfs_dirent *dir_sd;
312312
int error = 0;
313313

314-
dir_sd = sysfs_get_dirent(kobj->sd, NULL, group_name);
314+
dir_sd = sysfs_get_dirent(kobj->sd, group_name);
315315
if (!dir_sd)
316316
return -ENOENT;
317317

@@ -333,7 +333,7 @@ void sysfs_remove_link_from_group(struct kobject *kobj, const char *group_name,
333333
{
334334
struct sysfs_dirent *dir_sd;
335335

336-
dir_sd = sysfs_get_dirent(kobj->sd, NULL, group_name);
336+
dir_sd = sysfs_get_dirent(kobj->sd, group_name);
337337
if (dir_sd) {
338338
sysfs_hash_and_remove(dir_sd, NULL, link_name);
339339
sysfs_put(dir_sd);

‎fs/sysfs/symlink.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ int sysfs_rename_link_ns(struct kobject *kobj, struct kobject *targ,
191191
old_ns = targ->sd->s_ns;
192192

193193
result = -ENOENT;
194-
sd = sysfs_get_dirent(parent_sd, old_ns, old);
194+
sd = sysfs_get_dirent_ns(parent_sd, old, old_ns);
195195
if (!sd)
196196
goto out;
197197

‎fs/sysfs/sysfs.h‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -164,9 +164,6 @@ void sysfs_addrm_finish(struct sysfs_addrm_cxt *acxt);
164164
struct sysfs_dirent *sysfs_find_dirent(struct sysfs_dirent *parent_sd,
165165
const void *ns,
166166
const unsigned char *name);
167-
struct sysfs_dirent *sysfs_get_dirent(struct sysfs_dirent *parent_sd,
168-
const void *ns,
169-
const unsigned char *name);
170167
struct sysfs_dirent *sysfs_new_dirent(const char *name, umode_t mode, int type);
171168

172169
void release_sysfs_dirent(struct sysfs_dirent *sd);

‎include/linux/sysfs.h‎

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -245,9 +245,9 @@ void sysfs_remove_link_from_group(struct kobject *kobj, const char *group_name,
245245

246246
void sysfs_notify(struct kobject *kobj, const char *dir, const char *attr);
247247
void sysfs_notify_dirent(struct sysfs_dirent *sd);
248-
struct sysfs_dirent *sysfs_get_dirent(struct sysfs_dirent *parent_sd,
249-
const void *ns,
250-
const unsigned char *name);
248+
struct sysfs_dirent *sysfs_get_dirent_ns(struct sysfs_dirent *parent_sd,
249+
const unsigned char *name,
250+
const void *ns);
251251
struct sysfs_dirent *sysfs_get(struct sysfs_dirent *sd);
252252
void sysfs_put(struct sysfs_dirent *sd);
253253

@@ -422,10 +422,9 @@ static inline void sysfs_notify(struct kobject *kobj, const char *dir,
422422
static inline void sysfs_notify_dirent(struct sysfs_dirent *sd)
423423
{
424424
}
425-
static inline
426-
struct sysfs_dirent *sysfs_get_dirent(struct sysfs_dirent *parent_sd,
427-
const void *ns,
428-
const unsigned char *name)
425+
static inline struct sysfs_dirent *
426+
sysfs_get_dirent_ns(struct sysfs_dirent *parent_sd, const unsigned char *name,
427+
const void *ns)
429428
{
430429
return NULL;
431430
}
@@ -462,4 +461,10 @@ static inline int sysfs_rename_link(struct kobject *kobj, struct kobject *target
462461
return sysfs_rename_link_ns(kobj, target, old_name, new_name, NULL);
463462
}
464463

464+
static inline struct sysfs_dirent *
465+
sysfs_get_dirent(struct sysfs_dirent *parent_sd, const unsigned char *name)
466+
{
467+
return sysfs_get_dirent_ns(parent_sd, name, NULL);
468+
}
469+
465470
#endif /* _SYSFS_H_ */

0 commit comments

Comments
 (0)