From: Axel Lin Date: Tue, 20 Jul 2010 22:19:49 +0000 (-0700) Subject: acerhdf: fix resource reclaim in error path X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=a0dba697eec78fb2d4e2b76b83104a2b251ae70d;p=GitHub%2FLineageOS%2Fandroid_kernel_samsung_universal7580.git acerhdf: fix resource reclaim in error path Fix resource reclaim in below cases: 1. acerhdf_register_platform() does not properly handle platform_device_alloc() failure and platform_device_add() failure This patch adds error handing for acerhdf_register_platform(). 2. acerhdf_register_platform() return err with acerhdf_dev == NULL. as a result, acerhdf_unregister_platform() does not do resource reclaim in acerhdf_init() error path. This patch adds error handing for acerhdf_register_platform(), thus correct the error handing path in acerhdf_init(). goto out_err instead of err_unreg if acerhdf_register_platform() fail. 3. platform_device_del() should only used in error handling. Current implementation missed a platform_device_put() in acerhdf_exit. This patch fixes it by using platform_device_unregister() instead of platform_device_del() in acerhdf_unregister_platform. Signed-off-by: Axel Lin Acked-by: Peter Feuerer Cc: Matthew Garrett Acked-by: Borislav Petkov Signed-off-by: Andrew Morton Signed-off-by: Matthew Garrett --- diff --git a/drivers/platform/x86/acerhdf.c b/drivers/platform/x86/acerhdf.c index 4ce28d901b9..60f9cfcac93 100644 --- a/drivers/platform/x86/acerhdf.c +++ b/drivers/platform/x86/acerhdf.c @@ -615,17 +615,26 @@ static int acerhdf_register_platform(void) return err; acerhdf_dev = platform_device_alloc("acerhdf", -1); - platform_device_add(acerhdf_dev); + if (!acerhdf_dev) { + err = -ENOMEM; + goto err_device_alloc; + } + err = platform_device_add(acerhdf_dev); + if (err) + goto err_device_add; return 0; + +err_device_add: + platform_device_put(acerhdf_dev); +err_device_alloc: + platform_driver_unregister(&acerhdf_driver); + return err; } static void acerhdf_unregister_platform(void) { - if (!acerhdf_dev) - return; - - platform_device_del(acerhdf_dev); + platform_device_unregister(acerhdf_dev); platform_driver_unregister(&acerhdf_driver); } @@ -669,7 +678,7 @@ static int __init acerhdf_init(void) err = acerhdf_register_platform(); if (err) - goto err_unreg; + goto out_err; err = acerhdf_register_thermal(); if (err) @@ -682,7 +691,7 @@ err_unreg: acerhdf_unregister_platform(); out_err: - return -ENODEV; + return err; } static void __exit acerhdf_exit(void)