From: Pavel Roskin <proski@gnu.org>
To: grub-devel@gnu.org
Subject: [PATCH 3/3] Merge struct grub_dl_list into struct grub_dl
Date: Tue, 21 Jul 2009 20:47:56 -0400 [thread overview]
Message-ID: <20090722004756.22269.60955.stgit@mj.roinet.com> (raw)
In-Reply-To: <20090722004743.22269.56117.stgit@mj.roinet.com>
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(-)
diff --git a/include/grub/dl.h b/include/grub/dl.h
index 3f8b328..55cc6cc 100644
--- a/include/grub/dl.h
+++ b/include/grub/dl.h
@@ -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;
diff --git a/kern/dl.c b/kern/dl.c
index e2382d6..81c211e 100644
--- a/kern/dl.c
+++ b/kern/dl.c
@@ -40,31 +40,17 @@
\f
-struct grub_dl_list
-{
- struct grub_dl_list *next;
- grub_dl_t mod;
-};
-typedef struct grub_dl_list *grub_dl_list_t;
-
-static grub_dl_list_t grub_dl_head;
+static grub_dl_t grub_dl_head;
static grub_err_t
grub_dl_add (grub_dl_t mod)
{
- grub_dl_list_t l;
-
if (grub_dl_get (mod->name))
return grub_error (GRUB_ERR_BAD_MODULE,
"`%s' is already loaded", mod->name);
- l = (grub_dl_list_t) grub_malloc (sizeof (*l));
- if (! l)
- return grub_errno;
-
- l->mod = mod;
- l->next = grub_dl_head;
- grub_dl_head = l;
+ mod->next = grub_dl_head;
+ grub_dl_head = mod;
return GRUB_ERR_NONE;
}
@@ -72,13 +58,12 @@ grub_dl_add (grub_dl_t mod)
static void
grub_dl_remove (grub_dl_t mod)
{
- grub_dl_list_t *p, q;
+ grub_dl_t *p, q;
for (p = &grub_dl_head, q = *p; q; p = &q->next, q = *p)
- if (q->mod == mod)
+ if (q == mod)
{
*p = q->next;
- grub_free (q);
return;
}
}
@@ -86,11 +71,11 @@ grub_dl_remove (grub_dl_t mod)
grub_dl_t
grub_dl_get (const char *name)
{
- grub_dl_list_t l;
+ grub_dl_t mod;
- for (l = grub_dl_head; l; l = l->next)
- if (grub_strcmp (name, l->mod->name) == 0)
- return l->mod;
+ for (mod = grub_dl_head; mod; mod = mod->next)
+ if (grub_strcmp (name, mod->name) == 0)
+ return mod;
return 0;
}
@@ -98,10 +83,10 @@ grub_dl_get (const char *name)
void
grub_dl_iterate (int (*hook) (grub_dl_t mod))
{
- grub_dl_list_t l;
+ grub_dl_t mod;
- for (l = grub_dl_head; l; l = l->next)
- if (hook (l->mod))
+ for (mod = grub_dl_head; mod; mod = mod->next)
+ if (hook (mod))
break;
}
@@ -684,17 +669,17 @@ grub_dl_unload_unneeded (void)
{
/* Because grub_dl_remove modifies the list of modules, this
implementation is tricky. */
- grub_dl_list_t p = grub_dl_head;
+ grub_dl_t mod = grub_dl_head;
- while (p)
+ while (mod)
{
- if (grub_dl_unload (p->mod))
+ if (grub_dl_unload (mod))
{
- p = grub_dl_head;
+ mod = grub_dl_head;
continue;
}
- p = p->next;
+ mod = mod->next;
}
}
@@ -704,13 +689,13 @@ grub_dl_unload_all (void)
{
while (grub_dl_head)
{
- grub_dl_list_t p;
+ grub_dl_t mod;
grub_dl_unload_unneeded ();
/* Force to decrement the ref count. This will purge pre-loaded
modules and manually inserted modules. */
- for (p = grub_dl_head; p; p = p->next)
- p->mod->ref_count--;
+ for (mod = grub_dl_head; mod; mod = mod->next)
+ mod->ref_count--;
}
}
next prev parent reply other threads:[~2009-07-22 0:48 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-07-22 0:47 [PATCH 1/3] Don't initialize module before grub_dl_add() succeeds Pavel Roskin
2009-07-22 0:47 ` [PATCH 2/3] Eliminate grub_dl_call_init() Pavel Roskin
2009-07-23 8:30 ` Vladimir 'phcoder' Serbinenko
2009-07-22 0:47 ` Pavel Roskin [this message]
2009-07-23 8:33 ` [PATCH 1/3] Don't initialize module before grub_dl_add() succeeds Vladimir 'phcoder' Serbinenko
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=20090722004756.22269.60955.stgit@mj.roinet.com \
--to=proski@gnu.org \
--cc=grub-devel@gnu.org \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.