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

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

 



Hello Mr. Torokhov,

Thank you for your answer.

As it is not a problem now, How about changing it to -1 ?
Although extra subtraction is not expensive but still we could optimize it
as we want kernel to optimized as much as possible.

Regards,
Aniroop Mathur


On Thu, Nov 20, 2014 at 2:27 AM, Dmitry Torokhov
<dmitry.torokhov@xxxxxxxxx> wrote:
> 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
--
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