summaryrefslogtreecommitdiffstats
path: root/drivers/hwmon
diff options
context:
space:
mode:
authorWenwen Wang <wenwen@cs.uga.edu>2019-08-19 17:00:02 -0400
committerGuenter Roeck <linux@roeck-us.net>2019-08-31 11:04:57 -0400
commite027a2dea5fdde05740a98f571fc2903060559ce (patch)
treeedc75af2c0a56bd09f9d9773009457e7ab2fdcf3 /drivers/hwmon
parent7d82fcc9d9e81241778aaa22fda7be753e237d86 (diff)
hwmon (coretemp) Fix a memory leak bug
In coretemp_init(), 'zone_devices' is allocated through kcalloc(). However, it is not deallocated in the following execution if platform_driver_register() fails, leading to a memory leak. To fix this issue, introduce the 'outzone' label to free 'zone_devices' before returning the error. Signed-off-by: Wenwen Wang <wenwen@cs.uga.edu> Link: https://lore.kernel.org/r/1566248402-6538-1-git-send-email-wenwen@cs.uga.edu Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Diffstat (limited to 'drivers/hwmon')
-rw-r--r--drivers/hwmon/coretemp.c3
1 files changed, 2 insertions, 1 deletions
diff --git a/drivers/hwmon/coretemp.c b/drivers/hwmon/coretemp.c
index fe6618e49dc4..d855c78fb8be 100644
--- a/drivers/hwmon/coretemp.c
+++ b/drivers/hwmon/coretemp.c
@@ -736,7 +736,7 @@ static int __init coretemp_init(void)
736 736
737 err = platform_driver_register(&coretemp_driver); 737 err = platform_driver_register(&coretemp_driver);
738 if (err) 738 if (err)
739 return err; 739 goto outzone;
740 740
741 err = cpuhp_setup_state(CPUHP_AP_ONLINE_DYN, "hwmon/coretemp:online", 741 err = cpuhp_setup_state(CPUHP_AP_ONLINE_DYN, "hwmon/coretemp:online",
742 coretemp_cpu_online, coretemp_cpu_offline); 742 coretemp_cpu_online, coretemp_cpu_offline);
@@ -747,6 +747,7 @@ static int __init coretemp_init(void)
747 747
748outdrv: 748outdrv:
749 platform_driver_unregister(&coretemp_driver); 749 platform_driver_unregister(&coretemp_driver);
750outzone:
750 kfree(zone_devices); 751 kfree(zone_devices);
751 return err; 752 return err;
752} 753}