Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

David Herrmann and committed by
Dmitry Torokhov
a60a71b0 2f0d2604

+5 -5
+5 -5
drivers/input/input.c
··· 1734 1734 */ 1735 1735 struct input_dev *input_allocate_device(void) 1736 1736 { 1737 + static atomic_t input_no = ATOMIC_INIT(0); 1737 1738 struct input_dev *dev; 1738 1739 1739 1740 dev = kzalloc(sizeof(struct input_dev), GFP_KERNEL); ··· 1744 1743 device_initialize(&dev->dev); 1745 1744 mutex_init(&dev->mutex); 1746 1745 spin_lock_init(&dev->event_lock); 1746 + init_timer(&dev->timer); 1747 1747 INIT_LIST_HEAD(&dev->h_list); 1748 1748 INIT_LIST_HEAD(&dev->node); 1749 + 1750 + dev_set_name(&dev->dev, "input%ld", 1751 + (unsigned long) atomic_inc_return(&input_no) - 1); 1749 1752 1750 1753 __module_get(THIS_MODULE); 1751 1754 } ··· 2024 2019 */ 2025 2020 int input_register_device(struct input_dev *dev) 2026 2021 { 2027 - static atomic_t input_no = ATOMIC_INIT(0); 2028 2022 struct input_devres *devres = NULL; 2029 2023 struct input_handler *handler; 2030 2024 unsigned int packet_size; ··· 2063 2059 * If delay and period are pre-set by the driver, then autorepeating 2064 2060 * is handled by the driver itself and we don't do it in input.c. 2065 2061 */ 2066 - init_timer(&dev->timer); 2067 2062 if (!dev->rep[REP_DELAY] && !dev->rep[REP_PERIOD]) { 2068 2063 dev->timer.data = (long) dev; 2069 2064 dev->timer.function = input_repeat_key; ··· 2075 2072 2076 2073 if (!dev->setkeycode) 2077 2074 dev->setkeycode = input_default_setkeycode; 2078 - 2079 - dev_set_name(&dev->dev, "input%ld", 2080 - (unsigned long) atomic_inc_return(&input_no) - 1); 2081 2075 2082 2076 error = device_add(&dev->dev); 2083 2077 if (error)