[Question: drivers/input/input.c] Why input_no is initialized to 0 ?

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

 



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
--
To unsubscribe from this list: send the line "unsubscribe linux-input" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[Index of Archives]     [Linux Media Devel]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Linux Wireless Networking]     [Linux Omap]

  Powered by Linux