Commit ff1ffb85 authored by Johannes Berg's avatar Johannes Berg

iwlwifi: fix dynamic loading

Add locking to the dynamic loading code to prevent
corrupting the list if multiple device ever init at
the same time (which cannot happen for multiple PCI
devices, but could happen when different busses init
concurrently.)

Also remove a device from the list when it stops so
the list isn't left corrupted, including a fix from
Don to not crash when it was never added.
Reviewed-by: default avatarDonald H Fry <donald.h.fry@intel.com>
Tested-by: default avatarDonald H Fry <donald.h.fry@intel.com>
Reviewed-by: default avatarEmmanuel Grumbach <emmanuel.grumbach@intel.com>
Signed-off-by: default avatarDon Fry <donald.h.fry@intel.com>
Signed-off-by: default avatarJohannes Berg <johannes.berg@intel.com>
parent c76fe6d1
...@@ -131,6 +131,8 @@ struct iwl_drv { ...@@ -131,6 +131,8 @@ struct iwl_drv {
#define DVM_OP_MODE 0 #define DVM_OP_MODE 0
#define MVM_OP_MODE 1 #define MVM_OP_MODE 1
/* Protects the table contents, i.e. the ops pointer & drv list */
static struct mutex iwlwifi_opmode_table_mtx;
static struct iwlwifi_opmode_table { static struct iwlwifi_opmode_table {
const char *name; /* name: iwldvm, iwlmvm, etc */ const char *name; /* name: iwldvm, iwlmvm, etc */
const struct iwl_op_mode_ops *ops; /* pointer to op_mode ops */ const struct iwl_op_mode_ops *ops; /* pointer to op_mode ops */
...@@ -899,6 +901,7 @@ static void iwl_ucode_callback(const struct firmware *ucode_raw, void *context) ...@@ -899,6 +901,7 @@ static void iwl_ucode_callback(const struct firmware *ucode_raw, void *context)
release_firmware(ucode_raw); release_firmware(ucode_raw);
complete(&drv->request_firmware_complete); complete(&drv->request_firmware_complete);
mutex_lock(&iwlwifi_opmode_table_mtx);
op = &iwlwifi_opmode_table[DVM_OP_MODE]; op = &iwlwifi_opmode_table[DVM_OP_MODE];
/* add this device to the list of devices using this op_mode */ /* add this device to the list of devices using this op_mode */
...@@ -910,6 +913,7 @@ static void iwl_ucode_callback(const struct firmware *ucode_raw, void *context) ...@@ -910,6 +913,7 @@ static void iwl_ucode_callback(const struct firmware *ucode_raw, void *context)
} else { } else {
request_module_nowait("%s", op->name); request_module_nowait("%s", op->name);
} }
mutex_unlock(&iwlwifi_opmode_table_mtx);
return; return;
...@@ -944,6 +948,7 @@ struct iwl_drv *iwl_drv_start(struct iwl_trans *trans, ...@@ -944,6 +948,7 @@ struct iwl_drv *iwl_drv_start(struct iwl_trans *trans,
drv->cfg = cfg; drv->cfg = cfg;
init_completion(&drv->request_firmware_complete); init_completion(&drv->request_firmware_complete);
INIT_LIST_HEAD(&drv->list);
ret = iwl_request_firmware(drv, true); ret = iwl_request_firmware(drv, true);
...@@ -966,6 +971,16 @@ void iwl_drv_stop(struct iwl_drv *drv) ...@@ -966,6 +971,16 @@ void iwl_drv_stop(struct iwl_drv *drv)
iwl_dealloc_ucode(drv); iwl_dealloc_ucode(drv);
mutex_lock(&iwlwifi_opmode_table_mtx);
/*
* List is empty (this item wasn't added)
* when firmware loading failed -- in that
* case we can't remove it from any list.
*/
if (!list_empty(&drv->list))
list_del(&drv->list);
mutex_unlock(&iwlwifi_opmode_table_mtx);
kfree(drv); kfree(drv);
} }
...@@ -988,6 +1003,7 @@ int iwl_opmode_register(const char *name, const struct iwl_op_mode_ops *ops) ...@@ -988,6 +1003,7 @@ int iwl_opmode_register(const char *name, const struct iwl_op_mode_ops *ops)
int i; int i;
struct iwl_drv *drv; struct iwl_drv *drv;
mutex_lock(&iwlwifi_opmode_table_mtx);
for (i = 0; i < ARRAY_SIZE(iwlwifi_opmode_table); i++) { for (i = 0; i < ARRAY_SIZE(iwlwifi_opmode_table); i++) {
if (strcmp(iwlwifi_opmode_table[i].name, name)) if (strcmp(iwlwifi_opmode_table[i].name, name))
continue; continue;
...@@ -995,8 +1011,10 @@ int iwl_opmode_register(const char *name, const struct iwl_op_mode_ops *ops) ...@@ -995,8 +1011,10 @@ int iwl_opmode_register(const char *name, const struct iwl_op_mode_ops *ops)
list_for_each_entry(drv, &iwlwifi_opmode_table[i].drv, list) list_for_each_entry(drv, &iwlwifi_opmode_table[i].drv, list)
drv->op_mode = ops->start(drv->trans, drv->cfg, drv->op_mode = ops->start(drv->trans, drv->cfg,
&drv->fw); &drv->fw);
mutex_unlock(&iwlwifi_opmode_table_mtx);
return 0; return 0;
} }
mutex_unlock(&iwlwifi_opmode_table_mtx);
return -EIO; return -EIO;
} }
EXPORT_SYMBOL_GPL(iwl_opmode_register); EXPORT_SYMBOL_GPL(iwl_opmode_register);
...@@ -1006,6 +1024,7 @@ void iwl_opmode_deregister(const char *name) ...@@ -1006,6 +1024,7 @@ void iwl_opmode_deregister(const char *name)
int i; int i;
struct iwl_drv *drv; struct iwl_drv *drv;
mutex_lock(&iwlwifi_opmode_table_mtx);
for (i = 0; i < ARRAY_SIZE(iwlwifi_opmode_table); i++) { for (i = 0; i < ARRAY_SIZE(iwlwifi_opmode_table); i++) {
if (strcmp(iwlwifi_opmode_table[i].name, name)) if (strcmp(iwlwifi_opmode_table[i].name, name))
continue; continue;
...@@ -1018,8 +1037,10 @@ void iwl_opmode_deregister(const char *name) ...@@ -1018,8 +1037,10 @@ void iwl_opmode_deregister(const char *name)
drv->op_mode = NULL; drv->op_mode = NULL;
} }
} }
mutex_unlock(&iwlwifi_opmode_table_mtx);
return; return;
} }
mutex_unlock(&iwlwifi_opmode_table_mtx);
} }
EXPORT_SYMBOL_GPL(iwl_opmode_deregister); EXPORT_SYMBOL_GPL(iwl_opmode_deregister);
...@@ -1027,6 +1048,8 @@ static int __init iwl_drv_init(void) ...@@ -1027,6 +1048,8 @@ static int __init iwl_drv_init(void)
{ {
int i; int i;
mutex_init(&iwlwifi_opmode_table_mtx);
for (i = 0; i < ARRAY_SIZE(iwlwifi_opmode_table); i++) for (i = 0; i < ARRAY_SIZE(iwlwifi_opmode_table); i++)
INIT_LIST_HEAD(&iwlwifi_opmode_table[i].drv); INIT_LIST_HEAD(&iwlwifi_opmode_table[i].drv);
......
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