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

Configure Feed

Select the types of activity you want to include in your feed.

kernel: refactor lookup_or_create_module_kobject()

In the unlikely event of the allocation failing, it is better to let
the machine boot with a not fully populated sysfs than to kill it with
this BUG_ON(). All callers are already prepared for
lookup_or_create_module_kobject() returning NULL.

This is also preparation for calling this function from non __init
code, where using BUG_ON for allocation failure handling is not
acceptable.

Since we are here, also start using IS_ENABLED instead of #ifdef
construct.

Suggested-by: Thomas Weißschuh <linux@weissschuh.net>
Suggested-by: Rasmus Villemoes <linux@rasmusvillemoes.dk>
Signed-off-by: Shyam Saini <shyamsaini@linux.microsoft.com>
Link: https://lore.kernel.org/r/20250227184930.34163-3-shyamsaini@linux.microsoft.com
Signed-off-by: Petr Pavlu <petr.pavlu@suse.com>

authored by

Shyam Saini and committed by
Petr Pavlu
1c7777fe bbc9462f

+18 -21
+18 -21
kernel/params.c
··· 767 767 int err; 768 768 769 769 kobj = kset_find_obj(module_kset, name); 770 - if (kobj) { 771 - mk = to_module_kobject(kobj); 772 - } else { 773 - mk = kzalloc(sizeof(struct module_kobject), GFP_KERNEL); 774 - BUG_ON(!mk); 770 + if (kobj) 771 + return to_module_kobject(kobj); 775 772 776 - mk->mod = THIS_MODULE; 777 - mk->kobj.kset = module_kset; 778 - err = kobject_init_and_add(&mk->kobj, &module_ktype, NULL, 779 - "%s", name); 780 - #ifdef CONFIG_MODULES 781 - if (!err) 782 - err = sysfs_create_file(&mk->kobj, &module_uevent.attr); 783 - #endif 784 - if (err) { 785 - kobject_put(&mk->kobj); 786 - pr_crit("Adding module '%s' to sysfs failed (%d), the system may be unstable.\n", 787 - name, err); 788 - return NULL; 789 - } 773 + mk = kzalloc(sizeof(struct module_kobject), GFP_KERNEL); 774 + if (!mk) 775 + return NULL; 790 776 791 - /* So that we hold reference in both cases. */ 792 - kobject_get(&mk->kobj); 777 + mk->mod = THIS_MODULE; 778 + mk->kobj.kset = module_kset; 779 + err = kobject_init_and_add(&mk->kobj, &module_ktype, NULL, "%s", name); 780 + if (IS_ENABLED(CONFIG_MODULES) && !err) 781 + err = sysfs_create_file(&mk->kobj, &module_uevent.attr); 782 + if (err) { 783 + kobject_put(&mk->kobj); 784 + pr_crit("Adding module '%s' to sysfs failed (%d), the system may be unstable.\n", 785 + name, err); 786 + return NULL; 793 787 } 788 + 789 + /* So that we hold reference in both cases. */ 790 + kobject_get(&mk->kobj); 794 791 795 792 return mk; 796 793 }