Skip to contentSkip to conversation

Don't initialize module before grub_dl_add() succeeds

PATCH In review Pavel Roskin 2 participants 5 messages Jul 22, 2009 – Jul 23, 2009

lore
Share & tools
lore
#0 lore raw

PATCH 1/3 Don't initialize module before grub_dl_add() succeeds

ChangeLog:

* kern/dl.c (grub_dl_load_core): Call grub_dl_call_init() only after grub_dl_add() succeeds. Set mod->ref_count to 1 later to allow grub_dl_unload() to work.
Original patch by Joe Auricchio <[email protected]>

---
 kern/dl.c |   14 +++++---------
 1 files changed, 5 insertions(+), 9 deletions(-)
kern/dl.c +5 -9
index 78ebc1e..ebde547 100644
@@ -539,14 +539,13 @@ grub_dl_load_core (void *addr, grub_size_t size)
   if (! mod)
     return 0;
 
-  mod->ref_count = 1;
-
   grub_dprintf ("modules", "relocating to %p\n", mod);
   if (grub_dl_resolve_name (mod, e)
       || grub_dl_resolve_dependencies (mod, e)
       || grub_dl_load_segments (mod, e)
       || grub_dl_resolve_symbols (mod, e)
-      || grub_arch_dl_relocate_symbols (mod, e))
+      || grub_arch_dl_relocate_symbols (mod, e)
+      || grub_dl_add (mod))
     {
       mod->fini = 0;
       grub_dl_unload (mod);
@@ -557,13 +556,10 @@ grub_dl_load_core (void *addr, grub_size_t size)
 
   grub_dprintf ("modules", "module name: %s\n", mod->name);
   grub_dprintf ("modules", "init function: %p\n", mod->init);
-  grub_dl_call_init (mod);
 
-  if (grub_dl_add (mod))
-    {
-      grub_dl_unload (mod);
-      return 0;
-    }
+  mod->ref_count = 1;
+
+  grub_dl_call_init (mod);
 
   return mod;
 }
#1 lore raw

PATCH 2/3 Eliminate grub_dl_call_init()

It's just two lines long and there is only one caller. Besides, there is no equivalent for mod->fini.

ChangeLog:

	* kern/dl.c (grub_dl_call_init): Remove.
	(grub_dl_load_core): Call mod->init directly.
---
 kern/dl.c |   10 ++--------
 1 files changed, 2 insertions(+), 8 deletions(-)
kern/dl.c +2 -8
index ebde547..e2382d6 100644
@@ -393,13 +393,6 @@ grub_dl_resolve_symbols (grub_dl_t mod, Elf_Ehdr *e)
   return GRUB_ERR_NONE;
 }
 
-static void
-grub_dl_call_init (grub_dl_t mod)
-{
-  if (mod->init)
-    (mod->init) (mod);
-}
-
 static grub_err_t
 grub_dl_resolve_name (grub_dl_t mod, Elf_Ehdr *e)
 {
@@ -559,7 +552,8 @@ grub_dl_load_core (void *addr, grub_size_t size)
 
   mod->ref_count = 1;
 
-  grub_dl_call_init (mod);
+  if (mod->init)
+    (mod->init) (mod);
 
   return mod;
 }
#2 lore raw

Re: [PATCH 2/3] Eliminate grub_dl_call_init()

Quoted 2 lines · Pavel Roskin

It's just two lines long and there is only one caller.  Besides, there is no equivalent for mod->fini.

This patch is fine for me

Quoted 44 lines

ChangeLog:

       * kern/dl.c (grub_dl_call_init): Remove. (grub_dl_load_core): Call mod->init directly.
---
 kern/dl.c |   10 ++--------

 1 files changed, 2 insertions(+), 8 deletions(-)
kern/dl.c +0 -7
index ebde547..e2382d6 100644
@@ -393,13 +393,6 @@ grub_dl_resolve_symbols (grub_dl_t mod, Elf_Ehdr *e)
   return GRUB_ERR_NONE;
  }
 
