grub-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH 2/4] Fix insmod not to increase refcount above 1


From: Pavel Roskin
Subject: [PATCH 2/4] Fix insmod not to increase refcount above 1
Date: Tue, 21 Jul 2009 23:16:45 -0400
User-agent: StGit/0.15-rc1-9-gd8846

grub_dl_get() can return non-NULL for an already loaded module.  insmod
should not increase it refcount.  Only increase refcount if the module
is newly loaded or if the module is unused and autoloaded, so that it
won't get unloaded automatically.

It's not perfect, but close enough.  insmod won't lock autoloaded
modules with dependencies.  But it can be fixed by running insmod on the
dependent module.

ChangeLog:

        * kern/corecmd.c (grub_core_cmd_insmod): Exit without increasing
        refcount if the module is already loaded.
---
 kern/corecmd.c |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)

diff --git a/kern/corecmd.c b/kern/corecmd.c
index 03944f2..078b33e 100644
--- a/kern/corecmd.c
+++ b/kern/corecmd.c
@@ -102,7 +102,8 @@ grub_core_cmd_insmod (struct grub_command *cmd 
__attribute__ ((unused)),
   else
     mod = grub_dl_load_file (argv[0]);
 
-  if (mod)
+  /* Pin module in memory unless already pinned */
+  if (mod && mod->ref_count == 0)
     grub_dl_ref (mod);
 
   return 0;




reply via email to

[Prev in Thread] Current Thread [Next in Thread]