Skip to content

Commit

Permalink
md: extend spinlock protection in register_md_cluster_operations
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
NeilBrown committed Aug 31, 2015
1 parent abb9b22 commit 6022e75
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions drivers/md/md.c
Original file line number Diff line number Diff line change
Expand Up @@ -7427,15 +7427,19 @@ int unregister_md_personality(struct md_personality *p)
}
EXPORT_SYMBOL(unregister_md_personality);

int register_md_cluster_operations(struct md_cluster_operations *ops, struct module *module)
int register_md_cluster_operations(struct md_cluster_operations *ops,
struct module *module)
{
if (md_cluster_ops != NULL)
return -EALREADY;
int ret = 0;
spin_lock(&pers_lock);
md_cluster_ops = ops;
md_cluster_mod = module;
if (md_cluster_ops != NULL)
ret = -EALREADY;
else {
md_cluster_ops = ops;
md_cluster_mod = module;
}
spin_unlock(&pers_lock);
return 0;
return ret;
}
EXPORT_SYMBOL(register_md_cluster_operations);

Expand Down

0 comments on commit 6022e75

Please sign in to comment.