Skip to content

Commit 3544cf5

Browse files
committed
Input: rearrange input_alloc_device() to prepare for preallocating of vals
In preparation to have dev->vals memory pre-allocated rearrange code in input_alloc_device() so that it allows handling multiple points of failure. Reviewed-by: Jeff LaBundy <jeff@labundy.com> Reviewed-by: Benjamin Tissoires <bentiss@kernel.org> Link: https://lore.kernel.org/r/20240703213756.3375978-6-dmitry.torokhov@gmail.com Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
1 parent d469647 commit 3544cf5

1 file changed

Lines changed: 22 additions & 15 deletions

File tree

drivers/input/input.c

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1982,21 +1982,28 @@ struct input_dev *input_allocate_device(void)
19821982
struct input_dev *dev;
19831983

19841984
dev = kzalloc(sizeof(*dev), GFP_KERNEL);
1985-
if (dev) {
1986-
dev->dev.type = &input_dev_type;
1987-
dev->dev.class = &input_class;
1988-
device_initialize(&dev->dev);
1989-
mutex_init(&dev->mutex);
1990-
spin_lock_init(&dev->event_lock);
1991-
timer_setup(&dev->timer, NULL, 0);
1992-
INIT_LIST_HEAD(&dev->h_list);
1993-
INIT_LIST_HEAD(&dev->node);
1994-
1995-
dev_set_name(&dev->dev, "input%lu",
1996-
(unsigned long)atomic_inc_return(&input_no));
1997-
1998-
__module_get(THIS_MODULE);
1999-
}
1985+
if (!dev)
1986+
return NULL;
1987+
1988+
mutex_init(&dev->mutex);
1989+
spin_lock_init(&dev->event_lock);
1990+
timer_setup(&dev->timer, NULL, 0);
1991+
INIT_LIST_HEAD(&dev->h_list);
1992+
INIT_LIST_HEAD(&dev->node);
1993+
1994+
dev->dev.type = &input_dev_type;
1995+
dev->dev.class = &input_class;
1996+
device_initialize(&dev->dev);
1997+
/*
1998+
* From this point on we can no longer simply "kfree(dev)", we need
1999+
* to use input_free_device() so that device core properly frees its
2000+
* resources associated with the input device.
2001+
*/
2002+
2003+
dev_set_name(&dev->dev, "input%lu",
2004+
(unsigned long)atomic_inc_return(&input_no));
2005+
2006+
__module_get(THIS_MODULE);
20002007

20012008
return dev;
20022009
}

0 commit comments

Comments
 (0)