Skip to content

Commit 780138b

Browse files
Casey Chenakpm00
authored andcommitted
alloc_tag: check mem_profiling_support in alloc_tag_init
If mem_profiling_support is false, for example by sysctl.vm.mem_profiling=never, alloc_tag_init should skip module tags allocation, codetag type registration and procfs init. Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: Casey Chen <[email protected]> Reviewed-by: Yuanyuan Zhong <[email protected]> Acked-by: Suren Baghdasaryan <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent 6a4b355 commit 780138b

File tree

1 file changed

+19
-15
lines changed

1 file changed

+19
-15
lines changed

lib/alloc_tag.c

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -244,17 +244,6 @@ static void shutdown_mem_profiling(bool remove_file)
244244
mem_profiling_support = false;
245245
}
246246

247-
static void __init procfs_init(void)
248-
{
249-
if (!mem_profiling_support)
250-
return;
251-
252-
if (!proc_create_seq(ALLOCINFO_FILE_NAME, 0400, NULL, &allocinfo_seq_op)) {
253-
pr_err("Failed to create %s file\n", ALLOCINFO_FILE_NAME);
254-
shutdown_mem_profiling(false);
255-
}
256-
}
257-
258247
void __init alloc_tag_sec_init(void)
259248
{
260249
struct alloc_tag *last_codetag;
@@ -762,19 +751,34 @@ static int __init alloc_tag_init(void)
762751
};
763752
int res;
764753

754+
sysctl_init();
755+
756+
if (!mem_profiling_support) {
757+
pr_info("Memory allocation profiling is not supported!\n");
758+
return 0;
759+
}
760+
761+
if (!proc_create_seq(ALLOCINFO_FILE_NAME, 0400, NULL, &allocinfo_seq_op)) {
762+
pr_err("Failed to create %s file\n", ALLOCINFO_FILE_NAME);
763+
shutdown_mem_profiling(false);
764+
return -ENOMEM;
765+
}
766+
765767
res = alloc_mod_tags_mem();
766-
if (res)
768+
if (res) {
769+
pr_err("Failed to reserve address space for module tags, errno = %d\n", res);
770+
shutdown_mem_profiling(true);
767771
return res;
772+
}
768773

769774
alloc_tag_cttype = codetag_register_type(&desc);
770775
if (IS_ERR(alloc_tag_cttype)) {
776+
pr_err("Allocation tags registration failed, errno = %ld\n", PTR_ERR(alloc_tag_cttype));
771777
free_mod_tags_mem();
778+
shutdown_mem_profiling(true);
772779
return PTR_ERR(alloc_tag_cttype);
773780
}
774781

775-
sysctl_init();
776-
procfs_init();
777-
778782
return 0;
779783
}
780784
module_init(alloc_tag_init);

0 commit comments

Comments
 (0)