Skip to content

Commit cfec0bc

Browse files
htejungregkh
authored andcommitted
sysfs: @name comes before @ns
Some internal sysfs functions 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. This is confusing and error-prone especially as @ns and @name may be interchanged without causing compilation warning. Swap the positions of @name and @ns in the following internal functions. sysfs_find_dirent() sysfs_rename() sysfs_hash_and_remove() sysfs_name_hash() sysfs_name_compare() create_dir() This patch doesn't introduce any functional changes. Signed-off-by: Tejun Heo <tj@kernel.org> Cc: Eric W. Biederman <ebiederm@xmission.com> Cc: Kay Sievers <kay@vrfy.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 388975c commit cfec0bc

7 files changed

Lines changed: 46 additions & 45 deletions

File tree

‎fs/sysfs/bin.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -497,6 +497,6 @@ EXPORT_SYMBOL_GPL(sysfs_create_bin_file);
497497
void sysfs_remove_bin_file(struct kobject *kobj,
498498
const struct bin_attribute *attr)
499499
{
500-
sysfs_hash_and_remove(kobj->sd, NULL, attr->attr.name);
500+
sysfs_hash_and_remove(kobj->sd, attr->attr.name, NULL);
501501
}
502502
EXPORT_SYMBOL_GPL(sysfs_remove_bin_file);

‎fs/sysfs/dir.c‎

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,12 @@ static DEFINE_IDA(sysfs_ino_ida);
3535

3636
/**
3737
* sysfs_name_hash
38-
* @ns: Namespace tag to hash
3938
* @name: Null terminated string to hash
39+
* @ns: Namespace tag to hash
4040
*
4141
* Returns 31 bit hash of ns + name (so it fits in an off_t )
4242
*/
43-
static unsigned int sysfs_name_hash(const void *ns, const char *name)
43+
static unsigned int sysfs_name_hash(const char *name, const void *ns)
4444
{
4545
unsigned long hash = init_name_hash();
4646
unsigned int len = strlen(name);
@@ -56,8 +56,8 @@ static unsigned int sysfs_name_hash(const void *ns, const char *name)
5656
return hash;
5757
}
5858

