Commit cfc5cba4 authored by Alasdair G. Kergon's avatar Alasdair G. Kergon Committed by Linus Torvalds

[PATCH] device-mapper: fix mirror log type module ref count

Fix module reference counting for mirror log type.
Signed-Off-By: default avatarAlasdair G Kergon <agk@redhat.com>
Signed-off-by: default avatarAndrew Morton <akpm@osdl.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@osdl.org>
parent 74a68fc2
...@@ -17,9 +17,6 @@ static DEFINE_SPINLOCK(_lock); ...@@ -17,9 +17,6 @@ static DEFINE_SPINLOCK(_lock);
int dm_register_dirty_log_type(struct dirty_log_type *type) int dm_register_dirty_log_type(struct dirty_log_type *type)
{ {
if (!try_module_get(type->module))
return -EINVAL;
spin_lock(&_lock); spin_lock(&_lock);
type->use_count = 0; type->use_count = 0;
list_add(&type->list, &_log_types); list_add(&type->list, &_log_types);
...@@ -34,10 +31,8 @@ int dm_unregister_dirty_log_type(struct dirty_log_type *type) ...@@ -34,10 +31,8 @@ int dm_unregister_dirty_log_type(struct dirty_log_type *type)
if (type->use_count) if (type->use_count)
DMWARN("Attempt to unregister a log type that is still in use"); DMWARN("Attempt to unregister a log type that is still in use");
else { else
list_del(&type->list); list_del(&type->list);
module_put(type->module);
}
spin_unlock(&_lock); spin_unlock(&_lock);
...@@ -51,6 +46,10 @@ static struct dirty_log_type *get_type(const char *type_name) ...@@ -51,6 +46,10 @@ static struct dirty_log_type *get_type(const char *type_name)
spin_lock(&_lock); spin_lock(&_lock);
list_for_each_entry (type, &_log_types, list) list_for_each_entry (type, &_log_types, list)
if (!strcmp(type_name, type->name)) { if (!strcmp(type_name, type->name)) {
if (!type->use_count && !try_module_get(type->module)){
spin_unlock(&_lock);
return NULL;
}
type->use_count++; type->use_count++;
spin_unlock(&_lock); spin_unlock(&_lock);
return type; return type;
...@@ -63,7 +62,8 @@ static struct dirty_log_type *get_type(const char *type_name) ...@@ -63,7 +62,8 @@ static struct dirty_log_type *get_type(const char *type_name)
static void put_type(struct dirty_log_type *type) static void put_type(struct dirty_log_type *type)
{ {
spin_lock(&_lock); spin_lock(&_lock);
type->use_count--; if (!--type->use_count)
module_put(type->module);
spin_unlock(&_lock); spin_unlock(&_lock);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment