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

Staging: quickstart: free after input_unregister_device()

input_unregister_device() releases "quickstart_input" so the
input_free_device() is a double free. Also I noticed that there is a
memory leak if the call to input_register_device() fails.

Signed-off-by: Dan Carpenter <error27@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>

authored by

Dan Carpenter and committed by
Greg Kroah-Hartman
ebba26f4 5fb5d38f

+8 -2
+8 -2
drivers/staging/quickstart/quickstart.c
··· 355 355 static void quickstart_exit(void) 356 356 { 357 357 input_unregister_device(quickstart_input); 358 - input_free_device(quickstart_input); 359 358 360 359 device_remove_file(&pf_device->dev, &dev_attr_pressed_button); 361 360 device_remove_file(&pf_device->dev, &dev_attr_buttons); ··· 374 375 { 375 376 struct quickstart_btn **ptr = &quickstart_data.btn_lst; 376 377 int count; 378 + int ret; 377 379 378 380 quickstart_input = input_allocate_device(); 379 381 ··· 391 391 ptr = &((*ptr)->next); 392 392 } 393 393 394 - return input_register_device(quickstart_input); 394 + ret = input_register_device(quickstart_input); 395 + if (ret) { 396 + input_free_device(quickstart_input); 397 + return ret; 398 + } 399 + 400 + return 0; 395 401 } 396 402 397 403 static int __init quickstart_init(void)