Skip to contentSkip to conversation

staging: wilc1000: move initialization of the config values

PATCH New Alison Schofield 1 participant 1 message Mar 21, 2016 Staging

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 staging: wilc1000: move initialization of the config values

Move the initialization of the config values so that an uninit'd mutex is not exposed and to simplify the initialization process.

The code was allocating a structure with a lock, initializing and taking the lock, setting some values, and then releasing the lock. If no other thread can get it, then the lock isn't needed. If another thread can get it, it could find it before the mutex is initialized.

Make it safe and simple by setting the config values and initializing their mutex before the kthread is started. No lock/unlock needed.

---
 drivers/staging/wilc1000/host_interface.c | 18 ++++++++----------
 1 file changed, 8 insertions(+), 10 deletions(-)
drivers/staging/wilc1000/host_interface.c +8 -10
index 0a922c7..7661d52 100644
@@ -3404,6 +3404,14 @@ int wilc_init(struct net_device *dev, struct host_if_drv **hif_drv_handler)
 		sema_init(&hif_sema_deinit, 1);
 	}
 
+	hif_drv->cfg_values.site_survey_enabled = SITE_SURVEY_OFF;
+	hif_drv->cfg_values.scan_source = DEFAULT_SCAN;
+	hif_drv->cfg_values.active_scan_time = ACTIVE_SCAN_TIME;
+	hif_drv->cfg_values.passive_scan_time = PASSIVE_SCAN_TIME;
+	hif_drv->cfg_values.curr_tx_rate = AUTORATE;
+
+	mutex_init(&hif_drv->cfg_values_lock);
+
 	sema_init(&hif_drv->sem_test_key_block, 0);
 	sema_init(&hif_drv->sem_test_disconn_block, 0);
 	sema_init(&hif_drv->sem_get_rssi, 0);
@@ -3434,20 +3442,10 @@ int wilc_init(struct net_device *dev, struct host_if_drv **hif_drv_handler)
 	setup_timer(&hif_drv->connect_timer, TimerCB_Connect, 0);
 	setup_timer(&hif_drv->remain_on_ch_timer, ListenTimerCB, 0);
 
-	mutex_init(&hif_drv->cfg_values_lock);
-	mutex_lock(&hif_drv->cfg_values_lock);
-
 	hif_drv->hif_state = HOST_IF_IDLE;
-	hif_drv->cfg_values.site_survey_enabled = SITE_SURVEY_OFF;
-	hif_drv->cfg_values.scan_source = DEFAULT_SCAN;
-	hif_drv->cfg_values.active_scan_time = ACTIVE_SCAN_TIME;
-	hif_drv->cfg_values.passive_scan_time = PASSIVE_SCAN_TIME;
-	hif_drv->cfg_values.curr_tx_rate = AUTORATE;
 
 	hif_drv->p2p_timeout = 0;
 
-	mutex_unlock(&hif_drv->cfg_values_lock);
-
 	clients_count++;
 
 	return result;
Signature · 1 line
2.1.4