Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

sysfs, kobject: add sysfs wrapper for kernfs_enable_ns()

Currently, kobject is invoking kernfs_enable_ns() directly. This is
fine now as sysfs and kernfs are enabled and disabled together. If
sysfs is disabled, kernfs_enable_ns() is switched to dummy
implementation too and everything is fine; however, kernfs will soon
have its own config option CONFIG_KERNFS and !SYSFS && KERNFS will be
possible, which can make kobject call into non-dummy
kernfs_enable_ns() with NULL kernfs_node pointers leading to an oops.

Introduce sysfs_enable_ns() which is a wrapper around
kernfs_enable_ns() so that it can be made a noop depending only on
CONFIG_SYSFS regardless of the planned CONFIG_KERNFS.

Signed-off-by: Tejun Heo <tj@kernel.org>
Reported-by: Fengguang Wu <fengguang.wu@intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Tejun Heo and committed by
Greg Kroah-Hartman
fa4cd451 3eef34ad

+10 -1
+9
include/linux/sysfs.h
··· 244 244 245 245 int __must_check sysfs_init(void); 246 246 247 + static inline void sysfs_enable_ns(struct kernfs_node *kn) 248 + { 249 + return kernfs_enable_ns(kn); 250 + } 251 + 247 252 #else /* CONFIG_SYSFS */ 248 253 249 254 static inline int sysfs_create_dir_ns(struct kobject *kobj, const void *ns) ··· 419 414 static inline int __must_check sysfs_init(void) 420 415 { 421 416 return 0; 417 + } 418 + 419 + static inline void sysfs_enable_ns(struct kernfs_node *kn) 420 + { 422 421 } 423 422 424 423 #endif /* CONFIG_SYSFS */
+1 -1
lib/kobject.c
··· 94 94 BUG_ON(ops->type >= KOBJ_NS_TYPES); 95 95 BUG_ON(!kobj_ns_type_registered(ops->type)); 96 96 97 - kernfs_enable_ns(kobj->sd); 97 + sysfs_enable_ns(kobj->sd); 98 98 } 99 99 100 100 return 0;