Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp1596729iob; Fri, 29 Apr 2022 08:37:48 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy/JO4Vkw6RHC8ENxaBDEqHNpX3HXtq7i1SRP3OEeB3/4Q1alTQy46O+mySgaCbzFOS19FU X-Received: by 2002:a17:90a:d083:b0:1c9:94bb:732d with SMTP id k3-20020a17090ad08300b001c994bb732dmr4636369pju.106.1651246668400; Fri, 29 Apr 2022 08:37:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651246668; cv=none; d=google.com; s=arc-20160816; b=rfzg9YoCzm3f6co5EC61a6v3X3B5EDAnlRQRw2UhjZIioo8J+h3WTeXyAfgjyvEpIx zyjh1ZjCwAzB9QSjr9KSR/Z41kBGytKBvOPDORpC+TzmX9GCXz+TXW8IuFihKViEsV6a Om7eK4bC619Gq5xIeKe6xLX7q7UqLm07DvAynV+CmZQpAA65twqRlWi1PykZOjurztGk ja5wgj3D+3fZ66uKYgbTkjLXFzvD6TUQGZ/AH+tTe/2bMkIO2Je31RUJONxfbO9nJ3U9 qkpN2Wtr1Dsa/T/NWfP+8uC7fRYcBy+lUQ2sBgR2zhflpw42A0F2Me5wSEovwIu0P5wt 90OQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=u2ZO+O4yh89EBk0VnHPZeE1qH9sPJ8qp2pUnx4bNufM=; b=ObFQ+t/iccBuzTGMUmN9QNxbER4cTIcyKRRe+KOkG7oo0M1ZmxElAS3KMZopIbbl8w VgnCSgUK+lRTg6PLt17MxPj2xPCgTVEGzRtK5q/xLg3bMQMzgZ3EvHuTcw7BDu/NBxjC cgGzhcz7raVrHlpgP0LnKAsESORCWrvM4uTCI5CQXcJ5p7ZvPoFN/Nee4ejwe0Z1k+jv gw78wnpLfHlCSJupy9om1BQKOQw/C4XiHGDOJaj999C1qL5TpFzcDJ1ZEHq7U61cDU+B 6JcC8cfdKIYmFMWZxWy6xkJIFH+LkcRKT5+rh/oo7cpmgYXsPTH7BCszs7wR2D/kKlwy hZNg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="nuo6dp/3"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id c136-20020a63358e000000b003ab938b9b53si7704286pga.242.2022.04.29.08.37.31; Fri, 29 Apr 2022 08:37:48 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="nuo6dp/3"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1354541AbiD2Gex (ORCPT + 99 others); Fri, 29 Apr 2022 02:34:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48938 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1352779AbiD2Geq (ORCPT ); Fri, 29 Apr 2022 02:34:46 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 40DCB75E40; Thu, 28 Apr 2022 23:31:28 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id C287261D96; Fri, 29 Apr 2022 06:31:27 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2295DC385B1; Fri, 29 Apr 2022 06:31:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1651213887; bh=YFyHuYmc6SIjS2dllZCzaenBMhy2srBsAIJHOm3si5w=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=nuo6dp/3tl0nnZlmgHLbOlaAkA6qZLDf134fErf3iGDVtEKapgM8jZtI0cm+ltfN+ ebBS9EauekpxEv43x7uBc6Q8jwVowJIiJ/iWsOL/p5PuF/pSYwD9Dt4NzWGsVVB5Ia RN2dxRJOTlMKlTAKNcZunqjyCWaw9795sKgR99/mEtJq2STM6W9RGv1pRIeBblld46 m517QlKAkoVmVASeN5/9RBWI8KYmEGf/p3tE9UVsJ8B/tKMG0izj75hU8nO1Tll6s/ NNPxP7ZceYNBsnZkYxkDle7ZVo6kPdUtTuIN9zAV4vlBlA5TVnF9p/xkdUBs9kD/a/ KKU4CtlUBH6KA== Received: from mchehab by mail.kernel.org with local (Exim 4.94.2) (envelope-from ) id 1nkK9z-001Qmi-Mh; Fri, 29 Apr 2022 07:31:23 +0100 From: Mauro Carvalho Chehab To: Luis Chamberlain Cc: mauro.chehab@intel.com, Mauro Carvalho Chehab , "Kai Vehmanen" , "Lucas De Marchi" , "Pierre-Louis Bossart" , dri-devel@lists.freedesktop.org, intel-gfx@lists.freedesktop.org, linux-kernel@vger.kernel.org, linux-modules@vger.kernel.org, Daniel Vetter , David Airlie , Dan Williams Subject: [PATCH 1/2] module: add a function to add module references Date: Fri, 29 Apr 2022 07:31:15 +0100 Message-Id: X-Mailer: git-send-email 2.35.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.7 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Sometimes, device drivers are bound using indirect references, which is not visible when looking at /proc/modules or lsmod. Add a function to allow setting up module references for such cases. Reviewed-by: Dan Williams Signed-off-by: Mauro Carvalho Chehab --- See [PATCH 0/2] at: https://lore.kernel.org/all/cover.1651212016.git.mchehab@kernel.org/ include/linux/module.h | 7 +++++++ kernel/module/main.c | 31 +++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/include/linux/module.h b/include/linux/module.h index 46d4d5f2516e..be74f807e41d 100644 --- a/include/linux/module.h +++ b/include/linux/module.h @@ -596,6 +596,8 @@ static inline bool within_module(unsigned long addr, const struct module *mod) /* Search for module by name: must be in a RCU-sched critical section. */ struct module *find_module(const char *name); +int module_add_named_dependency(const char *name, struct module *this); + /* Returns 0 and fills in value, defined and namebuf, or -ERANGE if symnum out of range. */ int module_get_kallsym(unsigned int symnum, unsigned long *value, char *type, @@ -772,6 +774,11 @@ static inline int lookup_module_symbol_attrs(unsigned long addr, unsigned long * return -ERANGE; } +static inline int module_add_named_dependency(const char *name, struct module *this) +{ + return 0; +} + static inline int module_get_kallsym(unsigned int symnum, unsigned long *value, char *type, char *name, char *module_name, int *exported) diff --git a/kernel/module/main.c b/kernel/module/main.c index 05a42d8fcd7a..dbd577ccc38c 100644 --- a/kernel/module/main.c +++ b/kernel/module/main.c @@ -631,6 +631,37 @@ static int ref_module(struct module *a, struct module *b) return 0; } +int module_add_named_dependency(const char *name, struct module *this) +{ + struct module *mod; + int ret; + + if (!name || !this || !this->name) { + return -EINVAL; + } + + mutex_lock(&module_mutex); + mod = find_module(name); + if (!mod) { + ret = -EINVAL; + goto ret; + } + + ret = ref_module(this, mod); + if (ret) + goto ret; + +#ifdef CONFIG_MODULE_UNLOAD + ret = sysfs_create_link(mod->holders_dir, + &this->mkobj.kobj, this->name); +#endif + +ret: + mutex_unlock(&module_mutex); + return ret; +} +EXPORT_SYMBOL_GPL(module_add_named_dependency); + /* Clear the unload stuff of the module. */ static void module_unload_free(struct module *mod) { -- 2.35.1