Skip to contentSkip to conversation

x86: Fix off-by-one error in loop termination.

PATCH In review Sean Fu 2 participants 3 messages Sep 11, 2017 – Sep 25, 2017 x86

lore
Share & tools
lore

Sean Fu

author
#0 lore raw

PATCH 1/1 x86: Fix off-by-one error in loop termination.

An off-by-one error in loop terminantion conditions in create_setup_data_nodes will lead to memory leak when create_setup_data_node return error.

---
 arch/x86/kernel/ksysfs.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/kernel/ksysfs.c +1 -1
index 4afc67f..cfde6c0 100644
@@ -299,7 +299,7 @@ static int __init create_setup_data_nodes(struct kobject *parent)
 	return 0;
 
 out_clean_nodes:
-	for (j = i - 1; j > 0; j--)
+	for (j = i - 1; j >= 0; j--)
 		cleanup_setup_data_node(*(kobjp + j));
 	kfree(kobjp);
 out_setup_data_kobj:
Signature · 1 line
2.6.2
author
#1 lore raw
Quoted 25 lines · Sean Fu

An off-by-one error in loop terminantion conditions in create_setup_data_nodes will lead to memory leak when create_setup_data_node return error.

---
 arch/x86/kernel/ksysfs.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/kernel/ksysfs.c +1 -1
index 4afc67f..cfde6c0 100644
@@ -299,7 +299,7 @@ static int __init create_setup_data_nodes(struct kobject *parent)
 	return 0;
 
 out_clean_nodes:
-	for (j = i - 1; j > 0; j--)
+	for (j = i - 1; j >= 0; j--)
 		cleanup_setup_data_node(*(kobjp + j));
 	kfree(kobjp);
 out_setup_data_kobj:
Signature · 1 line
2.6.2

Appologize for the wrong subject prefix in previous email. Resent the patch right now.

Could you please review this patch?

Thanks

#2 lore raw

[tip:x86/urgent] x86/sysfs: Fix off-by-one error in loop termination

In reply to Sean Fu
x86/sysfs: Fix off-by-one error in loop termination
Commit-ID:  7d7099433d9eaaa5a989a55f1fa354c16a3ad297
Gitweb:     http://git.kernel.org/tip/7d7099433d9eaaa5a989a55f1fa354c16a3ad297
Author:     Sean Fu <[email protected]>
AuthorDate: Mon, 11 Sep 2017 08:33:21 +0800
Committer:  Thomas Gleixner <[email protected]>
CommitDate: Mon, 25 Sep 2017 09:36:16 +0200

x86/sysfs: Fix off-by-one error in loop termination

An off-by-one error in loop terminantion conditions in create_setup_data_nodes() will lead to memory leak when create_setup_data_node() failed.

---
 arch/x86/kernel/ksysfs.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/kernel/ksysfs.c +1 -1
index 4b0592c..8c1cc08 100644
@@ -299,7 +299,7 @@ static int __init create_setup_data_nodes(struct kobject *parent)
 	return 0;
 
 out_clean_nodes:
-	for (j = i - 1; j > 0; j--)
+	for (j = i - 1; j >= 0; j--)
 		cleanup_setup_data_node(*(kobjp + j));
 	kfree(kobjp);
 out_setup_data_kobj: