All of lore.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

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

* Re: [Question: drivers/input/input.c] Why input_no is initialized to 0 ?
  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
  0 siblings, 1 reply; 4+ messages in thread
From: Dmitry Torokhov @ 2014-11-19 20:57 UTC (permalink / raw)
  To: Aniroop Mathur; +Cc: linux-input

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

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

* Re: [Question: drivers/input/input.c] Why input_no is initialized to 0 ?
  2014-11-19 20:57 ` Dmitry Torokhov
@ 2014-11-19 21:19   ` Aniroop Mathur
  2014-11-20 19:29     ` Dmitry Torokhov
  0 siblings, 1 reply; 4+ messages in thread
From: Aniroop Mathur @ 2014-11-19 21:19 UTC (permalink / raw)
  To: Dmitry Torokhov; +Cc: linux-input

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@gmail.com> 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

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

* Re: [Question: drivers/input/input.c] Why input_no is initialized to 0 ?
  2014-11-19 21:19   ` Aniroop Mathur
@ 2014-11-20 19:29     ` Dmitry Torokhov
  0 siblings, 0 replies; 4+ messages in thread
From: Dmitry Torokhov @ 2014-11-20 19:29 UTC (permalink / raw)
  To: Aniroop Mathur; +Cc: linux-input

On Thursday, November 20, 2014 02:49:24 AM Aniroop Mathur wrote:
> 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.

Send patches. I think we have the same pattern in several subsystems.

Thanks.

-- 
Dmitry

^ 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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.