[PATCH v3] perf/profile: Report failure to create /proc/profile

From: Yongxin Yang

Date: Wed Nov 04 2026 - 04:38:43 EST


create_proc_profile() discards the result of proc_create(): when the
entry cannot be created, the function still returns 0 and profiling
setup silently pretends to have succeeded. The local variable err is
never assigned anything but 0 and only hides that.

Report the failure and return -ENOMEM instead.

create_proc_profile() is a subsys_initcall and do_initcall_level()
discards the initcall return value, so the error message is what the
user will actually see.

Signed-off-by: Yongxin Yang <yangyongxin@xxxxxxxxxx>
---
Link: https://lore.kernel.org/all/20260824024251.279751-1-yang_yongxin123@xxxxxxx/

Changes in v3:
- Do not silently ignore a proc_create() failure: report it with pr_err()
and return -ENOMEM, as suggested by Andrew Morton. This is no longer a
pure cleanup, so 'No functional change.' is dropped.
- Drop the Reviewed-by from Bradley Morgan: v3 changes the behaviour, so
the tag no longer covers the code he reviewed on v1. Bradley is Cc'd
again for a fresh review.

kernel/profile.c | 10 ++++++----
1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/kernel/profile.c b/kernel/profile.c
index 13be6fc9fd00..818098cc094a 100644
--- a/kernel/profile.c
+++ b/kernel/profile.c
@@ -240,15 +240,17 @@ static const struct proc_ops profile_proc_ops = {
int __ref create_proc_profile(void)
{
struct proc_dir_entry *entry;
- int err = 0;

if (!prof_on)
return 0;
entry = proc_create("profile", S_IWUSR | S_IRUGO,
NULL, &profile_proc_ops);
- if (entry)
- proc_set_size(entry, (1 + prof_len) * sizeof(atomic_t));
- return err;
+ if (!entry) {
+ pr_err("profile: failed to create /proc/profile\n");
+ return -ENOMEM;
+ }
+ proc_set_size(entry, (1 + prof_len) * sizeof(atomic_t));
+ return 0;
}
subsys_initcall(create_proc_profile);
#endif /* CONFIG_PROC_FS */
--
2.25.1