diff --git a/scst/src/scst.c b/scst/src/scst.c index ef0b73c65..7aa3aa923 100644 --- a/scst/src/scst.c +++ b/scst/src/scst.c @@ -42,7 +42,6 @@ unsigned long scst_trace_flag = SCST_DEFAULT_LOG_FLAGS; */ DECLARE_MUTEX(scst_mutex); -int scst_num_cpus; DECLARE_WAIT_QUEUE_HEAD(scst_dev_cmd_waitQ); LIST_HEAD(scst_dev_wait_sess_list); @@ -116,6 +115,7 @@ int scst_register_target_template(struct scst_tgt_template *vtt) { int res = 0; struct scst_tgt_template *t; + static DECLARE_MUTEX(m); TRACE_ENTRY(); @@ -149,8 +149,11 @@ int scst_register_target_template(struct scst_tgt_template *vtt) } } - if (down_interruptible(&scst_mutex) != 0) + if (down_interruptible(&m) != 0) goto out; + + if (down_interruptible(&scst_mutex) != 0) + goto out_m_up; list_for_each_entry(t, &scst_template_list, scst_template_list_entry) { if (strcmp(t->name, vtt->name) == 0) { PRINT_ERROR_PR("Target driver %s already registered", @@ -159,7 +162,6 @@ int scst_register_target_template(struct scst_tgt_template *vtt) goto out_cleanup; } } - /* That's OK to drop it. The race doesn't matter */ up(&scst_mutex); TRACE_DBG("%s", "Calling target driver's detect()"); @@ -177,6 +179,9 @@ int scst_register_target_template(struct scst_tgt_template *vtt) res = 0; +out_m_up: + up(&m); + out: TRACE_EXIT_RES(res); return res; @@ -238,21 +243,16 @@ struct scst_tgt *scst_register(struct scst_tgt_template *vtt) down(&scst_mutex); if (scst_build_proc_target_entries(tgt) < 0) { + kfree(tgt); tgt = NULL; - goto out_free; - } - - list_add_tail(&tgt->tgt_list_entry, &vtt->tgt_list); + } else + list_add_tail(&tgt->tgt_list_entry, &vtt->tgt_list); up(&scst_mutex); out: TRACE_EXIT(); return tgt; - -out_free: - kfree(tgt); - goto out; } static inline int test_sess_list(struct scst_tgt *tgt) @@ -632,16 +632,16 @@ int scst_register_dev_driver(struct scst_dev_type *dev_type) break; } } - + + if (exist) + goto out_up; + res = scst_build_proc_dev_handler_dir_entries(dev_type); if (res < 0) { goto out_up; } list_add_tail(&dev_type->dev_type_list_entry, &scst_dev_type_list); - - if (exist) - goto out_up; __scst_suspend_activity(); list_for_each_entry(dev, &scst_dev_list, dev_list_entry) { @@ -671,8 +671,7 @@ void scst_unregister_dev_driver(struct scst_dev_type *dev_type) TRACE_ENTRY(); - if (down_interruptible(&scst_mutex) != 0) - goto out; + down(&scst_mutex); __scst_suspend_activity(); list_for_each_entry(dev, &scst_dev_list, dev_list_entry) { @@ -692,7 +691,6 @@ void scst_unregister_dev_driver(struct scst_dev_type *dev_type) PRINT_INFO_PR("Device handler %s for type %d unloaded", dev_type->name, dev_type->type); -out: TRACE_EXIT(); return; } @@ -1053,19 +1051,11 @@ static struct class_interface scst_interface = { .remove = scst_remove, }; -static inline int get_cpus_count(void) -{ -#ifdef CONFIG_SMP - return cpus_weight(cpu_online_map); -#else - return 1; -#endif -} - static int __init init_scst(void) { int res = 0, i; struct scst_cmd *cmd; + int scst_num_cpus; TRACE_ENTRY(); @@ -1083,8 +1073,8 @@ static int __init init_scst(void) } #endif - scst_num_cpus = get_cpus_count(); - + scst_num_cpus = num_online_cpus(); + /* ToDo: register_cpu_notifier() */ if (scst_threads == 0) diff --git a/scst/src/scst_mem.c b/scst/src/scst_mem.c index a35c4517a..cb8b306d6 100644 --- a/scst/src/scst_mem.c +++ b/scst/src/scst_mem.c @@ -514,11 +514,11 @@ int scst_sgv_pools_init(struct scst_sgv_pools *pools) res = sgv_pool_init(&pools->norm, "sgv", 0); if (res != 0) - goto out_free_clust; + goto out; res = sgv_pool_init(&pools->norm_clust, "sgv-clust", 1); if (res != 0) - goto out; + goto out_free_clust; res = sgv_pool_init(&pools->dma, "sgv-dma", 0); if (res != 0) diff --git a/scst/src/scst_priv.h b/scst/src/scst_priv.h index c591d067b..744b1406a 100644 --- a/scst/src/scst_priv.h +++ b/scst/src/scst_priv.h @@ -131,7 +131,6 @@ extern kmem_cache_t *scst_acgd_cachep; extern struct scst_sgv_pools scst_sgv; -extern int scst_num_cpus; extern unsigned long scst_flags; extern struct semaphore scst_mutex; extern atomic_t scst_cmd_count; diff --git a/scst/src/scst_targ.c b/scst/src/scst_targ.c index 23cb8f93d..8e36d0c37 100644 --- a/scst/src/scst_targ.c +++ b/scst/src/scst_targ.c @@ -188,7 +188,6 @@ void scst_cmd_init_done(struct scst_cmd *cmd, int pref_context) } } -#ifdef EXTRACHECKS if (unlikely(cmd->lun == (lun_t)-1)) { PRINT_ERROR_PR("Wrong LUN %d, finishing cmd", -1); scst_set_cmd_error(cmd, @@ -204,7 +203,6 @@ void scst_cmd_init_done(struct scst_cmd *cmd, int pref_context) scst_setup_to_active(cmd); goto active; } -#endif TRACE_DBG("Adding cmd %p to init cmd list", cmd); list_add_tail(&cmd->cmd_list_entry, &scst_init_cmd_list); @@ -608,8 +606,7 @@ static int scst_prepare_space(struct scst_cmd *cmd) r = scst_alloc_space(cmd); else if (r == 0) { cmd->data_buf_alloced = 1; - if (cmd->data_buf_alloced && - unlikely(orig_bufflen < cmd->bufflen)) { + if (unlikely(orig_bufflen < cmd->bufflen)) { PRINT_ERROR_PR("Target driver allocated data " "buffer (size %d), is less, than " "required (size %d)", orig_bufflen,