From patchwork Tue Feb 11 21:48:39 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shyam Saini X-Patchwork-Id: 13970751 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C27C32676DC; Tue, 11 Feb 2025 21:49:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=13.77.154.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739310589; cv=none; b=JUwT3wfkwpnU8d8MGavQRlLHz16NxZbZYSl2MZ/ax77h8DgEsaXZBtf+Mgxzu+KUXviu/YkbNePJxzmlfTfwYKCdYXVDEjweedQHWBCDFMTJKAEDT0XlaerfnkRDfolf/zPeq79J35bM9nGYzTXtCfKWrn5+D8tkpOwdvRsTnj0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739310589; c=relaxed/simple; bh=i8qGikLjsH6XlE1U6wYSjOj/XPM/2vdBaBXdq55VsiY=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=m0w6o+9oDwAqj0zf1ZuYGiZsBSDBWoDloU/01AQnoNr7I/VcCzS8O1/pm5gJ5TtN+HPKn9+ZlWzxw6Py6HYoeKw1RLc2XJTL5XGrxWmwK1aJvwuaYJC+waWTGTqE+Uc1pchedmQsxvB/YFOL7YsJjWIM2PQvFVNzgQcAagF14IE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.microsoft.com; spf=pass smtp.mailfrom=linux.microsoft.com; dkim=pass (1024-bit key) header.d=linux.microsoft.com header.i=@linux.microsoft.com header.b=ELcehVbe; arc=none smtp.client-ip=13.77.154.182 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.microsoft.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.microsoft.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.microsoft.com header.i=@linux.microsoft.com header.b="ELcehVbe" Received: from thinkpad-p16sg1.. (d66-183-104-158.bchsia.telus.net [66.183.104.158]) by linux.microsoft.com (Postfix) with ESMTPSA id 0C45A2107AB2; Tue, 11 Feb 2025 13:49:47 -0800 (PST) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 0C45A2107AB2 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1739310587; bh=iaV/F7Xzowo/6Ktj0hPa5MUS5KH+gVRqXjzycDnnDws=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ELcehVbe2hh23WvfQVJjN+hRGt5fTWqdyzK87PcJsoi6jPUvIYbNvZ+ikiCbVsPqK eRKOWybeb0r0D4ihoTXXiwNf3xxP4cUiwSBaZj2kzcaA70B4rQVnT4VhKhBoPZ/qQa gK8Y0LN4MaUOXzi8X3+Lx0ig4UFhg5OhPMyDLnB0= From: Shyam Saini To: linux-kernel@vger.kernel.org, linux-modules@vger.kernel.org Cc: code@tyhicks.com, linux@rasmusvillemoes.dk, christophe.leroy@csgroup.eu, hch@infradead.org, mcgrof@kernel.org, frkaya@linux.microsoft.com, vijayb@linux.microsoft.com, petr.pavlu@suse.com, linux@weissschuh.net, samitolvanen@google.com, da.gomez@samsung.com, gregkh@linuxfoundation.org, rafael@kernel.org, dakr@kernel.org Subject: [PATCH v3 1/4] kernel: param: rename locate_module_kobject Date: Tue, 11 Feb 2025 13:48:39 -0800 Message-Id: <20250211214842.1806521-2-shyamsaini@linux.microsoft.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250211214842.1806521-1-shyamsaini@linux.microsoft.com> References: <20250211214842.1806521-1-shyamsaini@linux.microsoft.com> Precedence: bulk X-Mailing-List: linux-modules@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 The locate_module_kobject() function looks up an existing module_kobject for a given module name. If it cannot find the corresponding module_kobject, it creates one for the given name. This commit renames locate_module_kobject() to lookup_or_create_module_kobject() to better describe its operations. This doesn't change anything functionality wise. Suggested-by: Rasmus Villemoes Signed-off-by: Shyam Saini --- kernel/params.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/kernel/params.c b/kernel/params.c index 0074d29c9b80..4b43baaf7c83 100644 --- a/kernel/params.c +++ b/kernel/params.c @@ -763,7 +763,7 @@ void destroy_params(const struct kernel_param *params, unsigned num) params[i].ops->free(params[i].arg); } -static struct module_kobject * __init locate_module_kobject(const char *name) +static struct module_kobject * __init lookup_or_create_module_kobject(const char *name) { struct module_kobject *mk; struct kobject *kobj; @@ -805,10 +805,9 @@ static void __init kernel_add_sysfs_param(const char *name, struct module_kobject *mk; int err; - mk = locate_module_kobject(name); + mk = lookup_or_create_module_kobject(name); if (!mk) return; - /* We need to remove old parameters before adding more. */ if (mk->mp) sysfs_remove_group(&mk->kobj, &mk->mp->grp); @@ -876,7 +875,7 @@ static void __init version_sysfs_builtin(void) int err; for (vattr = __start___modver; vattr < __stop___modver; vattr++) { - mk = locate_module_kobject(vattr->module_name); + mk = lookup_or_create_module_kobject(vattr->module_name); if (mk) { err = sysfs_create_file(&mk->kobj, &vattr->mattr.attr); WARN_ON_ONCE(err); From patchwork Tue Feb 11 21:48:40 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Shyam Saini X-Patchwork-Id: 13970753 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 19B352676E7; Tue, 11 Feb 2025 21:49:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=13.77.154.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739310589; cv=none; b=Bwrep2kfwd0dURcBLFYyzpEdSxTu8aU3CQGDKPfuvVUns0pVlqdns/eqtypKpHeDvbupZVrMetYIHUNKGhEWcYhMoUf8iJFowkH3lKbOXhyYzObcs5RjxKpmY7JV869emDnP+qZzaR9/yBnDOcNEHCToT8unaY6skWrIs9tSNwo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739310589; c=relaxed/simple; bh=MooFLEl0bWPjHa3KlXQVOeMtCdlP7U0xpaaXz9mwZvg=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=UgE+qNf0ipgKdLBW2tClkJdVx/5JnNRhLmbJHR8v2D18fldcNUpczkgaLZFX06Ja4HA81qNrrZ5uROQ0OTS5J4zzl/5bN/MjtGvd575cmslDZaYvDE4GkVP/ZqXtAsdrkoYYv2tRLAIwMPQzgV0OxrIwalAtaTyqfij+YMQGAqE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.microsoft.com; spf=pass smtp.mailfrom=linux.microsoft.com; dkim=pass (1024-bit key) header.d=linux.microsoft.com header.i=@linux.microsoft.com header.b=e5LZ3OYk; arc=none smtp.client-ip=13.77.154.182 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.microsoft.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.microsoft.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.microsoft.com header.i=@linux.microsoft.com header.b="e5LZ3OYk" Received: from thinkpad-p16sg1.. (d66-183-104-158.bchsia.telus.net [66.183.104.158]) by linux.microsoft.com (Postfix) with ESMTPSA id 5F75E2107AB3; Tue, 11 Feb 2025 13:49:47 -0800 (PST) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 5F75E2107AB3 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1739310587; bh=Eg74aJvcfhvMWz2U+6WWbgLN/WbFA7n4ktssOz5i0E4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=e5LZ3OYkM4mBTKpKufldtlCuxffLm3HSXUe3HtS5JkcZGChmBWxPzVs8SK09pkWgu nQErit/CYCV1u53q6rLpeMGQBWrQHsiONzhMe9aWoxQ4RUCwcLRMy7+UR4lIn/h2na W8PBL2MG5rdUQbb7RYNE4GyOXh6N9Cu8AURyQyQ8= From: Shyam Saini To: linux-kernel@vger.kernel.org, linux-modules@vger.kernel.org Cc: code@tyhicks.com, linux@rasmusvillemoes.dk, christophe.leroy@csgroup.eu, hch@infradead.org, mcgrof@kernel.org, frkaya@linux.microsoft.com, vijayb@linux.microsoft.com, petr.pavlu@suse.com, linux@weissschuh.net, samitolvanen@google.com, da.gomez@samsung.com, gregkh@linuxfoundation.org, rafael@kernel.org, dakr@kernel.org Subject: [PATCH v3 2/4] kernel: refactor lookup_or_create_module_kobject() Date: Tue, 11 Feb 2025 13:48:40 -0800 Message-Id: <20250211214842.1806521-3-shyamsaini@linux.microsoft.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250211214842.1806521-1-shyamsaini@linux.microsoft.com> References: <20250211214842.1806521-1-shyamsaini@linux.microsoft.com> Precedence: bulk X-Mailing-List: linux-modules@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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 Suggested-by: Rasmus Villemoes Signed-off-by: Shyam Saini --- kernel/params.c | 41 +++++++++++++++++++---------------------- 1 file changed, 19 insertions(+), 22 deletions(-) diff --git a/kernel/params.c b/kernel/params.c index 4b43baaf7c83..6e87aef876b2 100644 --- a/kernel/params.c +++ b/kernel/params.c @@ -770,31 +770,28 @@ static struct module_kobject * __init lookup_or_create_module_kobject(const char int err; kobj = kset_find_obj(module_kset, name); - if (kobj) { - mk = to_module_kobject(kobj); - } else { - mk = kzalloc(sizeof(struct module_kobject), GFP_KERNEL); - BUG_ON(!mk); - - mk->mod = THIS_MODULE; - mk->kobj.kset = module_kset; - err = kobject_init_and_add(&mk->kobj, &module_ktype, NULL, - "%s", name); -#ifdef CONFIG_MODULES - if (!err) - err = sysfs_create_file(&mk->kobj, &module_uevent.attr); -#endif - if (err) { - kobject_put(&mk->kobj); - pr_crit("Adding module '%s' to sysfs failed (%d), the system may be unstable.\n", - name, err); - return NULL; - } + if (kobj) + return to_module_kobject(kobj); - /* So that we hold reference in both cases. */ - kobject_get(&mk->kobj); + mk = kzalloc(sizeof(struct module_kobject), GFP_KERNEL); + if (!mk) + return NULL; + + mk->mod = THIS_MODULE; + mk->kobj.kset = module_kset; + err = kobject_init_and_add(&mk->kobj, &module_ktype, NULL, "%s", name); + if (IS_ENABLED(CONFIG_MODULES) && !err) + err = sysfs_create_file(&mk->kobj, &module_uevent.attr); + if (err) { + kobject_put(&mk->kobj); + pr_crit("Adding module '%s' to sysfs failed (%d), the system may be unstable.\n", + name, err); + return NULL; } + /* So that we hold reference in both cases. */ + kobject_get(&mk->kobj); + return mk; } From patchwork Tue Feb 11 21:48:41 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shyam Saini X-Patchwork-Id: 13970752 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 5EA4F262D33; Tue, 11 Feb 2025 21:49:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=13.77.154.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739310589; cv=none; b=jSme1aJxiIoywYJRBC3QRgqVh0xftDv5oBcq5x2y/ng/Per+vRzbxiUZPCMb7vdCLSUp/XBO5A/nwfUbQwnI/uwPIPX+DXU/LOdlC7eg+zqMkNvsD+zbciBmZyyALiZT98VYZnM38Y2QzytbCghxg1QWzerWAFmOgiE9gk7E3u0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739310589; c=relaxed/simple; bh=/3sXTPmHd1UID6qSXjmOeYQOJBoH0cODtgaUKrHgM/E=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=ojugiMsyfMUYck3Zn0qztGXpDww+cC2o+HSjkj4uClOFv/nFLz4Ng13Sz8eL7MCUtM1t9vcqF+1k/y1vhV+sXfTwvcsqmKuWtksTQ8rbLrQt+hu21WoNaQmygyGUEw/6bHIdG1dB7fM92KATWWLiHcE4cAGoz1e/5kzb/IWgoQ4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.microsoft.com; spf=pass smtp.mailfrom=linux.microsoft.com; dkim=pass (1024-bit key) header.d=linux.microsoft.com header.i=@linux.microsoft.com header.b=rcjblPVg; arc=none smtp.client-ip=13.77.154.182 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.microsoft.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.microsoft.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.microsoft.com header.i=@linux.microsoft.com header.b="rcjblPVg" Received: from thinkpad-p16sg1.. (d66-183-104-158.bchsia.telus.net [66.183.104.158]) by linux.microsoft.com (Postfix) with ESMTPSA id B0C012107AB4; Tue, 11 Feb 2025 13:49:47 -0800 (PST) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com B0C012107AB4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1739310587; bh=ldM/qO0KdxfBenOA6k2tUfy02w6fasJ0fnnvLXlT6Wk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=rcjblPVgHxW9xILSvZr2YdhA30d3OxwbXIEJrvjHt+HRxg5ygyb3A3NyQJBcn2u2D 1tgt5IgpKsKTJy8Tehu3LKeHctWErSgyx3cQ9g60odfWJXmRW32A4o9Dk1/OLcKuqD /zM1LlPugQCi2yF5Rpg0B1H0+o7lJk8iHZWgh/xQ= From: Shyam Saini To: linux-kernel@vger.kernel.org, linux-modules@vger.kernel.org Cc: code@tyhicks.com, linux@rasmusvillemoes.dk, christophe.leroy@csgroup.eu, hch@infradead.org, mcgrof@kernel.org, frkaya@linux.microsoft.com, vijayb@linux.microsoft.com, petr.pavlu@suse.com, linux@weissschuh.net, samitolvanen@google.com, da.gomez@samsung.com, gregkh@linuxfoundation.org, rafael@kernel.org, dakr@kernel.org Subject: [PATCH v3 3/4] kernel: globalize lookup_or_create_module_kobject() Date: Tue, 11 Feb 2025 13:48:41 -0800 Message-Id: <20250211214842.1806521-4-shyamsaini@linux.microsoft.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250211214842.1806521-1-shyamsaini@linux.microsoft.com> References: <20250211214842.1806521-1-shyamsaini@linux.microsoft.com> Precedence: bulk X-Mailing-List: linux-modules@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 lookup_or_create_module_kobject() is marked as static and __init, to make it global drop static keyword. Since this function can be called from non-init code, use __modinit instead of __init, __modinit marker will make it __init if CONFIG_MODULES is not defined. Suggested-by: Rasmus Villemoes Signed-off-by: Shyam Saini --- include/linux/module.h | 2 ++ kernel/params.c | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/include/linux/module.h b/include/linux/module.h index 12f8a7d4fc1c..aeaaf9e068eb 100644 --- a/include/linux/module.h +++ b/include/linux/module.h @@ -162,6 +162,8 @@ extern void cleanup_module(void); #define __INITRODATA_OR_MODULE __INITRODATA #endif /*CONFIG_MODULES*/ +struct module_kobject *lookup_or_create_module_kobject(const char *name); + /* Generic info of form tag = "info" */ #define MODULE_INFO(tag, info) __MODULE_INFO(tag, tag, info) diff --git a/kernel/params.c b/kernel/params.c index 6e87aef876b2..1073f8ebd5a6 100644 --- a/kernel/params.c +++ b/kernel/params.c @@ -763,7 +763,7 @@ void destroy_params(const struct kernel_param *params, unsigned num) params[i].ops->free(params[i].arg); } -static struct module_kobject * __init lookup_or_create_module_kobject(const char *name) +struct module_kobject __modinit * lookup_or_create_module_kobject(const char *name) { struct module_kobject *mk; struct kobject *kobj; From patchwork Tue Feb 11 21:48:42 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shyam Saini X-Patchwork-Id: 13970754 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A46042676F9; Tue, 11 Feb 2025 21:49:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=13.77.154.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739310590; cv=none; b=n8hzZN/RPxJd8Y5WSKT91g0RcveT6NfUto7R7iTzKpXaC+UMNTUVwli590+Xuqof8wNLbLm0iTprol0OZgqYYEfeVPHN5Fx9yqiEhFkZnCHYNiF+nYWJn8aPvXckj9/BrI74rqeu66X7hWxq7c4N2YtwudEjPBYqUgQveL/oP2Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739310590; c=relaxed/simple; bh=/Vw0uA/SfcM1Q5cZ2D0GVUFQ1fCC93v6eCJXbUyAOKk=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=T+ssMxAJbDYFg6ojaONyrmHlY0CY4nRTCCYBihD2nwYN5BbPt7lzjYxMpK5Nr5Wd3ELZGhqLfMkJTWl5H7SJ8Fzr2xbrI1V+V/B/EP60Xq+gnBdiI3vLI+yXGvxQkdkXVHzELIPw8nHMItO4HcGJBO2I2WiJpUyheLbEfnIZViM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.microsoft.com; spf=pass smtp.mailfrom=linux.microsoft.com; dkim=pass (1024-bit key) header.d=linux.microsoft.com header.i=@linux.microsoft.com header.b=WThL7b9M; arc=none smtp.client-ip=13.77.154.182 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.microsoft.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.microsoft.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.microsoft.com header.i=@linux.microsoft.com header.b="WThL7b9M" Received: from thinkpad-p16sg1.. (d66-183-104-158.bchsia.telus.net [66.183.104.158]) by linux.microsoft.com (Postfix) with ESMTPSA id 0EE412107AB5; Tue, 11 Feb 2025 13:49:48 -0800 (PST) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 0EE412107AB5 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1739310588; bh=spbTcWnNZV/JIcqv/y8cbywTNmS9a7lMbI4mTbTwEKg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=WThL7b9MXhjdL/yP/jL5UsSyOyc2zgHo6MzmEkqDsZ6neDOVPGvFa1LYW+xLVH41O VWFzfJ2H0uN4LI5OJCsPO6p4W8YD6wTOZPoyy2M4PiNdULLT11AjKKoHn8bBlDp46m dYkcsZRYutoT93eCiBNzMunbzm/Ttv1L8H+DDej4= From: Shyam Saini To: linux-kernel@vger.kernel.org, linux-modules@vger.kernel.org Cc: code@tyhicks.com, linux@rasmusvillemoes.dk, christophe.leroy@csgroup.eu, hch@infradead.org, mcgrof@kernel.org, frkaya@linux.microsoft.com, vijayb@linux.microsoft.com, petr.pavlu@suse.com, linux@weissschuh.net, samitolvanen@google.com, da.gomez@samsung.com, gregkh@linuxfoundation.org, rafael@kernel.org, dakr@kernel.org Subject: [PATCH v3 4/4] drivers: base: handle module_kobject creation Date: Tue, 11 Feb 2025 13:48:42 -0800 Message-Id: <20250211214842.1806521-5-shyamsaini@linux.microsoft.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250211214842.1806521-1-shyamsaini@linux.microsoft.com> References: <20250211214842.1806521-1-shyamsaini@linux.microsoft.com> Precedence: bulk X-Mailing-List: linux-modules@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 module_add_driver() relies on module_kset list for /sys/module//drivers directory creation. Since, commit 96a1a2412acba ("kernel/params.c: defer most of param_sysfs_init() to late_initcall time") drivers which are initialized from subsys_initcall() or any other higher precedence initcall couldn't find the related kobject entry in the module_kset list because module_kset is not fully populated by the time module_add_driver() refers it. As a consequence, module_add_driver() returns early without calling make_driver_name(). Therefore, /sys/module//drivers is never created. Fix this issue by letting module_add_driver() handle module_kobject creation itself. Fixes: 96a1a2412acb ("kernel/params.c: defer most of param_sysfs_init() to late_initcall time") Suggested-by: Rasmus Villemoes Signed-off-by: Shyam Saini --- drivers/base/module.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/drivers/base/module.c b/drivers/base/module.c index 5bc71bea883a..218aaa096455 100644 --- a/drivers/base/module.c +++ b/drivers/base/module.c @@ -42,16 +42,13 @@ int module_add_driver(struct module *mod, const struct device_driver *drv) if (mod) mk = &mod->mkobj; else if (drv->mod_name) { - struct kobject *mkobj; - - /* Lookup built-in module entry in /sys/modules */ - mkobj = kset_find_obj(module_kset, drv->mod_name); - if (mkobj) { - mk = container_of(mkobj, struct module_kobject, kobj); + /* Lookup or create built-in module entry in /sys/modules */ + mk = lookup_or_create_module_kobject(drv->mod_name); + if (mk) { /* remember our module structure */ drv->p->mkobj = mk; - /* kset_find_obj took a reference */ - kobject_put(mkobj); + /* lookup_or_create_module_kobject took a reference */ + kobject_put(&mk->kobj); } }