diff options
author | Axel Lin <axel.lin@gmail.com> | 2011-07-06 11:40:51 -0400 |
---|---|---|
committer | Matthew Garrett <mjg@redhat.com> | 2011-08-05 14:46:11 -0400 |
commit | 03f8952cf63b6059e56074be6ed450dc7739cdee (patch) | |
tree | fbbd5410b36f457d4446ba77e2cff7fae5da3ff6 | |
parent | 94ee48b9287c5c22c90754a48dbcf80b2df99d5f (diff) |
platform-drivers-x86: intel_mid_thermal: fix memory leak
The memory for td_info which is allocated in initialize_sensor()
should be properly kfreed in mid_thermal_probe() error patch and
mid_thermal_remove().
Signed-off-by: Axel Lin <axel.lin@gmail.com>
Signed-off-by: Matthew Garrett <mjg@redhat.com>
-rw-r--r-- | drivers/platform/x86/intel_mid_thermal.c | 26 |
1 files changed, 19 insertions, 7 deletions
diff --git a/drivers/platform/x86/intel_mid_thermal.c b/drivers/platform/x86/intel_mid_thermal.c index 3a578323122b..ccd7b1f83519 100644 --- a/drivers/platform/x86/intel_mid_thermal.c +++ b/drivers/platform/x86/intel_mid_thermal.c | |||
@@ -493,20 +493,30 @@ static int mid_thermal_probe(struct platform_device *pdev) | |||
493 | 493 | ||
494 | /* Register each sensor with the generic thermal framework*/ | 494 | /* Register each sensor with the generic thermal framework*/ |
495 | for (i = 0; i < MSIC_THERMAL_SENSORS; i++) { | 495 | for (i = 0; i < MSIC_THERMAL_SENSORS; i++) { |
496 | struct thermal_device_info *td_info = initialize_sensor(i); | ||
497 | |||
498 | if (!td_info) { | ||
499 | ret = -ENOMEM; | ||
500 | goto err; | ||
501 | } | ||
496 | pinfo->tzd[i] = thermal_zone_device_register(name[i], | 502 | pinfo->tzd[i] = thermal_zone_device_register(name[i], |
497 | 0, initialize_sensor(i), &tzd_ops, 0, 0, 0, 0); | 503 | 0, td_info, &tzd_ops, 0, 0, 0, 0); |
498 | if (IS_ERR(pinfo->tzd[i])) | 504 | if (IS_ERR(pinfo->tzd[i])) { |
499 | goto reg_fail; | 505 | kfree(td_info); |
506 | ret = PTR_ERR(pinfo->tzd[i]); | ||
507 | goto err; | ||
508 | } | ||
500 | } | 509 | } |
501 | 510 | ||
502 | pinfo->pdev = pdev; | 511 | pinfo->pdev = pdev; |
503 | platform_set_drvdata(pdev, pinfo); | 512 | platform_set_drvdata(pdev, pinfo); |
504 | return 0; | 513 | return 0; |
505 | 514 | ||
506 | reg_fail: | 515 | err: |
507 | ret = PTR_ERR(pinfo->tzd[i]); | 516 | while (--i >= 0) { |
508 | while (--i >= 0) | 517 | kfree(pinfo->tzd[i]->devdata); |
509 | thermal_zone_device_unregister(pinfo->tzd[i]); | 518 | thermal_zone_device_unregister(pinfo->tzd[i]); |
519 | } | ||
510 | configure_adc(0); | 520 | configure_adc(0); |
511 | kfree(pinfo); | 521 | kfree(pinfo); |
512 | return ret; | 522 | return ret; |
@@ -524,8 +534,10 @@ static int mid_thermal_remove(struct platform_device *pdev) | |||
524 | int i; | 534 | int i; |
525 | struct platform_info *pinfo = platform_get_drvdata(pdev); | 535 | struct platform_info *pinfo = platform_get_drvdata(pdev); |
526 | 536 | ||
527 | for (i = 0; i < MSIC_THERMAL_SENSORS; i++) | 537 | for (i = 0; i < MSIC_THERMAL_SENSORS; i++) { |
538 | kfree(pinfo->tzd[i]->devdata); | ||
528 | thermal_zone_device_unregister(pinfo->tzd[i]); | 539 | thermal_zone_device_unregister(pinfo->tzd[i]); |
540 | } | ||
529 | 541 | ||
530 | kfree(pinfo); | 542 | kfree(pinfo); |
531 | platform_set_drvdata(pdev, NULL); | 543 | platform_set_drvdata(pdev, NULL); |