Skip to contentSkip to conversation

proc: proc_sysctl: Optimize insert_links()

PATCH New Li kunyu 1 participant 1 message Jan 15, 2024

Subsystems (3)
lore
Share & tools
lore

Li kunyu

author
#0 lore raw

PATCH 1/1 proc: proc_sysctl: Optimize insert_links()

Optimize the err variable assignment location so that the err variable is manually modified when an error occurs.

---
 fs/proc/proc_sysctl.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
fs/proc/proc_sysctl.c +4 -3
index cdda684551599..737071754a6e5 100644
@@ -1258,13 +1258,14 @@ static int insert_links(struct ctl_table_header *head)
 	links = new_links(core_parent, head);
 
 	spin_lock(&sysctl_lock);
-	err = -ENOMEM;
-	if (!links)
+	if (!links) {
+		err = -ENOMEM;
 		goto out;
+	}
 
-	err = 0;
 	if (get_links(core_parent, head, head->root)) {
 		kfree(links);
+		err = 0;
 		goto out;
 	}
 
Signature · 1 line
2.18.2