Skip to contentSkip to conversation

kernel: profile: fix error return code of create_proc_profile()

PATCH In review Jia-Ju Bai 2 participants 2 messages Mar 9, 2021

lore
Share & tools
lore

Jia-Ju Bai

author
#0 lore raw

PATCH 1/1 kernel: profile: fix error return code of create_proc_profile()

When proc_create() returns NULL to entry, no error return code of create_proc_profile() is assigned.
To fix this bug, err is assigned with -ENOMEM in this case.

Fixes e722d8daafb9 ("profile: Convert to hotplug state machine")
---
 kernel/profile.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
kernel/profile.c +3 -1
index 6f69a4195d56..65bf03bb8a5e 100644
@@ -549,8 +549,10 @@ int __ref create_proc_profile(void)
 #endif
 	entry = proc_create("profile", S_IWUSR | S_IRUGO,
 			    NULL, &profile_proc_ops);
-	if (!entry)
+	if (!entry) {
+		err = -ENOMEM;
 		goto err_state_onl;
+	}
 	proc_set_size(entry, (1 + prof_len) * sizeof(atomic_t));
 
 	return err;
Signature · 1 line
2.17.1
#1 lore raw
Quoted 3 lines · Jia-Ju Bai

When proc_create() returns NULL to entry, no error return code of create_proc_profile() is assigned.
To fix this bug, err is assigned with -ENOMEM in this case.

I preserved what was in commit
c270a817196a9 ("profile: Fix CPU hotplug callback registration")

which was already in commit
c33fff0afbef4 ("kernel: use non-racy method for proc entries creation")

and goes back to its original introduction in history tree's commit

    423284ee6eb52 ("[PATCH] consolidate prof_cpu_mask")

which is ignoring a failure here.
If we decide otherwise and not ignore the error then it would be good to use an earlier commit so the change also makes into v4.4+ stable.

Quoted 13 lines
Fixes e722d8daafb9 ("profile: Convert to hotplug state machine")
---
 kernel/profile.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
kernel/profile.c +0 -0
index 6f69a4195d56..65bf03bb8a5e 100644
@@ -549,8 +549,10 @@ int __ref create_proc_profile(void)
 #endif

kernel/profile.c int __ref create_proc_profile(void) · line 558

Quoted 10 lines
kernel/profile.c +3 -1
 	entry = proc_create("profile", S_IWUSR | S_IRUGO,
 			    NULL, &profile_proc_ops);
-	if (!entry)
+	if (!entry) {
+		err = -ENOMEM;
 		goto err_state_onl;
+	}
 	proc_set_size(entry, (1 + prof_len) * sizeof(atomic_t));
 
 	return err;

Sebastian