mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Rusty Russell <rusty@rustcorp.com.au>
To: torvalds@transmeta.com
Cc: linux-kernel@vger.kernel.org
Subject: [PATCH] Minor module cleanup 1/3
Date: Thu, 27 Mar 2003 15:10:48 +1100	[thread overview]
Message-ID: <20030327041148.032A62C050@lists.samba.org> (raw)

Linus, please apply.  Nobody uses symbol_put_addr yet, but it's
significantly neater to use module_text_addr which does the same "is
this in a module" search.

Rusty.
--
  Anyone who quotes me in their sig is an idiot. -- Rusty Russell.

Name: module_text_address returns the module
Author: Rusty Russell
Status: Trivial

D: By making module_text_address return the module it found, we
D: simplify symbol_put_addr significantly.

diff -urpN --exclude TAGS -X /home/rusty/devel/kernel/kernel-patches/current-dontdiff --minimal .19470-linux-2.5.66-bk2/include/linux/module.h .19470-linux-2.5.66-bk2.updated/include/linux/module.h
--- .19470-linux-2.5.66-bk2/include/linux/module.h	2003-03-25 12:17:31.000000000 +1100
+++ .19470-linux-2.5.66-bk2.updated/include/linux/module.h	2003-03-27 15:08:54.000000000 +1100
@@ -268,7 +268,7 @@ static inline int module_is_live(struct 
 }
 
 /* Is this address in a module? */
-int module_text_address(unsigned long addr);
+struct module *module_text_address(unsigned long addr);
 
 #ifdef CONFIG_MODULE_UNLOAD
 
@@ -361,9 +361,9 @@ search_module_extables(unsigned long add
 }
 
 /* Is this address in a module? */
-static inline int module_text_address(unsigned long addr)
+static inline struct module *module_text_address(unsigned long addr)
 {
-	return 0;
+	return NULL;
 }
 
 /* Get/put a kernel symbol (calls should be symmetric) */
diff -urpN --exclude TAGS -X /home/rusty/devel/kernel/kernel-patches/current-dontdiff --minimal .19470-linux-2.5.66-bk2/kernel/extable.c .19470-linux-2.5.66-bk2.updated/kernel/extable.c
--- .19470-linux-2.5.66-bk2/kernel/extable.c	2003-02-07 19:20:44.000000000 +1100
+++ .19470-linux-2.5.66-bk2.updated/kernel/extable.c	2003-03-27 15:08:54.000000000 +1100
@@ -38,5 +38,5 @@ int kernel_text_address(unsigned long ad
 	    addr <= (unsigned long)_etext)
 		return 1;
 
-	return module_text_address(addr);
+	return module_text_address(addr) != NULL;
 }
diff -urpN --exclude TAGS -X /home/rusty/devel/kernel/kernel-patches/current-dontdiff --minimal .19470-linux-2.5.66-bk2/kernel/module.c .19470-linux-2.5.66-bk2.updated/kernel/module.c
--- .19470-linux-2.5.66-bk2/kernel/module.c	2003-03-18 05:01:52.000000000 +1100
+++ .19470-linux-2.5.66-bk2.updated/kernel/module.c	2003-03-27 15:09:34.000000000 +1100
@@ -552,23 +552,14 @@ EXPORT_SYMBOL(__symbol_put);
 
 void symbol_put_addr(void *addr)
 {
-	struct kernel_symbol_group *ks;
 	unsigned long flags;
 
 	spin_lock_irqsave(&modlist_lock, flags);
-	list_for_each_entry(ks, &symbols, list) {
- 		unsigned int i;
+	if (!kernel_text_address((unsigned long)addr))
+		BUG();
 
-		for (i = 0; i < ks->num_syms; i++) {
-			if (ks->syms[i].value == (unsigned long)addr) {
-				module_put(ks->owner);
-				spin_unlock_irqrestore(&modlist_lock, flags);
-				return;
-			}
-		}
-	}
+	module_put(module_text_address((unsigned long)addr));
 	spin_unlock_irqrestore(&modlist_lock, flags);
-	BUG();
 }
 EXPORT_SYMBOL_GPL(symbol_put_addr);
 
@@ -1545,15 +1536,15 @@ const struct exception_table_entry *sear
 }
 
 /* Is this a valid kernel address?  We don't grab the lock: we are oopsing. */
-int module_text_address(unsigned long addr)
+struct module *module_text_address(unsigned long addr)
 {
 	struct module *mod;
 
 	list_for_each_entry(mod, &modules, list)
 		if (within(addr, mod->module_init, mod->init_size)
 		    || within(addr, mod->module_core, mod->core_size))
-			return 1;
-	return 0;
+			return mod;
+	return NULL;
 }
 
 /* Provided by the linker */

                 reply	other threads:[~2003-03-27  4:00 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20030327041148.032A62C050@lists.samba.org \
    --to=rusty@rustcorp.com.au \
    --cc=linux-kernel@vger.kernel.org \
    --cc=torvalds@transmeta.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®