On Tue, 13 Mar 2007, Rusty Russell wrote: > Hi Trent, > > Patch looks good, just one comment: > > On Mon, 2007-03-12 at 07:07 -0700, Trent Piepho wrote: > > + use = already_uses(a, b); > > + if (!use) { > > + printk(KERN_ERR "module %s trying to un-use a module, %s, which " > > + "it is not using", a->name, b->name); > > + return 0; > > + } > > s/return 0/BUG()/. This is potentially quite a nasty bug. Ok, I did that before, I'll change it back. Note that the reference counting isn't perfect when it comes to catching mistakes. The fundamental problem is that when a module is loaded and linked, all the modules that it used symbols from gain a "use". To be symmetric, when a module is unloaded all the modules it used symbols from should lose a "use". Except, there is no record of what modules gained a "use" at link time. Suppose module 1 uses a symbol from module 2. At link time, a module_use that "1 uses 2" is created. Now say 1 does a symbol_put() on something in 2, with no matching get. The "1 uses 2" goes away. When 1 is unloaded, there is no way to tell that "1 uses 2", deleted by the extra put, is missing. If it's wanted, I think I could fix this. I'd have a separate count of static uses vs dynamic uses.