From: Dmitry Torokhov <dmitry.torokhov@gmail.com>
To: Aniroop Mathur <aniroop.mathur@gmail.com>
Cc: "linux-input@vger.kernel.org" <linux-input@vger.kernel.org>
Subject: Re: [Question: drivers/input/input.c] Why input_no is initialized to 0 ?
Date: Wed, 19 Nov 2014 12:57:13 -0800 [thread overview]
Message-ID: <20141119205713.GG37989@dtor-ws> (raw)
In-Reply-To: <CADYu3087SYHPSzzEP+92Kh69fUN7gXS1otAsmT8SfuPLQB3h_A@mail.gmail.com>
Hi Aniroop,
On Thu, Nov 20, 2014 at 01:31:44AM +0530, Aniroop Mathur wrote:
> Dear Mr. Torokhov,
> Greetings of the day ! :)
>
> Recently, I saw input_allocate_device() funtion in input.c file and
> faced one small doubt about it.
> Unfortunately, I could not find the decent answer on internet. Can you
> help to answer the query as follows:
>
> In this function, input_no is initialized to 0.
> static atomic_t input_no = ATOMIC_INIT(0);
> and then it is used to set input device name like below:
> dev_set_name(&dev->dev, "input%ld", (unsigned long)
> atomic_inc_return(&input_no) - 1);
>
> Here, we are increamenting input no by 1 and then again decreamenting by 1.
> I think, it is because we have initialized input_no to 0 and we want
> name of input devices to start from input0.
>
> Is it not a good idea to initialize input_no to -1 and then only
> increamenting input_no without subtracting when setting input device
> name ?
> With this, we will be able to save one extra subtraction instruction
> every time input device is allocated.
Historically atomic_t on sparc32 had only 24 usable bits so I think
setting it to -1 would not have worked. Now it is no longer a concern,
but neither that extra subtraction is expensive so nobody bothered to
change it.
Thanks.
--
Dmitry
next prev parent reply other threads:[~2014-11-19 20:57 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-11-19 20:01 [Question: drivers/input/input.c] Why input_no is initialized to 0 ? Aniroop Mathur
2014-11-19 20:57 ` Dmitry Torokhov [this message]
2014-11-19 21:19 ` Aniroop Mathur
2014-11-20 19:29 ` Dmitry Torokhov
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=20141119205713.GG37989@dtor-ws \
--to=dmitry.torokhov@gmail.com \
--cc=aniroop.mathur@gmail.com \
--cc=linux-input@vger.kernel.org \
/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