From patchwork Tue Feb 4 05:22:22 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shyam Saini X-Patchwork-Id: 13958607 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A182819B5A9; Tue, 4 Feb 2025 05:23:11 +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=1738646593; cv=none; b=XoL9zQR3YzQd+7XNs7NjtVb0KhGF8Z1AI9bGHfmK0/x/02+f8XZc5c+9dPUu9+egTvxy+jKPgA6uLG0IaICMCFgSBnCnOJtL+y+ZMXvFjcK9YXzAzU+e/QPkVqseB5NxjvacBp6dVYodisqtuW5ev4erS+8Dw012WOel7iDYTdQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738646593; c=relaxed/simple; bh=p6Kok+qq/l2B3e2e4G34QtRJ4FvWDnVU8naLbf3/tmc=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=AkbGhn7b3e4Rspj91yK/zTi6DAzC1rx7P7IyM3PvP4cffoySXzkfOVPsYjd7iTnivHcA8LV0StdP/TgbOMkbkiTg93rS+HdVeRS6wPdGAQFeqAs3YJWYg0br8eQHv1dggYTE9aJ9Z5G8h9kBf6Zip0Wz2BEUKtibyzKdFtllAfk= 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=fqcOuSdC; 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="fqcOuSdC" Received: from thinkpad-p16sg1.corp.microsoft.com (unknown [20.236.11.42]) by linux.microsoft.com (Postfix) with ESMTPSA id 14426206AB6B; Mon, 3 Feb 2025 21:23:11 -0800 (PST) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 14426206AB6B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1738646591; bh=f5DIEBK/28IXN8N2iEB0e9xXQ45c/QNvM+ed7OW3uQU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=fqcOuSdCj74sxw2TfcszdnZ1SWXhXpg6VxEcNLiRP3WFIeBMFxRaU8hRpmXxXdDaH acCKueQrVP55clhraQeaXMiTZQVk108A3QzuhwQEEioNrpUJKCSdCbMraaU4PB6KpD zt7F06zXXCaAoH0FLD4YYkz5E0+3QRn1lPcSyFqk= From: Shyam Saini To: linux-kernel@vger.kernel.org, linux-modules@vger.kernel.org Cc: code@tyhicks.com, linux@rasmusvillemoes.dk, 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: [v1 3/3] drivers: base: handle module_kboject creation Date: Mon, 3 Feb 2025 21:22:22 -0800 Message-Id: <20250204052222.1611510-4-shyamsaini@linux.microsoft.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250204052222.1611510-1-shyamsaini@linux.microsoft.com> References: <20250204052222.1611510-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 96a1a2412acb ("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); } }