Skip to contentSkip to conversation

Input : Initialize input_no by -1

PATCH Applied Aniroop Mathur 2 participants 3 messages Dec 2, 2014 – Dec 3, 2014

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Input : Initialize input_no by -1

This patch initializes input_no by -1 in order to avoid extra subtraction operation performed everytime for allocation of an input device.

---
 drivers/input/input.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/input/input.c +2 -2
index 29ca0bb..01fe49e 100644
@@ -1774,7 +1774,7 @@ EXPORT_SYMBOL_GPL(input_class);
  */
 struct input_dev *input_allocate_device(void)
 {
-	static atomic_t input_no = ATOMIC_INIT(0);
+	static atomic_t input_no = ATOMIC_INIT(-1);
 	struct input_dev *dev;
 
 	dev = kzalloc(sizeof(struct input_dev), GFP_KERNEL);
@@ -1789,7 +1789,7 @@ struct input_dev *input_allocate_device(void)
 		INIT_LIST_HEAD(&dev->node);
 
 		dev_set_name(&dev->dev, "input%ld",
-			     (unsigned long) atomic_inc_return(&input_no) - 1);
+			     (unsigned long) atomic_inc_return(&input_no));
 
 		__module_get(THIS_MODULE);
 	}
Signature · 1 line
1.9.1
maintainer Applied
#1 lore raw
Quoted 4 lines · Aniroop Mathur

This patch initializes input_no by -1 in order to avoid extra subtraction operation performed everytime for allocation of an input device.

Applied, thank you.

By the way, we have a few more places in drivers/input that count from 0, we may want to change them as well.

Quoted 29 lines
---
 drivers/input/input.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/input/input.c +2 -2
index 29ca0bb..01fe49e 100644
@@ -1774,7 +1774,7 @@ EXPORT_SYMBOL_GPL(input_class);
  */
 struct input_dev *input_allocate_device(void)
 {
-	static atomic_t input_no = ATOMIC_INIT(0);
+	static atomic_t input_no = ATOMIC_INIT(-1);
 	struct input_dev *dev;
 
 	dev = kzalloc(sizeof(struct input_dev), GFP_KERNEL);
@@ -1789,7 +1789,7 @@ struct input_dev *input_allocate_device(void)
 		INIT_LIST_HEAD(&dev->node);
 
 		dev_set_name(&dev->dev, "input%ld",
-			     (unsigned long) atomic_inc_return(&input_no) - 1);
+			     (unsigned long) atomic_inc_return(&input_no));
 
 		__module_get(THIS_MODULE);
 	}
Signature · 1 line
1.9.1

Thanks.

Signature · 1 line
Dmitry
maintainer
#2 lore raw
Quoted 10 lines · Dmitry Torokhov
Quoted 4 lines · Aniroop Mathur

This patch initializes input_no by -1 in order to avoid extra subtraction operation performed everytime for allocation of an input device.

Applied, thank you.

By the way, we have a few more places in drivers/input that count from 0, we may want to change them as well.

Also, for patches of such nature (non urgent) there is no need to ping me so often.

Thanks.

Quoted 35 lines
Quoted 30 lines
---
 drivers/input/input.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/input/input.c +2 -2
index 29ca0bb..01fe49e 100644
@@ -1774,7 +1774,7 @@ EXPORT_SYMBOL_GPL(input_class);
  */
 struct input_dev *input_allocate_device(void)
 {
-	static atomic_t input_no = ATOMIC_INIT(0);
+	static atomic_t input_no = ATOMIC_INIT(-1);
 	struct input_dev *dev;
 
 	dev = kzalloc(sizeof(struct input_dev), GFP_KERNEL);
@@ -1789,7 +1789,7 @@ struct input_dev *input_allocate_device(void)
 		INIT_LIST_HEAD(&dev->node);
 
 		dev_set_name(&dev->dev, "input%ld",
-			     (unsigned long) atomic_inc_return(&input_no) - 1);
+			     (unsigned long) atomic_inc_return(&input_no));
 
 		__module_get(THIS_MODULE);
 	}
Signature · 1 line
1.9.1

Thanks.

Signature · 1 line
Dmitry
Signature · 1 line
Dmitry