Linux 6.5 compat: safe cleanup in spl_proc_fini()

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 <behlendorf1@llnl.gov>
Reviewed-by: Ameer Hamza <ahamza@ixsystems.com>
Signed-off-by: Andrea Righi <andrea.righi@canonical.com>
Closes #15234 
Closes #15235
This commit is contained in:
Andrea Righi 2023-09-02 02:21:40 +02:00 committed by GitHub
parent 9da6b60417
commit bcb1159c09
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 18 additions and 18 deletions

View File

@ -659,6 +659,21 @@ static struct ctl_table spl_root[] = {
}; };
#endif #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 int
spl_proc_init(void) spl_proc_init(void)
{ {
@ -723,15 +738,8 @@ spl_proc_init(void)
goto out; goto out;
} }
out: out:
if (rc) { if (rc)
remove_proc_entry("kstat", proc_spl); spl_proc_cleanup();
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);
}
return (rc); return (rc);
} }
@ -739,13 +747,5 @@ out:
void void
spl_proc_fini(void) spl_proc_fini(void)
{ {
remove_proc_entry("kstat", proc_spl); spl_proc_cleanup();
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);
} }