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

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>

+20 -13
+20 -13
drivers/input/input.c
··· 1982 1982 struct input_dev *dev; 1983 1983 1984 1984 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); 1985 + if (!dev) 1986 + return NULL; 1994 1987 1995 - dev_set_name(&dev->dev, "input%lu", 1996 - (unsigned long)atomic_inc_return(&input_no)); 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); 1997 1993 1998 - __module_get(THIS_MODULE); 1999 - } 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); 2000 2007 2001 2008 return dev; 2002 2009 }