Skip to contentSkip to conversation

asus_acpi: fix a memory leask in asus_hotk_get_info

PATCH New Axel Lin 1 participant 2 messages Jul 5, 2010

Subsystems (2)
lore
Share & tools
lore

Axel Lin

author
#0 lore raw

PATCH 1/2 asus_acpi: fix a memory leask in asus_hotk_get_info

In the case of no match ( hotk->model == END_MODEL ), model sholud be kfreed before return AE_OK.
This patch includes below fixes:
1. adds a missing kfree(model) before return AE_OK.
2. asus_hotk_get_info should return int, thus return 0 instead of AE_OK.

---
 drivers/platform/x86/asus_acpi.c |    5 +++--
 1 files changed, 3 insertions(+), 2 deletions(-)
drivers/platform/x86/asus_acpi.c +3 -2
index 92fd30c..ae0914d 100644
@@ -1340,7 +1340,8 @@ static int asus_hotk_get_info(void)
 			return -ENODEV;
 		}
 		hotk->methods = &model_conf[hotk->model];
-		return AE_OK;
+		kfree(model);
+		return 0;
 	}
 	hotk->methods = &model_conf[hotk->model];
 	printk(KERN_NOTICE "  %s model detected, supported\n", string);
@@ -1374,7 +1375,7 @@ static int asus_hotk_get_info(void)
 
 	kfree(model);
 
-	return AE_OK;
+	return 0;
 }
 
 static int asus_hotk_check(void)
Signature · 1 line
1.5.4.3
author
#1 lore raw

PATCH 2/2 asus_acpi: fix coding style to improve readability

In the case of no match ( hotk->model == END_MODEL ),
the only posible case to return 0 is to have a Samsung P30 detected. This patch improves readability by moving related code after if/else clause to be inside if clause.

---
 drivers/platform/x86/asus_acpi.c |    6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)
drivers/platform/x86/asus_acpi.c +3 -3
index ae0914d..e058c2b 100644
@@ -1330,6 +1330,9 @@ static int asus_hotk_get_info(void)
 			hotk->model = P30;
 			printk(KERN_NOTICE
 			       "  Samsung P30 detected, supported\n");
+			hotk->methods = &model_conf[hotk->model];
+			kfree(model);
+			return 0;
 		} else {
 			hotk->model = M2E;
 			printk(KERN_NOTICE "  unsupported model %s, trying "
@@ -1339,9 +1342,6 @@ static int asus_hotk_get_info(void)
 			kfree(model);
 			return -ENODEV;
 		}
-		hotk->methods = &model_conf[hotk->model];
-		kfree(model);
-		return 0;
 	}
 	hotk->methods = &model_conf[hotk->model];
 	printk(KERN_NOTICE "  %s model detected, supported\n", string);
Signature · 1 line
1.5.4.3