From patchwork Fri Feb 7 05:45:38 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shyam Saini X-Patchwork-Id: 13964361 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A4485175D5D; Fri, 7 Feb 2025 05:46:03 +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=1738907165; cv=none; b=ZlLdpRzESXSRxUj+q/6E6FssYvrkHTkGHXDjwIGHBypCsBK7GirSXinnaE+6+DyVsTJCS4Htket8XkFzE+XxnG+4nWZzrmWL+SdnBIB8BczvA9WQDeQKKVGu8t4ZGTg5cumzUlc5YwrWinAovX8DUFnICEZzMRCbl3LC6nn8lLw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738907165; c=relaxed/simple; bh=/Vw0uA/SfcM1Q5cZ2D0GVUFQ1fCC93v6eCJXbUyAOKk=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=o0XKt9KQricfcVR/Lt7EZjnvIt02tOOM30n3CPeJ9OrGngMUnVSOS5bdj40W3bSxbiJk2jU5vMaKr6MIBZqDYYG2OP7J2b5ehiI2DDcqaTHl66FOqVWs8eIEwSLS7U9125vhjpj1HQtPnYgYgUpZOwVGVZy0AuKluJ/L0RIlKLM= 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=M1qeq8CB; 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="M1qeq8CB" Received: from thinkpad-p16sg1.corp.microsoft.com (unknown [20.236.10.120]) by linux.microsoft.com (Postfix) with ESMTPSA id E658E206AB97; Thu, 6 Feb 2025 21:46:02 -0800 (PST) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com E658E206AB97 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1738907163; bh=spbTcWnNZV/JIcqv/y8cbywTNmS9a7lMbI4mTbTwEKg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=M1qeq8CBQKhbrQ4prdNzoPhJ6HlxfL8fQzEVERM1FsTH29pcSbuw/PMasPKH3Em+s tqaxQbmte8aQIIrtasKBaPhgl6AHMU/HejAN7jlBh4B+ePktzZPAXbIsUEMGWC2w0O 09Se4GD8s/NSliTvdE8+TcfAmxJ1BFh7nrLvY644= 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: [v2 3/3] drivers: base: handle module_kobject creation Date: Thu, 6 Feb 2025 21:45:38 -0800 Message-Id: <20250207054538.1110340-4-shyamsaini@linux.microsoft.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250207054538.1110340-1-shyamsaini@linux.microsoft.com> References: <20250207054538.1110340-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); } }