59-
static int sysfs_name_compare(unsigned int hash, const void *ns,
60-
const char *name, const struct sysfs_dirent *sd)
59+
static int sysfs_name_compare(unsigned int hash, const char *name,
60+
const void *ns, const struct sysfs_dirent *sd)
6161
{
6262
if (hash != sd->s_hash)
6363
return hash - sd->s_hash;
@@ -69,7 +69,7 @@ static int sysfs_name_compare(unsigned int hash, const void *ns,
6969
static int sysfs_sd_compare(const struct sysfs_dirent *left,
7070
const struct sysfs_dirent *right)
7171
{
72-
return sysfs_name_compare(left->s_hash, left->s_ns, left->s_name,
72+
return sysfs_name_compare(left->s_hash, left->s_name, left->s_ns,
7373
right);
7474
}
7575

@@ -451,7 +451,7 @@ int __sysfs_add_one(struct sysfs_addrm_cxt *acxt, struct sysfs_dirent *sd)
451451
struct sysfs_inode_attrs *ps_iattr;
452452
int ret;
453453

454-
sd->s_hash = sysfs_name_hash(sd->s_ns, sd->s_name);
454+
sd->s_hash = sysfs_name_hash(sd->s_name, sd->s_ns);
455455
sd->s_parent = sysfs_get(acxt->parent_sd);
456456

457457
ret = sysfs_link_sibling(sd);
@@ -596,6 +596,7 @@ void sysfs_addrm_finish(struct sysfs_addrm_cxt *acxt)
596596
* sysfs_find_dirent - find sysfs_dirent with the given name
597597
* @parent_sd: sysfs_dirent to search under
598598
* @name: name to look for
599+
* @ns: the namespace tag to use
599600
*
600601
* Look for sysfs_dirent with name @name under @parent_sd.
601602
*
@@ -606,19 +607,19 @@ void sysfs_addrm_finish(struct sysfs_addrm_cxt *acxt)
606607
* Pointer to sysfs_dirent if found, NULL if not.
607608
*/
608609
struct sysfs_dirent *sysfs_find_dirent(struct sysfs_dirent *parent_sd,
609-
const void *ns,
610-
const unsigned char *name)
610+
const unsigned char *name,
611+
const void *ns)
611612
{
612613
struct rb_node *node = parent_sd->s_dir.children.rb_node;
613614
unsigned int hash;
614615

615-
hash = sysfs_name_hash(ns, name);
616+
hash = sysfs_name_hash(name, ns);
616617
while (node) {
617618
struct sysfs_dirent *sd;
618619
int result;
619620

620621
sd = to_sysfs_dirent(node);
621-
result = sysfs_name_compare(hash, ns, name, sd);
622+
result = sysfs_name_compare(hash, name, ns, sd);
622623
if (result < 0)
623624
node = node->rb_left;
624625
else if (result > 0)
@@ -651,7 +652,7 @@ struct sysfs_dirent *sysfs_get_dirent_ns(struct sysfs_dirent *parent_sd,
651652
struct sysfs_dirent *sd;
652653

653654
mutex_lock(&sysfs_mutex);
654-
sd = sysfs_find_dirent(parent_sd, ns, name);
655+
sd = sysfs_find_dirent(parent_sd, name, ns);
655656
sysfs_get(sd);
656657
mutex_unlock(&sysfs_mutex);
657658

@@ -660,7 +661,8 @@ struct sysfs_dirent *sysfs_get_dirent_ns(struct sysfs_dirent *parent_sd,
660661
EXPORT_SYMBOL_GPL(sysfs_get_dirent_ns);
661662

662663
static int create_dir(struct kobject *kobj, struct sysfs_dirent *parent_sd,
663-
const void *ns, const char *name, struct sysfs_dirent **p_sd)
664+
const char *name, const void *ns,
665+
struct sysfs_dirent **p_sd)
664666
{
665667
umode_t mode = S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO;
666668
struct sysfs_addrm_cxt acxt;
@@ -691,7 +693,7 @@ static int create_dir(struct kobject *kobj, struct sysfs_dirent *parent_sd,
691693
int sysfs_create_subdir(struct kobject *kobj, const char *name,
692694
struct sysfs_dirent **p_sd)
693695
{
694-
return create_dir(kobj, kobj->sd, NULL, name, p_sd);
696+
return create_dir(kobj, kobj->sd, name, NULL, p_sd);
695697
}
696698

697699
/**
@@ -714,7 +716,7 @@ int sysfs_create_dir_ns(struct kobject *kobj, const void *ns)
714716
if (!parent_sd)
715717
return -ENOENT;
716718

717-
error = create_dir(kobj, parent_sd, ns, kobject_name(kobj), &sd);
719+
error = create_dir(kobj, parent_sd, kobject_name(kobj), ns, &sd);
718720
if (!error)
719721
kobj->sd = sd;
720722
return error;
@@ -735,7 +737,7 @@ static struct dentry *sysfs_lookup(struct inode *dir, struct dentry *dentry,
735737
if (parent_sd->s_flags & SYSFS_FLAG_HAS_NS)
736738
ns = sysfs_info(dir->i_sb)->ns;
737739

738-
sd = sysfs_find_dirent(parent_sd, ns, dentry->d_name.name);
740+
sd = sysfs_find_dirent(parent_sd, dentry->d_name.name, ns);
739741

740742
/* no such entry */
741743
if (!sd) {
@@ -823,9 +825,8 @@ void sysfs_remove_dir(struct kobject *kobj)
823825
__sysfs_remove_dir(sd);
824826
}
825827

826-
int sysfs_rename(struct sysfs_dirent *sd,
827-
struct sysfs_dirent *new_parent_sd, const void *new_ns,
828-
const char *new_name)
828+
int sysfs_rename(struct sysfs_dirent *sd, struct sysfs_dirent *new_parent_sd,
829+
const char *new_name, const void *new_ns)
829830
{
830831
int error;
831832

@@ -837,7 +838,7 @@ int sysfs_rename(struct sysfs_dirent *sd,
837838
goto out; /* nothing to rename */
838839

839840
error = -EEXIST;
840-
if (sysfs_find_dirent(new_parent_sd, new_ns, new_name))
841+
if (sysfs_find_dirent(new_parent_sd, new_name, new_ns))
841842
goto out;
842843

843844
/* rename sysfs_dirent */
@@ -858,7 +859,7 @@ int sysfs_rename(struct sysfs_dirent *sd,
858859
sysfs_get(new_parent_sd);
859860
sysfs_put(sd->s_parent);
860861
sd->s_ns = new_ns;
861-
sd->s_hash = sysfs_name_hash(sd->s_ns, sd->s_name);
862+
sd->s_hash = sysfs_name_hash(sd->s_name, sd->s_ns);
862863
sd->s_parent = new_parent_sd;
863864
sysfs_link_sibling(sd);
864865

@@ -873,7 +874,7 @@ int sysfs_rename_dir_ns(struct kobject *kobj, const char *new_name,
873874
{
874875
struct sysfs_dirent *parent_sd = kobj->sd->s_parent;
875876

876-
return sysfs_rename(kobj->sd, parent_sd, new_ns, new_name);
877+
return sysfs_rename(kobj->sd, parent_sd, new_name, new_ns);
877878
}
878879

879880
int sysfs_move_dir_ns(struct kobject *kobj, struct kobject *new_parent_kobj,
@@ -886,7 +887,7 @@ int sysfs_move_dir_ns(struct kobject *kobj, struct kobject *new_parent_kobj,
886887
new_parent_sd = new_parent_kobj && new_parent_kobj->sd ?
887888
new_parent_kobj->sd : &sysfs_root;
888889

889-
return sysfs_rename(sd, new_parent_sd, new_ns, sd->s_name);
890+
return sysfs_rename(sd, new_parent_sd, sd->s_name, new_ns);
890891
}
891892

892893
/* Relationship between s_mode and the DT_xxx types */

‎fs/sysfs/file.c‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -466,9 +466,9 @@ void sysfs_notify(struct kobject *k, const char *dir, const char *attr)
466466
mutex_lock(&sysfs_mutex);
467467

468468
if (sd && dir)
469-
sd = sysfs_find_dirent(sd, NULL, dir);
469+
sd = sysfs_find_dirent(sd, dir, NULL);
470470
if (sd && attr)
471-
sd = sysfs_find_dirent(sd, NULL, attr);
471+
sd = sysfs_find_dirent(sd, attr, NULL);
472472
if (sd)
473473
sysfs_notify_dirent(sd);
474474

@@ -594,7 +594,7 @@ int sysfs_chmod_file(struct kobject *kobj, const struct attribute *attr,
594594
mutex_lock(&sysfs_mutex);
595595

596596
rc = -ENOENT;
597-
sd = sysfs_find_dirent(kobj->sd, NULL, attr->name);
597+
sd = sysfs_find_dirent(kobj->sd, attr->name, NULL);
598598
if (!sd)
599599
goto out;
600600

@@ -621,7 +621,7 @@ void sysfs_remove_file_ns(struct kobject *kobj, const struct attribute *attr,
621621
{
622622
struct sysfs_dirent *dir_sd = kobj->sd;
623623

624-
sysfs_hash_and_remove(dir_sd, ns, attr->name);
624+
sysfs_hash_and_remove(dir_sd, attr->name, ns);
625625
}
626626
EXPORT_SYMBOL_GPL(sysfs_remove_file_ns);
627627

@@ -649,7 +649,7 @@ void sysfs_remove_file_from_group(struct kobject *kobj,
649649
else
650650
dir_sd = sysfs_get(kobj->sd);
651651
if (dir_sd) {
652-
sysfs_hash_and_remove(dir_sd, NULL, attr->name);
652+
sysfs_hash_and_remove(dir_sd, attr->name, NULL);
653653
sysfs_put(dir_sd);
654654
}
655655
}

‎fs/sysfs/group.c‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ static void remove_files(struct sysfs_dirent *dir_sd, struct kobject *kobj,
2626

2727
if (grp->attrs)
2828
for (attr = grp->attrs; *attr; attr++)
29-
sysfs_hash_and_remove(dir_sd, NULL, (*attr)->name);
29+
sysfs_hash_and_remove(dir_sd, (*attr)->name, NULL);
3030
if (grp->bin_attrs)
3131
for (bin_attr = grp->bin_attrs; *bin_attr; bin_attr++)
3232
sysfs_remove_bin_file(kobj, *bin_attr);
@@ -49,8 +49,8 @@ static int create_files(struct sysfs_dirent *dir_sd, struct kobject *kobj,
4949
* re-adding (if required) the file.
5050
*/
5151
if (update)
52-
sysfs_hash_and_remove(dir_sd, NULL,
53-
(*attr)->name);
52+
sysfs_hash_and_remove(dir_sd, (*attr)->name,
53+
NULL);
5454
if (grp->is_visible) {
5555
mode = grp->is_visible(kobj, *attr, i);
5656
if (!mode)
@@ -270,7 +270,7 @@ int sysfs_merge_group(struct kobject *kobj,
270270
error = sysfs_add_file(dir_sd, *attr, SYSFS_KOBJ_ATTR);
271271
if (error) {
272272
while (--i >= 0)
273-
sysfs_hash_and_remove(dir_sd, NULL, (*--attr)->name);
273+
sysfs_hash_and_remove(dir_sd, (*--attr)->name, NULL);
274274
}
275275
sysfs_put(dir_sd);
276276

@@ -292,7 +292,7 @@ void sysfs_unmerge_group(struct kobject *kobj,
292292
dir_sd = sysfs_get_dirent(kobj->sd, grp->name);
293293
if (dir_sd) {
294294
for (attr = grp->attrs; *attr; ++attr)
295-
sysfs_hash_and_remove(dir_sd, NULL, (*attr)->name);
295+
sysfs_hash_and_remove(dir_sd, (*attr)->name, NULL);
296296
sysfs_put(dir_sd);
297297
}
298298
}
@@ -335,7 +335,7 @@ void sysfs_remove_link_from_group(struct kobject *kobj, const char *group_name,
335335

336336
dir_sd = sysfs_get_dirent(kobj->sd, group_name);
337337
if (dir_sd) {
338-
sysfs_hash_and_remove(dir_sd, NULL, link_name);
338+
sysfs_hash_and_remove(dir_sd, link_name, NULL);
339339
sysfs_put(dir_sd);
340340
}
341341
}

‎fs/sysfs/inode.c‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -314,8 +314,8 @@ void sysfs_evict_inode(struct inode *inode)
314314
sysfs_put(sd);
315315
}
316316

317-
int sysfs_hash_and_remove(struct sysfs_dirent *dir_sd, const void *ns,
318-
const char *name)
317+
int sysfs_hash_and_remove(struct sysfs_dirent *dir_sd, const char *name,
318+
const void *ns)
319319
{
320320
struct sysfs_addrm_cxt acxt;
321321
struct sysfs_dirent *sd;
@@ -328,7 +328,7 @@ int sysfs_hash_and_remove(struct sysfs_dirent *dir_sd, const void *ns,
328328

329329
sysfs_addrm_start(&acxt, dir_sd);
330330

331-
sd = sysfs_find_dirent(dir_sd, ns, name);
331+
sd = sysfs_find_dirent(dir_sd, name, ns);
332332
if (sd)
333333
sysfs_remove_one(&acxt, sd);
334334

‎fs/sysfs/symlink.c‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ void sysfs_delete_link(struct kobject *kobj, struct kobject *targ,
144144
if (targ->sd)
145145
ns = targ->sd->s_ns;
146146
spin_unlock(&sysfs_assoc_lock);
147-
sysfs_hash_and_remove(kobj->sd, ns, name);
147+
sysfs_hash_and_remove(kobj->sd, name, ns);
148148
}
149149

150150
/**
@@ -161,7 +161,7 @@ void sysfs_remove_link(struct kobject *kobj, const char *name)
161161
else
162162
parent_sd = kobj->sd;
163163

164-
sysfs_hash_and_remove(parent_sd, NULL, name);
164+
sysfs_hash_and_remove(parent_sd, name, NULL);
165165
}
166166
EXPORT_SYMBOL_GPL(sysfs_remove_link);
167167

@@ -201,7 +201,7 @@ int sysfs_rename_link_ns(struct kobject *kobj, struct kobject *targ,
201201
if (sd->s_symlink.target_sd->s_dir.kobj != targ)
202202
goto out;
203203

204-
result = sysfs_rename(sd, parent_sd, new_ns, new);
204+
result = sysfs_rename(sd, parent_sd, new, new_ns);
205205

206206
out:
207207
sysfs_put(sd);

‎fs/sysfs/sysfs.h‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -162,8 +162,8 @@ void sysfs_remove_one(struct sysfs_addrm_cxt *acxt, struct sysfs_dirent *sd);
162162
void sysfs_addrm_finish(struct sysfs_addrm_cxt *acxt);
163163

164164
struct sysfs_dirent *sysfs_find_dirent(struct sysfs_dirent *parent_sd,
165-
const void *ns,
166-
const unsigned char *name);
165+
const unsigned char *name,
166+
const void *ns);
167167
struct sysfs_dirent *sysfs_new_dirent(const char *name, umode_t mode, int type);
168168

169169
void release_sysfs_dirent(struct sysfs_dirent *sd);
@@ -173,7 +173,7 @@ int sysfs_create_subdir(struct kobject *kobj, const char *name,
173173
void sysfs_remove_subdir(struct sysfs_dirent *sd);
174174

175175
int sysfs_rename(struct sysfs_dirent *sd, struct sysfs_dirent *new_parent_sd,
176-
const void *ns, const char *new_name);
176+
const char *new_name, const void *new_ns);
177177

178178
static inline struct sysfs_dirent *__sysfs_get(struct sysfs_dirent *sd)
179179
{
@@ -204,8 +204,8 @@ int sysfs_getattr(struct vfsmount *mnt, struct dentry *dentry,
204204
struct kstat *stat);
205205
int sysfs_setxattr(struct dentry *dentry, const char *name, const void *value,
206206
size_t size, int flags);
207-
int sysfs_hash_and_remove(struct sysfs_dirent *dir_sd, const void *ns,
208-
const char *name);
207+
int sysfs_hash_and_remove(struct sysfs_dirent *dir_sd, const char *name,
208+
const void *ns);
209209
int sysfs_inode_init(void);
210210

211211
/*

0 commit comments

Comments
 (0)