mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* try_module_get code understanding
@ 2007-09-27  5:19 Shreyansh Jain
  2007-09-27  6:13 ` Heiko Carstens
  2007-09-27  6:14 ` Valdis.Kletnieks
  0 siblings, 2 replies; 5+ messages in thread
From: Shreyansh Jain @ 2007-09-27  5:19 UTC (permalink / raw)
  To: linux-kernel

Dear List,

I agree that this issue certainly doesn't require to be in this list (rightful
place being kernewbies) but I tried that and got no response - so trying my luck
here.

I was going through try_module_get function in include/linux/module.h file
(2.6.22 stock kernel) - which is like:

-----
static inline int try_module_get(struct module *module){
  int ret = 1;   <--- error case when !module
    if (module) {
         unsigned int cpu = get_cpu();
         if (likely(module_is_live(module)))
                local_inc(&module->ref[cpu].count);
         else
                ret = 0;   <--- error case
         put_cpu();
  }
  return ret;   <----
}
----

What I understand about the code flow is:
-- module live would return the flag stating that this module can be reference
and is NOT being removed currently.

1. In case the module pointer passed is invalid (NULL) this function would
return 1 (error case)
2. In case the module pointer is OK, and module is currently not being removed,
reference count would be incremented and 1 returned (non error case)
3. In case the module pointer is OK, and module reference count can NOT be
increased, 0 would be returned (error case).

As you can observe from above points, 0 and 1 are returned for error cases. I am
a little confused and wondering if there is something which I am missing in this
code??.

Can anyone help me out with this? Any help would be highly appreciated.

Regards
Shreyansh


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2007-09-27  7:11 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-09-27  5:19 try_module_get code understanding Shreyansh Jain
2007-09-27  6:13 ` Heiko Carstens
2007-09-27  6:26   ` Shreyansh Jain
2007-09-27  7:11     ` Heiko Carstens
2007-09-27  6:14 ` Valdis.Kletnieks

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®