[lkml]   [2010]   [May]   [31]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
Messages in this thread
SubjectRe: [PATCH 1/2] Make the module 'usage' lists be two-way
On Mon, May 31, 2010 at 01:16:23PM -0700, Linus Torvalds wrote:
>From: Linus Torvalds <>
>Date: Mon, 31 May 2010 12:19:37 -0700
>Subject: [PATCH 1/2] Make the module 'usage' lists be two-way
>When adding a module that depends on another one, we used to create a
>one-way list of "modules_which_use_me", so that module unloading could
>see who needs a module.
>It's actually quite simple to make that list go both ways: so that we
>not only can see "who uses me", but also see a list of modules that are
>"used by me".
>In fact, we always wanted that list in "module_unload_free()": when we
>unload a module, we want to also release all the other modules that are
>used by that module. But because we didn't have that list, we used to
>first iterate over all modules, and then iterate over each "used by me"
>list of that module.
>By making the list two-way, we simplify module_unload_free(), and it
>allows for some trivial fixes later too.
>Signed-off-by: Linus Torvalds <>

Hi, Linus,

> /* Clear the unload stuff of the module. */
> static void module_unload_free(struct module *mod)
> {
>- struct module *i;
>+ struct module_use *use, *tmp;
>- list_for_each_entry(i, &modules, list) {
>- struct module_use *use;
>- list_for_each_entry(use, &i->modules_which_use_me, list) {
>- if (use->module_which_uses == mod) {
>- DEBUGP("%s unusing %s\n", mod->name, i->name);
>- module_put(i);
>- list_del(&use->list);
>- kfree(use);
>- sysfs_remove_link(i->holders_dir, mod->name);
>- /* There can be at most one match. */
>- break;
>- }
>- }
>+ list_for_each_entry_safe(use, tmp, &mod->target_list, target_list) {
>+ struct module *i = use->target;
>+ DEBUGP("%s unusing %s\n", mod->name, i->name);
>+ module_put(i);
>+ list_del(&use->source_list);
>+ list_del(&use->target_list);
>+ kfree(use);
>+ sysfs_remove_link(i->holders_dir, mod->name);

I think it's nice to have a remove_module_usage() here, since we already
have add_module_usage().


 \ /
  Last update: 2010-06-01 04:43    [W:0.108 / U:1.824 seconds]
©2003-2018 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site