Skip to content

Commit f9bb488

Browse files
committed
sysfs: Create mountpoints with sysfs_create_mount_point
This allows for better documentation in the code and it allows for a simpler and fully correct version of fs_fully_visible to be written. The mount points converted and their filesystems are: /sys/hypervisor/s390/ s390_hypfs /sys/kernel/config/ configfs /sys/kernel/debug/ debugfs /sys/firmware/efi/efivars/ efivarfs /sys/fs/fuse/connections/ fusectl /sys/fs/pstore/ pstore /sys/kernel/tracing/ tracefs /sys/fs/cgroup/ cgroup /sys/kernel/security/ securityfs /sys/fs/selinux/ selinuxfs /sys/fs/smackfs/ smackfs Cc: stable@vger.kernel.org Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Signed-off-by: "Eric W. Biederman" <ebiederm@xmission.com>
1 parent 87d2846 commit f9bb488

11 files changed

Lines changed: 40 additions & 65 deletions

File tree

‎arch/s390/hypfs/inode.c‎

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -456,8 +456,6 @@ static const struct super_operations hypfs_s_ops = {
456456
.show_options = hypfs_show_options,
457457
};
458458

459-
static struct kobject *s390_kobj;
460-
461459
static int __init hypfs_init(void)
462460
{
463461
int rc;
@@ -481,18 +479,16 @@ static int __init hypfs_init(void)
481479
rc = -ENODATA;
482480
goto fail_hypfs_sprp_exit;
483481
}
484-
s390_kobj = kobject_create_and_add("s390", hypervisor_kobj);
485-
if (!s390_kobj) {
486-
rc = -ENOMEM;
482+
rc = sysfs_create_mount_point(hypervisor_kobj, "s390");
483+
if (rc)
487484
goto fail_hypfs_diag0c_exit;
488-
}
489485
rc = register_filesystem(&hypfs_type);
490486
if (rc)
491487
goto fail_filesystem;
492488
return 0;
493489

