Skip to content
This repository has been archived by the owner on Oct 31, 2024. It is now read-only.

Commit

Permalink
btrfs: merge module cleanup sequence to one helper
Browse files Browse the repository at this point in the history
The module exit function exit_btrfs_fs() is duplicating a section of code
in init_btrfs_fs(). Add a helper to remove the duplicated code. Due
to the init/exit section requirements the function must be inline and
not a plain static as it could cause section mismatch.

Signed-off-by: Anand Jain <[email protected]>
Reviewed-by: David Sterba <[email protected]>
Signed-off-by: David Sterba <[email protected]>
  • Loading branch information
asj authored and kdave committed Dec 5, 2022
1 parent 02bc392 commit 82c0efd
Showing 1 changed file with 10 additions and 18 deletions.
28 changes: 10 additions & 18 deletions fs/btrfs/super.c
Original file line number Diff line number Diff line change
Expand Up @@ -2837,7 +2837,7 @@ static const struct init_sequence mod_init_seq[] = {

static bool mod_init_result[ARRAY_SIZE(mod_init_seq)];

static void __exit exit_btrfs_fs(void)
static __always_inline void btrfs_exit_btrfs_fs(void)
{
int i;

Expand All @@ -2850,6 +2850,11 @@ static void __exit exit_btrfs_fs(void)
}
}

static void __exit exit_btrfs_fs(void)
{
btrfs_exit_btrfs_fs();
}

static int __init init_btrfs_fs(void)
{
int ret;
Expand All @@ -2858,26 +2863,13 @@ static int __init init_btrfs_fs(void)
for (i = 0; i < ARRAY_SIZE(mod_init_seq); i++) {
ASSERT(!mod_init_result[i]);
ret = mod_init_seq[i].init_func();
if (ret < 0)
goto error;
if (ret < 0) {
btrfs_exit_btrfs_fs();
return ret;
}
mod_init_result[i] = true;
}
return 0;

error:
/*
* If we call exit_btrfs_fs() it would cause section mismatch.
* As init_btrfs_fs() belongs to .init.text, while exit_btrfs_fs()
* belongs to .exit.text.
*/
for (i = ARRAY_SIZE(mod_init_seq) - 1; i >= 0; i--) {
if (!mod_init_result[i])
continue;
if (mod_init_seq[i].exit_func)
mod_init_seq[i].exit_func();
mod_init_result[i] = false;
}
return ret;
}

late_initcall(init_btrfs_fs);
Expand Down

0 comments on commit 82c0efd

Please sign in to comment.