Re: try_module_get code understanding

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

 



On Thu, 27 Sep 2007 05:19:06 -0000, Shreyansh Jain said:

> -----
> 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;   <----
> }

> 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??.

Go look at the call sites for this function - I bet that most of them, if they
check the return code at all, only check for zero or nonzero, because they only
*care* about the case that returns zero. Since they already know they're not
passing a NULL pointer, they don't worry about that case returning a 1.  So
there's only two realistic returns - either the module is live or it isn't.

Attachment: pgpApoTJMo8s9.pgp
Description: PGP signature


[Index of Archives]     [Kernel Newbies]     [Netfilter]     [Bugtraq]     [Photo]     [Stuff]     [Gimp]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Video 4 Linux]     [Linux for the blind]     [Linux Resources]
  Powered by Linux