Skip to content

Commit 82c0efd

Browse files
asjkdave
authored andcommitted
btrfs: merge module cleanup sequence to one helper
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]>
1 parent 02bc392 commit 82c0efd

File tree

1 file changed

+10
-18
lines changed

1 file changed

+10
-18
lines changed

fs/btrfs/super.c

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2837,7 +2837,7 @@ static const struct init_sequence mod_init_seq[] = {
28372837

28382838
static bool mod_init_result[ARRAY_SIZE(mod_init_seq)];
28392839

2840-
static void __exit exit_btrfs_fs(void)
2840+
static __always_inline void btrfs_exit_btrfs_fs(void)
28412841
{
28422842
int i;
28432843

@@ -2850,6 +2850,11 @@ static void __exit exit_btrfs_fs(void)
28502850
}
28512851
}
28522852

2853+
static void __exit exit_btrfs_fs(void)
2854+
{
2855+
btrfs_exit_btrfs_fs();
2856+
}
2857+
28532858
static int __init init_btrfs_fs(void)
28542859
{
28552860
int ret;
@@ -2858,26 +2863,13 @@ static int __init init_btrfs_fs(void)
28582863
for (i = 0; i < ARRAY_SIZE(mod_init_seq); i++) {
28592864
ASSERT(!mod_init_result[i]);
28602865
ret = mod_init_seq[i].init_func();
2861-
if (ret < 0)
2862-
goto error;
2866+
if (ret < 0) {
2867+
btrfs_exit_btrfs_fs();
2868+
return ret;
2869+
}
28632870
mod_init_result[i] = true;
28642871
}
28652872
return 0;
2866-
2867-
error:
2868-
/*
2869-
* If we call exit_btrfs_fs() it would cause section mismatch.
2870-
* As init_btrfs_fs() belongs to .init.text, while exit_btrfs_fs()
2871-
* belongs to .exit.text.
2872-
*/
2873-
for (i = ARRAY_SIZE(mod_init_seq) - 1; i >= 0; i--) {
2874-
if (!mod_init_result[i])
2875-
continue;
2876-
if (mod_init_seq[i].exit_func)
2877-
mod_init_seq[i].exit_func();
2878-
mod_init_result[i] = false;
2879-
}
2880-
return ret;
28812873
}
28822874

28832875
late_initcall(init_btrfs_fs);

0 commit comments

Comments
 (0)