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

Configure Feed

Select the types of activity you want to include in your feed.

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 <axel.lin@gmail.com>
Acked-by: Peter Feuerer <peter@piie.net>
Cc: Matthew Garrett <mjg@redhat.com>
Acked-by: Borislav Petkov <bp@alien8.de>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Matthew Garrett <mjg@redhat.com>

authored by

Axel Lin and committed by
Matthew Garrett
a0dba697 6a984a06

+16 -7
+16 -7
drivers/platform/x86/acerhdf.c
··· 615 615 return err; 616 616 617 617 acerhdf_dev = platform_device_alloc("acerhdf", -1); 618 - platform_device_add(acerhdf_dev); 618 + if (!acerhdf_dev) { 619 + err = -ENOMEM; 620 + goto err_device_alloc; 621 + } 622 + err = platform_device_add(acerhdf_dev); 623 + if (err) 624 + goto err_device_add; 619 625 620 626 return 0; 627 + 628 + err_device_add: 629 + platform_device_put(acerhdf_dev); 630 + err_device_alloc: 631 + platform_driver_unregister(&acerhdf_driver); 632 + return err; 621 633 } 622 634 623 635 static void acerhdf_unregister_platform(void) 624 636 { 625 - if (!acerhdf_dev) 626 - return; 627 - 628 - platform_device_del(acerhdf_dev); 637 + platform_device_unregister(acerhdf_dev); 629 638 platform_driver_unregister(&acerhdf_driver); 630 639 } 631 640 ··· 678 669 679 670 err = acerhdf_register_platform(); 680 671 if (err) 681 - goto err_unreg; 672 + goto out_err; 682 673 683 674 err = acerhdf_register_thermal(); 684 675 if (err) ··· 691 682 acerhdf_unregister_platform(); 692 683 693 684 out_err: 694 - return -ENODEV; 685 + return err; 695 686 } 696 687 697 688 static void __exit acerhdf_exit(void)