linux-modules.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/3] module: trivial cleanups for symbol search
@ 2022-05-04 19:42 Masahiro Yamada
  2022-05-04 19:42 ` [PATCH 1/3] module: do not pass opaque pointer " Masahiro Yamada
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Masahiro Yamada @ 2022-05-04 19:42 UTC (permalink / raw)
  To: Luis Chamberlain, linux-modules, linux-kernel; +Cc: Masahiro Yamada


Masahiro Yamada (3):
  module: do not pass opaque pointer for symbol search
  module: do not binary-search in __ksymtab_gpl if fsa->gplok is false
  module: merge check_exported_symbol() into
    find_exported_symbol_in_section()

 kernel/module.c | 32 +++++++++++---------------------
 1 file changed, 11 insertions(+), 21 deletions(-)

-- 
2.32.0


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 1/3] module: do not pass opaque pointer for symbol search
  2022-05-04 19:42 [PATCH 0/3] module: trivial cleanups for symbol search Masahiro Yamada
@ 2022-05-04 19:42 ` Masahiro Yamada
  2022-05-04 19:42 ` [PATCH 2/3] module: do not binary-search in __ksymtab_gpl if fsa->gplok is false Masahiro Yamada
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Masahiro Yamada @ 2022-05-04 19:42 UTC (permalink / raw)
  To: Luis Chamberlain, linux-modules, linux-kernel; +Cc: Masahiro Yamada

There is no need to use an opaque pointer for check_exported_symbol()
or find_exported_symbol_in_section.

Pass (struct find_symbol_arg *) explicitly.

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
---

 kernel/module.c | 11 ++++-------
 1 file changed, 4 insertions(+), 7 deletions(-)

diff --git a/kernel/module.c b/kernel/module.c
index c9e2342da28e..d57beb6b4eee 100644
--- a/kernel/module.c
+++ b/kernel/module.c
@@ -445,11 +445,9 @@ struct find_symbol_arg {
 };
 
 static bool check_exported_symbol(const struct symsearch *syms,
-				  struct module *owner,
-				  unsigned int symnum, void *data)
+				  struct module *owner, unsigned int symnum,
+				  struct find_symbol_arg *fsa)
 {
-	struct find_symbol_arg *fsa = data;
-
 	if (!fsa->gplok && syms->license == GPL_ONLY)
 		return false;
 	fsa->owner = owner;
@@ -495,16 +493,15 @@ static int cmp_name(const void *name, const void *sym)
 
 static bool find_exported_symbol_in_section(const struct symsearch *syms,
 					    struct module *owner,
-					    void *data)
+					    struct find_symbol_arg *fsa)
 {
-	struct find_symbol_arg *fsa = data;
 	struct kernel_symbol *sym;
 
 	sym = bsearch(fsa->name, syms->start, syms->stop - syms->start,
 			sizeof(struct kernel_symbol), cmp_name);
 
 	if (sym != NULL && check_exported_symbol(syms, owner,
-						 sym - syms->start, data))
+						 sym - syms->start, fsa))
 		return true;
 
 	return false;
-- 
2.32.0


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 2/3] module: do not binary-search in __ksymtab_gpl if fsa->gplok is false
  2022-05-04 19:42 [PATCH 0/3] module: trivial cleanups for symbol search Masahiro Yamada
  2022-05-04 19:42 ` [PATCH 1/3] module: do not pass opaque pointer " Masahiro Yamada
