From: Alasdair G Kergon Fix module reference counting for mirror log type. Signed-Off-By: Alasdair G Kergon Signed-off-by: Andrew Morton --- 25-akpm/drivers/md/dm-log.c | 14 +++++++------- 1 files changed, 7 insertions(+), 7 deletions(-) diff -puN drivers/md/dm-log.c~device-mapper-fix-mirror-log-type-module-ref-count drivers/md/dm-log.c --- 25/drivers/md/dm-log.c~device-mapper-fix-mirror-log-type-module-ref-count 2005-01-22 23:31:23.155866928 -0800 +++ 25-akpm/drivers/md/dm-log.c 2005-01-22 23:31:23.158866472 -0800 @@ -17,9 +17,6 @@ static DEFINE_SPINLOCK(_lock); int dm_register_dirty_log_type(struct dirty_log_type *type) { - if (!try_module_get(type->module)) - return -EINVAL; - spin_lock(&_lock); type->use_count = 0; list_add(&type->list, &_log_types); @@ -34,10 +31,8 @@ int dm_unregister_dirty_log_type(struct if (type->use_count) DMWARN("Attempt to unregister a log type that is still in use"); - else { + else list_del(&type->list); - module_put(type->module); - } spin_unlock(&_lock); @@ -51,6 +46,10 @@ static struct dirty_log_type *get_type(c spin_lock(&_lock); list_for_each_entry (type, &_log_types, list) if (!strcmp(type_name, type->name)) { + if (!type->use_count && !try_module_get(type->module)){ + spin_unlock(&_lock); + return NULL; + } type->use_count++; spin_unlock(&_lock); return type; @@ -63,7 +62,8 @@ static struct dirty_log_type *get_type(c static void put_type(struct dirty_log_type *type) { spin_lock(&_lock); - type->use_count--; + if (!--type->use_count) + module_put(type->module); spin_unlock(&_lock); } _