Skip to content

Commit 6022e75

Browse files
author
NeilBrown
committed
md: extend spinlock protection in register_md_cluster_operations
This code looks racy. The only possible race is if two modules try to register at the same time and that won't happen. But make the code look safe anyway. Signed-off-by: NeilBrown <neilb@suse.com>
1 parent abb9b22 commit 6022e75

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

drivers/md/md.c

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7427,15 +7427,19 @@ int unregister_md_personality(struct md_personality *p)
74277427
}
74287428
EXPORT_SYMBOL(unregister_md_personality);
74297429

7430-
int register_md_cluster_operations(struct md_cluster_operations *ops, struct module *module)
7430+
int register_md_cluster_operations(struct md_cluster_operations *ops,
7431+
struct module *module)
74317432
{
7432-
if (md_cluster_ops != NULL)
7433-
return -EALREADY;
7433+
int ret = 0;
74347434
spin_lock(&pers_lock);
7435-
md_cluster_ops = ops;
7436-
md_cluster_mod = module;
7435+
if (md_cluster_ops != NULL)
7436+
ret = -EALREADY;
7437+
else {
7438+
md_cluster_ops = ops;
7439+
md_cluster_mod = module;
7440+
}
74377441
spin_unlock(&pers_lock);
7438-
return 0;
7442+
return ret;
74397443
}
74407444
EXPORT_SYMBOL(register_md_cluster_operations);
74417445

0 commit comments

Comments
 (0)