@ 2022-05-04 19:42 ` Masahiro Yamada
  2022-05-04 19:42 ` [PATCH 3/3] module: merge check_exported_symbol() into find_exported_symbol_in_section() Masahiro Yamada
  2022-05-04 20:22 ` [PATCH 0/3] module: trivial cleanups for symbol search Luis Chamberlain
  3 siblings, 0 replies; 5+ messages in thread
From: Masahiro Yamada @ 2022-05-04 19:42 UTC (permalink / raw)
  To: Luis Chamberlain, linux-modules, linux-kernel; +Cc: Masahiro Yamada

Currently, !fsa->gplok && syms->license == GPL_ONLY) is checked after
bsearch() succeeds.

It is meaningless to do the binary search in the GPL symbol table when
fsa->gplok is false because we know find_exported_symbol_in_section()
will fail anyway.

This check should be done before bsearch().

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
---

 kernel/module.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/kernel/module.c b/kernel/module.c
index d57beb6b4eee..4380ceb825b9 100644
--- a/kernel/module.c
+++ b/kernel/module.c
@@ -448,8 +448,6 @@ static bool check_exported_symbol(const struct symsearch *syms,
 				  struct module *owner, unsigned int symnum,
 				  struct find_symbol_arg *fsa)
 {
-	if (!fsa->gplok && syms->license == GPL_ONLY)
-		return false;
 	fsa->owner = owner;
 	fsa->crc = symversion(syms->crcs, symnum);
 	fsa->sym = &syms->start[symnum];
@@ -497,6 +495,9 @@ static bool find_exported_symbol_in_section(const struct symsearch *syms,
 {
 	struct kernel_symbol *sym;
 
+	if (!fsa->gplok && syms->license == GPL_ONLY)
+		return false;
+
 	sym = bsearch(fsa->name, syms->start, syms->stop - syms->start,
 			sizeof(struct kernel_symbol), cmp_name);
 
-- 
2.32.0


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 3/3] module: merge check_exported_symbol() into find_exported_symbol_in_section()
  2022-05-04 19:42 [PATCH 0/3] module: trivial cleanups for symbol search Masahiro Yamada
  2022-05-04 19:42 ` [PATCH 1/3] module: do not pass opaque pointer " Masahiro Yamada
  2022-05-04 19:42 ` [PATCH 2/3] module: do not binary-search in __ksymtab_gpl if fsa->gplok is false Masahiro Yamada
@ 2022-05-04 19:42 ` Masahiro Yamada
  2022-05-04 20:22 ` [PATCH 0/3] module: trivial cleanups for symbol search Luis Chamberlain
  3 siblings, 0 replies; 5+ messages in thread
From: Masahiro Yamada @ 2022-05-04 19:42 UTC (permalink / raw)
  To: Luis Chamberlain, linux-modules, linux-kernel; +Cc: Masahiro Yamada

Now check_exported_symbol() always succeeds.

Merge it into find_exported_symbol_in_search() to make the code concise.

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
---

 kernel/module.c | 22 +++++++---------------
 1 file changed, 7 insertions(+), 15 deletions(-)

diff --git a/kernel/module.c b/kernel/module.c
index 4380ceb825b9..6b2afce80c32 100644
--- a/kernel/module.c
+++ b/kernel/module.c
@@ -444,17 +444,6 @@ struct find_symbol_arg {
 	enum mod_license license;
 };
 
-static bool check_exported_symbol(const struct symsearch *syms,
-				  struct module *owner, unsigned int symnum,
-				  struct find_symbol_arg *fsa)
-{
-	fsa->owner = owner;
-	fsa->crc = symversion(syms->crcs, symnum);
-	fsa->sym = &syms->start[symnum];
-	fsa->license = syms->license;
-	return true;
-}
-
 static unsigned long kernel_symbol_value(const struct kernel_symbol *sym)
 {
 #ifdef CONFIG_HAVE_ARCH_PREL32_RELOCATIONS
@@ -500,12 +489,15 @@ static bool find_exported_symbol_in_section(const struct symsearch *syms,
 
 	sym = bsearch(fsa->name, syms->start, syms->stop - syms->start,
 			sizeof(struct kernel_symbol), cmp_name);
+	if (!sym)
+		return false;
 
-	if (sym != NULL && check_exported_symbol(syms, owner,
-						 sym - syms->start, fsa))
-		return true;
+	fsa->owner = owner;
+	fsa->crc = symversion(syms->crcs, sym - syms->start);
+	fsa->sym = sym;
+	fsa->license = syms->license;
 
-	return false;
+	return true;
 }
 
 /*
-- 
2.32.0


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH 0/3] module: trivial cleanups for symbol search
  2022-05-04 19:42 [PATCH 0/3] module: trivial cleanups for symbol search Masahiro Yamada
                   ` (2 preceding siblings ...)
  2022-05-04 19:42 ` [PATCH 3/3] module: merge check_exported_symbol() into find_exported_symbol_in_section() Masahiro Yamada
@ 2022-05-04 20:22 ` Luis Chamberlain
  3 siblings, 0 replies; 5+ messages in thread
From: Luis Chamberlain @ 2022-05-04 20:22 UTC (permalink / raw)
  To: Masahiro Yamada; +Cc: linux-modules, linux-kernel

On Thu, May 05, 2022 at 04:42:42AM +0900, Masahiro Yamada wrote:
> 
> Masahiro Yamada (3):
>   module: do not pass opaque pointer for symbol search
>   module: do not binary-search in __ksymtab_gpl if fsa->gplok is false
>   module: merge check_exported_symbol() into
>     find_exported_symbol_in_section()
> 
>  kernel/module.c | 32 +++++++++++---------------------
>  1 file changed, 11 insertions(+), 21 deletions(-)

Thanks! The droid you are looking for however has morphed quite a bit,
any chance you can rebase onto modules-next [0] and resend a v2?

[0] https://git.kernel.org/pub/scm/linux/kernel/git/mcgrof/linux.git/log/?h=modules-next

  Luis

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2022-05-04 20:22 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-05-04 19:42 [PATCH 0/3] module: trivial cleanups for symbol search Masahiro Yamada
2022-05-04 19:42 ` [PATCH 1/3] module: do not pass opaque pointer " Masahiro Yamada
2022-05-04 19:42 ` [PATCH 2/3] module: do not binary-search in __ksymtab_gpl if fsa->gplok is false Masahiro Yamada
2022-05-04 19:42 ` [PATCH 3/3] module: merge check_exported_symbol() into find_exported_symbol_in_section() Masahiro Yamada
2022-05-04 20:22 ` [PATCH 0/3] module: trivial cleanups for symbol search Luis Chamberlain

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).