Skip to content

Commit

Permalink
Linux 6.5 compat: safe cleanup in spl_proc_fini()
Browse files Browse the repository at this point in the history
If we fail to create a proc entry in spl_proc_init() we may end up
calling unregister_sysctl_table() twice: one in the failure path of
spl_proc_init() and another time during spl_proc_fini().

Avoid the double call to unregister_sysctl_table() and while at it
refactor the code a bit to reduce code duplication.

This was accidentally introduced when the spl code was
updated for Linux 6.5 compatibility.

Reviewed-by: Brian Behlendorf <[email protected]>
Reviewed-by: Ameer Hamza <[email protected]>
Signed-off-by: Andrea Righi <[email protected]>
Closes #15234 
Closes #15235
  • Loading branch information
Andrea Righi authored Sep 2, 2023
1 parent 9da6b60 commit bcb1159
Showing 1 changed file with 18 additions and 18 deletions.
36 changes: 18 additions & 18 deletions module/os/linux/spl/spl-proc.c
Original file line number Diff line number Diff line change
Expand Up @@ -659,6 +659,21 @@ static struct ctl_table spl_root[] = {
};
#endif

static void spl_proc_cleanup(void)
{
remove_proc_entry("kstat", proc_spl);
remove_proc_entry("slab", proc_spl_kmem);
remove_proc_entry("kmem", proc_spl);
remove_proc_entry("taskq-all", proc_spl);
remove_proc_entry("taskq", proc_spl);
remove_proc_entry("spl", NULL);

if (spl_header) {
unregister_sysctl_table(spl_header);
spl_header = NULL;
}
}

int
spl_proc_init(void)
{
Expand Down Expand Up @@ -723,29 +738,14 @@ spl_proc_init(void)
goto out;
}
out:
if (rc) {
remove_proc_entry("kstat", proc_spl);
remove_proc_entry("slab", proc_spl_kmem);
remove_proc_entry("kmem", proc_spl);
remove_proc_entry("taskq-all", proc_spl);
remove_proc_entry("taskq", proc_spl);
remove_proc_entry("spl", NULL);
unregister_sysctl_table(spl_header);
}
if (rc)
spl_proc_cleanup();

return (rc);
}

void
spl_proc_fini(void)
{
remove_proc_entry("kstat", proc_spl);
remove_proc_entry("slab", proc_spl_kmem);
remove_proc_entry("kmem", proc_spl);
remove_proc_entry("taskq-all", proc_spl);
remove_proc_entry("taskq", proc_spl);
remove_proc_entry("spl", NULL);

ASSERT(spl_header != NULL);
unregister_sysctl_table(spl_header);
spl_proc_cleanup();
}

0 comments on commit bcb1159

Please sign in to comment.