-static void
-grub_dl_call_init (grub_dl_t mod)
-{
-  if (mod->init)
-    (mod->init) (mod);
-}
-

 static grub_err_t
 grub_dl_resolve_name (grub_dl_t mod, Elf_Ehdr *e) {

kern/dl.c +2 -1
@@ -559,7 +552,8 @@ grub_dl_load_core (void *addr, grub_size_t size)
 
   mod->ref_count = 1;
 
-  grub_dl_call_init (mod);
+  if (mod->init)
+    (mod->init) (mod);
 
   return mod;
  }

_______________________________________________
Grub-devel mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/grub-devel

Signature · 4 lines
Regards
Vladimir 'phcoder' Serbinenko

Personal git repository: http://repo.or.cz/w/grub2/phcoder.git
#3 lore raw

PATCH 3/3 Merge struct grub_dl_list into struct grub_dl

In reply to Pavel Roskin

There is no need to keep a separate list of the modules. It requires additional memory allocation and additional error handling. Now grub_dl_add() can only fail if the module is already loaded.

ChangeLog:

* include/grub/dl.h (struct grub_dl): Add next field.
* kern/dl.c: Remove struct grub_dl_list. Use mod->next to iterate over modules.

---
 include/grub/dl.h |    1 +
 kern/dl.c         |   55 +++++++++++++++++++----------------------------------
 2 files changed, 21 insertions(+), 35 deletions(-)
include/grub/dl.h +1 -0
index 3f8b328..55cc6cc 100644
@@ -82,6 +82,7 @@ struct grub_dl
   Elf_Sym *symtab;
   void (*init) (struct grub_dl *mod);
   void (*fini) (void);
+  struct grub_dl *next;
 };
 typedef struct grub_dl *grub_dl_t;
 
kern/dl.c +20 -35

115 lines not on this page · raw message

#4 lore raw
In reply to Pavel Roskin
Quoted 6 lines · Pavel Roskin

ChangeLog:

       * kern/dl.c (grub_dl_load_core): Call grub_dl_call_init() only after grub_dl_add() succeeds.  Set mod->ref_count to 1 later to allow grub_dl_unload() to work.
       Original patch by Joe Auricchio <[email protected]>

Ok with me

Quoted 49 lines

---
 kern/dl.c |   14 +++++---------

 1 files changed, 5 insertions(+), 9 deletions(-)
kern/dl.c +5 -9
index 78ebc1e..ebde547 100644
@@ -539,14 +539,13 @@ grub_dl_load_core (void *addr, grub_size_t size)
   if (! mod)
     return 0;
 
-  mod->ref_count = 1;
-
   grub_dprintf ("modules", "relocating to %p\n", mod);
   if (grub_dl_resolve_name (mod, e)
       || grub_dl_resolve_dependencies (mod, e)
       || grub_dl_load_segments (mod, e)
       || grub_dl_resolve_symbols (mod, e)
-      || grub_arch_dl_relocate_symbols (mod, e))
+      || grub_arch_dl_relocate_symbols (mod, e)
+      || grub_dl_add (mod))
     {
       mod->fini = 0;
       grub_dl_unload (mod);
@@ -557,13 +556,10 @@ grub_dl_load_core (void *addr, grub_size_t size)
 
   grub_dprintf ("modules", "module name: %s\n", mod->name);
   grub_dprintf ("modules", "init function: %p\n", mod->init);
-  grub_dl_call_init (mod);
 
-  if (grub_dl_add (mod))
-    {
-      grub_dl_unload (mod);
-      return 0;
-    }
+  mod->ref_count = 1;
+
+  grub_dl_call_init (mod);
 
   return mod;
  }

_______________________________________________
Grub-devel mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/grub-devel

Signature · 4 lines
Regards
Vladimir 'phcoder' Serbinenko

Personal git repository: http://repo.or.cz/w/grub2/phcoder.git