Skip to content

Commit a60a71b

Browse files
David Herrmanndtor
authored andcommitted
Input: move name/timer init to input_alloc_dev()
We want to allow drivers to call input_event() at any time after the device got allocated. This means input_event() and input_register_device() must be allowed to run in parallel. The only conflicting calls in input_register_device() are init_timer() and dev_set_name(). Both can safely be moved to device allocation and we're good to go. Signed-off-by: David Herrmann <dh.herrmann@gmail.com> Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
1 parent 2f0d260 commit a60a71b

1 file changed

Lines changed: 5 additions & 5 deletions

File tree

‎drivers/input/input.c‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1734,6 +1734,7 @@ EXPORT_SYMBOL_GPL(input_class);
17341734
*/
17351735
struct input_dev *input_allocate_device(void)
17361736
{
1737+
static atomic_t input_no = ATOMIC_INIT(0);
17371738
struct input_dev *dev;
17381739

17391740
dev = kzalloc(sizeof(struct input_dev), GFP_KERNEL);
@@ -1743,9 +1744,13 @@ struct input_dev *input_allocate_device(void)
17431744
device_initialize(&dev->dev);
17441745
mutex_init(&dev->mutex);
17451746
spin_lock_init(&dev->event_lock);
1747+
init_timer(&dev->timer);
17461748
INIT_LIST_HEAD(&dev->h_list);
17471749
INIT_LIST_HEAD(&dev->node);
17481750

1751+
dev_set_name(&dev->dev, "input%ld",
1752+
(unsigned long) atomic_inc_return(&input_no) - 1);
1753+
17491754
__module_get(THIS_MODULE);
17501755
}
17511756

@@ -2019,7 +2024,6 @@ static void devm_input_device_unregister(struct device *dev, void *res)
20192024
*/
20202025
int input_register_device(struct input_dev *dev)
20212026
{
2022-
static atomic_t input_no = ATOMIC_INIT(0);
20232027
struct input_devres *devres = NULL;
20242028
struct input_handler *handler;
20252029
unsigned int packet_size;
@@ -2059,7 +2063,6 @@ int input_register_device(struct input_dev *dev)
20592063
* If delay and period are pre-set by the driver, then autorepeating
20602064
* is handled by the driver itself and we don't do it in input.c.
20612065
*/
2062-
init_timer(&dev->timer);
20632066
if (!dev->rep[REP_DELAY] && !dev->rep[REP_PERIOD]) {
20642067
dev->timer.data = (long) dev;
20652068
dev->timer.function = input_repeat_key;
@@ -2073,9 +2076,6 @@ int input_register_device(struct input_dev *dev)
20732076
if (!dev->setkeycode)
20742077
dev->setkeycode = input_default_setkeycode;
20752078

2076-
dev_set_name(&dev->dev, "input%ld",
2077-
(unsigned long) atomic_inc_return(&input_no) - 1);
2078-
20792079
error = device_add(&dev->dev);
20802080
if (error)
20812081
goto err_free_vals;

0 commit comments

Comments
 (0)