494490
fail_filesystem:
495-
kobject_put(s390_kobj);
491+
sysfs_remove_mount_point(hypervisor_kobj, "s390");
496492
fail_hypfs_diag0c_exit:
497493
hypfs_diag0c_exit();
498494
fail_hypfs_sprp_exit:
@@ -510,7 +506,7 @@ static int __init hypfs_init(void)
510506
static void __exit hypfs_exit(void)
511507
{
512508
unregister_filesystem(&hypfs_type);
513-
kobject_put(s390_kobj);
509+
sysfs_remove_mount_point(hypervisor_kobj, "s390");
514510
hypfs_diag0c_exit();
515511
hypfs_sprp_exit();
516512
hypfs_vm_exit();

‎drivers/firmware/efi/efi.c‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ static int __init parse_efi_cmdline(char *str)
6565
early_param("efi", parse_efi_cmdline);
6666

6767
static struct kobject *efi_kobj;
68-
static struct kobject *efivars_kobj;
6968

7069
/*
7170
* Let's not leave out systab information that snuck into
@@ -212,10 +211,9 @@ static int __init efisubsys_init(void)
212211
goto err_remove_group;
213212

214213
/* and the standard mountpoint for efivarfs */
215-
efivars_kobj = kobject_create_and_add("efivars", efi_kobj);
216-
if (!efivars_kobj) {
214+
error = sysfs_create_mount_point(efi_kobj, "efivars");
215+
if (error) {
217216
pr_err("efivars: Subsystem registration failed.\n");
218-
error = -ENOMEM;
219217
goto err_remove_group;
220218
}
221219

‎fs/configfs/mount.c‎

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,6 @@ void configfs_release_fs(void)
129129
}
130130

131131

132-
static struct kobject *config_kobj;
133-
134132
static int __init configfs_init(void)
135133
{
136134
int err = -ENOMEM;
@@ -141,8 +139,8 @@ static int __init configfs_init(void)
141139
if (!configfs_dir_cachep)
142140
goto out;
143141

144-
config_kobj = kobject_create_and_add("config", kernel_kobj);
145-
if (!config_kobj)
142+
err = sysfs_create_mount_point(kernel_kobj, "config");
143+
if (err)
146144
goto out2;
147145

148146
err = register_filesystem(&configfs_fs_type);
@@ -152,7 +150,7 @@ static int __init configfs_init(void)
152150
return 0;
153151
out3:
154152
pr_err("Unable to register filesystem!\n");
155-
kobject_put(config_kobj);
153+
sysfs_remove_mount_point(kernel_kobj, "config");
156154
out2:
157155
kmem_cache_destroy(configfs_dir_cachep);
158156
configfs_dir_cachep = NULL;
@@ -163,7 +161,7 @@ static int __init configfs_init(void)
163161
static void __exit configfs_exit(void)
164162
{
165163
unregister_filesystem(&configfs_fs_type);
166-
kobject_put(config_kobj);
164+
sysfs_remove_mount_point(kernel_kobj, "config");
167165
kmem_cache_destroy(configfs_dir_cachep);
168166
configfs_dir_cachep = NULL;
169167
}

‎fs/debugfs/inode.c‎

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -716,20 +716,17 @@ bool debugfs_initialized(void)
716716
}
717717
EXPORT_SYMBOL_GPL(debugfs_initialized);
718718

719-
720-
static struct kobject *debug_kobj;
721-
722719
static int __init debugfs_init(void)
723720
{
724721
int retval;
725722

726-
debug_kobj = kobject_create_and_add("debug", kernel_kobj);
727-
if (!debug_kobj)
728-
return -EINVAL;
723+
retval = sysfs_create_mount_point(kernel_kobj, "debug");
724+
if (retval)
725+
return retval;
729726

730727
retval = register_filesystem(&debug_fs_type);
731728
if (retval)
732-
kobject_put(debug_kobj);
729+
sysfs_remove_mount_point(kernel_kobj, "debug");
733730
else
734731
debugfs_registered = true;
735732

‎fs/fuse/inode.c‎

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1238,7 +1238,6 @@ static void fuse_fs_cleanup(void)
12381238
}
12391239

12401240
static struct kobject *fuse_kobj;
1241-
static struct kobject *connections_kobj;
12421241

12431242
static int fuse_sysfs_init(void)
12441243
{
@@ -1250,11 +1249,9 @@ static int fuse_sysfs_init(void)
12501249
goto out_err;
12511250
}
12521251

1253-
connections_kobj = kobject_create_and_add("connections", fuse_kobj);
1254-
if (!connections_kobj) {
1255-
err = -ENOMEM;
1252+
err = sysfs_create_mount_point(fuse_kobj, "connections");
1253+
if (err)
12561254
goto out_fuse_unregister;
1257-
}
12581255

12591256
return 0;
12601257

@@ -1266,7 +1263,7 @@ static int fuse_sysfs_init(void)
12661263

12671264
static void fuse_sysfs_cleanup(void)
12681265
{
1269-
kobject_put(connections_kobj);
1266+
sysfs_remove_mount_point(fuse_kobj, "connections");
12701267
kobject_put(fuse_kobj);
12711268
}
12721269

‎fs/pstore/inode.c‎

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -461,22 +461,18 @@ static struct file_system_type pstore_fs_type = {
461461
.kill_sb = pstore_kill_sb,
462462
};
463463

464-
static struct kobject *pstore_kobj;
465-
466464
static int __init init_pstore_fs(void)
467465
{
468-
int err = 0;
466+
int err;
469467

470468
/* Create a convenient mount point for people to access pstore */
471-
pstore_kobj = kobject_create_and_add("pstore", fs_kobj);
472-
if (!pstore_kobj) {
473-
err = -ENOMEM;
469+
err = sysfs_create_mount_point(fs_kobj, "pstore");
470+
if (err)
474471
goto out;
475-
}
476472

477473
err = register_filesystem(&pstore_fs_type);
478474
if (err < 0)
479-
kobject_put(pstore_kobj);
475+
sysfs_remove_mount_point(fs_kobj, "pstore");
480476

481477
out:
482478
return err;

‎fs/tracefs/inode.c‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -631,14 +631,12 @@ bool tracefs_initialized(void)
631631
return tracefs_registered;
632632
}
633633

634-
static struct kobject *trace_kobj;
635-
636634
static int __init tracefs_init(void)
637635
{
638636
int retval;
639637

640-
trace_kobj = kobject_create_and_add("tracing", kernel_kobj);
641-
if (!trace_kobj)
638+
retval = sysfs_create_mount_point(kernel_kobj, "tracing");
639+
if (retval)
642640
return -EINVAL;
643641

644642
retval = register_filesystem(&trace_fs_type);

‎kernel/cgroup.c‎

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1924,8 +1924,6 @@ static struct file_system_type cgroup_fs_type = {
19241924
.kill_sb = cgroup_kill_sb,
19251925
};
19261926

1927-
static struct kobject *cgroup_kobj;
1928-
19291927
/**
19301928
* task_cgroup_path - cgroup path of a task in the first cgroup hierarchy
19311929
* @task: target task
@@ -5044,13 +5042,13 @@ int __init cgroup_init(void)
50445042
ss->bind(init_css_set.subsys[ssid]);
50455043
}
50465044

5047-
cgroup_kobj = kobject_create_and_add("cgroup", fs_kobj);
5048-
if (!cgroup_kobj)
5049-
return -ENOMEM;
5045+
err = sysfs_create_mount_point(fs_kobj, "cgroup");
5046+
if (err)
5047+
return err;
50505048

50515049
err = register_filesystem(&cgroup_fs_type);
50525050
if (err < 0) {
5053-
kobject_put(cgroup_kobj);
5051+
sysfs_remove_mount_point(fs_kobj, "cgroup");
50545052
return err;
50555053
}
50565054

‎security/inode.c‎

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -215,19 +215,17 @@ void securityfs_remove(struct dentry *dentry)
215215
}
216216
EXPORT_SYMBOL_GPL(securityfs_remove);
217217

218-
static struct kobject *security_kobj;
219-
220218
static int __init securityfs_init(void)
221219
{
222220
int retval;
223221

224-
security_kobj = kobject_create_and_add("security", kernel_kobj);
225-
if (!security_kobj)
226-
return -EINVAL;
222+
retval = sysfs_create_mount_point(kernel_kobj, "security");
223+
if (retval)
224+
return retval;
227225

228226
retval = register_filesystem(&fs_type);
229227
if (retval)
230-
kobject_put(security_kobj);
228+
sysfs_remove_mount_point(kernel_kobj, "security");
231229
return retval;
232230
}
233231

‎security/selinux/selinuxfs.c‎

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1853,7 +1853,6 @@ static struct file_system_type sel_fs_type = {
18531853
};
18541854

18551855
struct vfsmount *selinuxfs_mount;
1856-
static struct kobject *selinuxfs_kobj;
18571856

18581857
static int __init init_sel_fs(void)
18591858
{
@@ -1862,13 +1861,13 @@ static int __init init_sel_fs(void)
18621861
if (!selinux_enabled)
18631862
return 0;
18641863

1865-
selinuxfs_kobj = kobject_create_and_add("selinux", fs_kobj);
1866-
if (!selinuxfs_kobj)
1867-
return -ENOMEM;
1864+
err = sysfs_create_mount_point(fs_kobj, "selinux");
1865+
if (err)
1866+
return err;
18681867

18691868
err = register_filesystem(&sel_fs_type);
18701869
if (err) {
1871-
kobject_put(selinuxfs_kobj);
1870+
sysfs_remove_mount_point(fs_kobj, "selinux");
18721871
return err;
18731872
}
18741873

@@ -1887,7 +1886,7 @@ __initcall(init_sel_fs);
18871886
#ifdef CONFIG_SECURITY_SELINUX_DISABLE
18881887
void exit_sel_fs(void)
18891888
{
1890-
kobject_put(selinuxfs_kobj);
1889+
sysfs_remove_mount_point(fs_kobj, "selinux");
18911890
kern_unmount(selinuxfs_mount);
18921891
unregister_filesystem(&sel_fs_type);
18931892
}

0 commit comments

Comments
 (0)