try_module_get code understanding

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

 



Hello All,

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?

I have looked into other kernel code as well (2.6.16.46) and no changes in the
code. Have gone through
http://ftp.kernel.org/pub/linux/kernel/people/rusty/modules/FAQ link and found
nothing which could clear my doubts.

Any help would be appreciated.

Regards
Shreyansh

--
To unsubscribe from this list: send an email with
"unsubscribe kernelnewbies" to ecartis@xxxxxxxxxxxx
Please read the FAQ at http://kernelnewbies.org/FAQ


[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux