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

xen/mce: fix up xen_late_init_mcelog() error handling

Static checkers complain about the missing call to misc_deregister() if
bind_virq_for_mce() fails.

Also I reversed the tests so that we do error handling instead of
success handling. That way we just have a series of function calls
instead of the more complicated nested if statements in the original
code. Let's preserve the error codes as well.

Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
Reviewed-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Signed-off-by: David Vrabel <david.vrabel@citrix.com>

authored by

Dan Carpenter and committed by
David Vrabel
ebfe79a7 4e8c0c8c

+19 -8
+19 -8
drivers/xen/mcelog.c
··· 393 393 394 394 static int __init xen_late_init_mcelog(void) 395 395 { 396 - /* Only DOM0 is responsible for MCE logging */ 397 - if (xen_initial_domain()) { 398 - /* register character device /dev/mcelog for xen mcelog */ 399 - if (misc_register(&xen_mce_chrdev_device)) 400 - return -ENODEV; 401 - return bind_virq_for_mce(); 402 - } 396 + int ret; 403 397 404 - return -ENODEV; 398 + /* Only DOM0 is responsible for MCE logging */ 399 + if (!xen_initial_domain()) 400 + return -ENODEV; 401 + 402 + /* register character device /dev/mcelog for xen mcelog */ 403 + ret = misc_register(&xen_mce_chrdev_device); 404 + if (ret) 405 + return ret; 406 + 407 + ret = bind_virq_for_mce(); 408 + if (ret) 409 + goto deregister; 410 + 411 + return 0; 412 + 413 + deregister: 414 + misc_deregister(&xen_mce_chrdev_device); 415 + return ret; 405 416 } 406 417 device_initcall(xen_late_init_mcelog);