public inbox for linux-input@vger.kernel.org
 help / color / mirror / Atom feed
* [Question: drivers/input/input.c] Why input_no is initialized to 0 ?
@ 2014-11-19 20:01 Aniroop Mathur
  2014-11-19 20:57 ` Dmitry Torokhov
  0 siblings, 1 reply; 4+ messages in thread
From: Aniroop Mathur @ 2014-11-19 20:01 UTC (permalink / raw)
  To: Dmitry Torokhov, linux-input@vger.kernel.org

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.

Thanks in advance ! :)

Regards,
Aniroop Mathur

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

end of thread, other threads:[~2014-11-20 19:29 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
2014-11-19 21:19   ` Aniroop Mathur
2014-11-20 19:29     ` Dmitry Torokhov

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