mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Valdis.Kletnieks@vt.edu
To: Shreyansh Jain <shreyansh.jain@gmail.com>
Cc: linux-kernel@vger.kernel.org
Subject: Re: try_module_get code understanding
Date: Thu, 27 Sep 2007 02:14:34 -0400	[thread overview]
Message-ID: <9977.1190873674@turing-police.cc.vt.edu> (raw)
In-Reply-To: Your message of "Thu, 27 Sep 2007 05:19:06 -0000." <loom.20070927T051622-501@post.gmane.org>

[-- Attachment #1: Type: text/plain, Size: 1399 bytes --]

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 #2: Type: application/pgp-signature, Size: 226 bytes --]

      parent reply	other threads:[~2007-09-27  6:14 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-09-27  5:19 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 message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=9977.1190873674@turing-police.cc.vt.edu \
    --to=valdis.kletnieks@vt.edu \
    --cc=linux-kernel@vger.kernel.org \
    --cc=shreyansh.jain@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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®