Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit fc3a2fca authored by Ganapathi Bhat's avatar Ganapathi Bhat Committed by Kalle Valo
Browse files

mwifiex: use atomic bitops to represent adapter status variables



Driver is using boolean variables to maintain vairous status
information of adapter. These status variables are accessed by
multiple threads and there is a possibility of a race. To avoid
this, convert these variables to a set of bitops flags, to be
operated atomically.

Below variables of mwifiex_adapter are converted to bitop flags:
surprise_removed
is_cmd_timedout
is_suspended
is_hs_configured
hs_enabling

Signed-off-by: default avatarGanapathi Bhat <gbhat@marvell.com>
Signed-off-by: default avatarKalle Valo <kvalo@codeaurora.org>
parent 5188d545
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -2322,7 +2322,8 @@ mwifiex_cfg80211_connect(struct wiphy *wiphy, struct net_device *dev,
	if (priv->scan_block)
		priv->scan_block = false;

	if (adapter->surprise_removed || adapter->is_cmd_timedout) {
	if (test_bit(MWIFIEX_SURPRISE_REMOVED, &adapter->work_flags) ||
	    test_bit(MWIFIEX_IS_CMD_TIMEDOUT, &adapter->work_flags)) {
		mwifiex_dbg(adapter, ERROR,
			    "%s: Ignore connection.\t"
			    "Card removed or FW in bad state\n",
+19 −15
Original line number Diff line number Diff line
@@ -372,7 +372,7 @@ static int mwifiex_dnld_sleep_confirm_cmd(struct mwifiex_adapter *adapter)
		adapter->ps_state = PS_STATE_SLEEP_CFM;

	if (!le16_to_cpu(sleep_cfm_buf->resp_ctrl) &&
	    (adapter->is_hs_configured &&
	    (test_bit(MWIFIEX_IS_HS_CONFIGURED, &adapter->work_flags) &&
	     !adapter->sleep_period.period)) {
		adapter->pm_wakeup_card_req = true;
		mwifiex_hs_activated_event(mwifiex_get_priv
@@ -564,25 +564,26 @@ int mwifiex_send_cmd(struct mwifiex_private *priv, u16 cmd_no,
		return -1;
	}

	if (adapter->is_suspended) {
	if (test_bit(MWIFIEX_IS_SUSPENDED, &adapter->work_flags)) {
		mwifiex_dbg(adapter, ERROR,
			    "PREP_CMD: device in suspended state\n");
		return -1;
	}

	if (adapter->hs_enabling && cmd_no != HostCmd_CMD_802_11_HS_CFG_ENH) {
	if (test_bit(MWIFIEX_IS_HS_ENABLING, &adapter->work_flags) &&
	    cmd_no != HostCmd_CMD_802_11_HS_CFG_ENH) {
		mwifiex_dbg(adapter, ERROR,
			    "PREP_CMD: host entering sleep state\n");
		return -1;
	}

	if (adapter->surprise_removed) {
	if (test_bit(MWIFIEX_SURPRISE_REMOVED, &adapter->work_flags)) {
		mwifiex_dbg(adapter, ERROR,
			    "PREP_CMD: card is removed\n");
		return -1;
	}

	if (adapter->is_cmd_timedout) {
	if (test_bit(MWIFIEX_IS_CMD_TIMEDOUT, &adapter->work_flags)) {
		mwifiex_dbg(adapter, ERROR,
			    "PREP_CMD: FW is in bad state\n");
		return -1;
@@ -789,7 +790,8 @@ int mwifiex_exec_next_cmd(struct mwifiex_adapter *adapter)
	if (priv && (host_cmd->command !=
	     cpu_to_le16(HostCmd_CMD_802_11_HS_CFG_ENH))) {
		if (adapter->hs_activated) {
			adapter->is_hs_configured = false;
			clear_bit(MWIFIEX_IS_HS_CONFIGURED,
				  &adapter->work_flags);
			mwifiex_hs_activated_event(priv, false);
		}
	}
@@ -825,7 +827,7 @@ int mwifiex_process_cmdresp(struct mwifiex_adapter *adapter)
		return -1;
	}

	adapter->is_cmd_timedout = 0;
	clear_bit(MWIFIEX_IS_CMD_TIMEDOUT, &adapter->work_flags);

	resp = (struct host_cmd_ds_command *) adapter->curr_cmd->resp_skb->data;
	if (adapter->curr_cmd->cmd_flag & CMD_F_HOSTCMD) {
@@ -927,7 +929,7 @@ mwifiex_cmd_timeout_func(struct timer_list *t)
	struct mwifiex_adapter *adapter = from_timer(adapter, t, cmd_timer);
	struct cmd_ctrl_node *cmd_node;

	adapter->is_cmd_timedout = 1;
	set_bit(MWIFIEX_IS_CMD_TIMEDOUT, &adapter->work_flags);
	if (!adapter->curr_cmd) {
		mwifiex_dbg(adapter, ERROR,
			    "cmd: empty curr_cmd\n");
@@ -953,7 +955,8 @@ mwifiex_cmd_timeout_func(struct timer_list *t)

		mwifiex_dbg(adapter, MSG,
			    "is_cmd_timedout = %d\n",
			    adapter->is_cmd_timedout);
			    test_bit(MWIFIEX_IS_CMD_TIMEDOUT,
				     &adapter->work_flags));
		mwifiex_dbg(adapter, MSG,
			    "num_tx_timeout = %d\n",
			    adapter->dbg.num_tx_timeout);
@@ -1135,7 +1138,8 @@ void
mwifiex_hs_activated_event(struct mwifiex_private *priv, u8 activated)
{
	if (activated) {
		if (priv->adapter->is_hs_configured) {
		if (test_bit(MWIFIEX_IS_HS_CONFIGURED,
			     &priv->adapter->work_flags)) {
			priv->adapter->hs_activated = true;
			mwifiex_update_rxreor_flags(priv->adapter,
						    RXREOR_FORCE_NO_DROP);
@@ -1186,11 +1190,11 @@ int mwifiex_ret_802_11_hs_cfg(struct mwifiex_private *priv,
			    phs_cfg->params.hs_config.gap);
	}
	if (conditions != HS_CFG_CANCEL) {
		adapter->is_hs_configured = true;
		set_bit(MWIFIEX_IS_HS_CONFIGURED, &adapter->work_flags);
		if (adapter->iface_type == MWIFIEX_USB)
			mwifiex_hs_activated_event(priv, true);
	} else {
		adapter->is_hs_configured = false;
		clear_bit(MWIFIEX_IS_HS_CONFIGURED, &adapter->work_flags);
		if (adapter->hs_activated)
			mwifiex_hs_activated_event(priv, false);
	}
@@ -1212,8 +1216,8 @@ mwifiex_process_hs_config(struct mwifiex_adapter *adapter)

	adapter->if_ops.wakeup(adapter);
	adapter->hs_activated = false;
	adapter->is_hs_configured = false;
	adapter->is_suspended = false;
	clear_bit(MWIFIEX_IS_HS_CONFIGURED, &adapter->work_flags);
	clear_bit(MWIFIEX_IS_SUSPENDED, &adapter->work_flags);
	mwifiex_hs_activated_event(mwifiex_get_priv(adapter,
						    MWIFIEX_BSS_ROLE_ANY),
				   false);
@@ -1273,7 +1277,7 @@ mwifiex_process_sleep_confirm_resp(struct mwifiex_adapter *adapter,
		return;
	}
	adapter->pm_wakeup_card_req = true;
	if (adapter->is_hs_configured)
	if (test_bit(MWIFIEX_IS_HS_CONFIGURED, &adapter->work_flags))
		mwifiex_hs_activated_event(mwifiex_get_priv
						(adapter, MWIFIEX_BSS_ROLE_ANY),
					   true);
+1 −1
Original line number Diff line number Diff line
@@ -813,7 +813,7 @@ mwifiex_hscfg_write(struct file *file, const char __user *ubuf,
			      MWIFIEX_SYNC_CMD, &hscfg);

	mwifiex_enable_hs(priv->adapter);
	priv->adapter->hs_enabling = false;
	clear_bit(MWIFIEX_IS_HS_ENABLING, &priv->adapter->work_flags);
	ret = count;
done:
	kfree(buf);
+2 −2
Original line number Diff line number Diff line
@@ -233,7 +233,7 @@ static void mwifiex_init_adapter(struct mwifiex_adapter *adapter)
	adapter->event_received = false;
	adapter->data_received = false;

	adapter->surprise_removed = false;
	clear_bit(MWIFIEX_SURPRISE_REMOVED, &adapter->work_flags);

	adapter->hw_status = MWIFIEX_HW_STATUS_INITIALIZING;

@@ -270,7 +270,7 @@ static void mwifiex_init_adapter(struct mwifiex_adapter *adapter)

	adapter->curr_tx_buf_size = MWIFIEX_TX_DATA_BUF_SIZE_2K;

	adapter->is_hs_configured = false;
	clear_bit(MWIFIEX_IS_HS_CONFIGURED, &adapter->work_flags);
	adapter->hs_cfg.conditions = cpu_to_le32(HS_CFG_COND_DEF);
	adapter->hs_cfg.gpio = HS_CFG_GPIO_DEF;
	adapter->hs_cfg.gap = HS_CFG_GAP_DEF;
+18 −15
Original line number Diff line number Diff line
@@ -404,7 +404,8 @@ int mwifiex_main_process(struct mwifiex_adapter *adapter)
		    !skb_queue_empty(&adapter->tx_data_q)) {
			mwifiex_process_tx_queue(adapter);
			if (adapter->hs_activated) {
				adapter->is_hs_configured = false;
				clear_bit(MWIFIEX_IS_HS_CONFIGURED,
					  &adapter->work_flags);
				mwifiex_hs_activated_event
					(mwifiex_get_priv
					(adapter, MWIFIEX_BSS_ROLE_ANY),
@@ -420,7 +421,8 @@ int mwifiex_main_process(struct mwifiex_adapter *adapter)
			(mwifiex_get_priv(adapter, MWIFIEX_BSS_ROLE_STA))) {
			mwifiex_process_bypass_tx(adapter);
			if (adapter->hs_activated) {
				adapter->is_hs_configured = false;
				clear_bit(MWIFIEX_IS_HS_CONFIGURED,
					  &adapter->work_flags);
				mwifiex_hs_activated_event
					(mwifiex_get_priv
					 (adapter, MWIFIEX_BSS_ROLE_ANY),
@@ -435,7 +437,8 @@ int mwifiex_main_process(struct mwifiex_adapter *adapter)
			(mwifiex_get_priv(adapter, MWIFIEX_BSS_ROLE_STA))) {
			mwifiex_wmm_process_tx(adapter);
			if (adapter->hs_activated) {
				adapter->is_hs_configured = false;
				clear_bit(MWIFIEX_IS_HS_CONFIGURED,
					  &adapter->work_flags);
				mwifiex_hs_activated_event
					(mwifiex_get_priv
					 (adapter, MWIFIEX_BSS_ROLE_ANY),
@@ -647,7 +650,7 @@ static int _mwifiex_fw_dpc(const struct firmware *firmware, void *context)
	if (adapter->if_ops.unregister_dev)
		adapter->if_ops.unregister_dev(adapter);

	adapter->surprise_removed = true;
	set_bit(MWIFIEX_SURPRISE_REMOVED, &adapter->work_flags);
	mwifiex_terminate_workqueue(adapter);

	if (adapter->hw_status == MWIFIEX_HW_STATUS_READY) {
@@ -870,7 +873,7 @@ mwifiex_hard_start_xmit(struct sk_buff *skb, struct net_device *dev)
		    "data: %lu BSS(%d-%d): Data <= kernel\n",
		    jiffies, priv->bss_type, priv->bss_num);

	if (priv->adapter->surprise_removed) {
	if (test_bit(MWIFIEX_SURPRISE_REMOVED, &priv->adapter->work_flags)) {
		kfree_skb(skb);
		priv->stats.tx_dropped++;
		return 0;
@@ -1372,7 +1375,7 @@ static void mwifiex_rx_work_queue(struct work_struct *work)
	struct mwifiex_adapter *adapter =
		container_of(work, struct mwifiex_adapter, rx_work);

	if (adapter->surprise_removed)
	if (test_bit(MWIFIEX_SURPRISE_REMOVED, &adapter->work_flags))
		return;
	mwifiex_process_rx(adapter);
}
@@ -1388,7 +1391,7 @@ static void mwifiex_main_work_queue(struct work_struct *work)
	struct mwifiex_adapter *adapter =
		container_of(work, struct mwifiex_adapter, main_work);

	if (adapter->surprise_removed)
	if (test_bit(MWIFIEX_SURPRISE_REMOVED, &adapter->work_flags))
		return;
	mwifiex_main_process(adapter);
}
@@ -1405,7 +1408,7 @@ static void mwifiex_uninit_sw(struct mwifiex_adapter *adapter)
	if (adapter->if_ops.disable_int)
		adapter->if_ops.disable_int(adapter);

	adapter->surprise_removed = true;
	set_bit(MWIFIEX_SURPRISE_REMOVED, &adapter->work_flags);
	mwifiex_terminate_workqueue(adapter);
	adapter->int_status = 0;

@@ -1493,11 +1496,11 @@ mwifiex_reinit_sw(struct mwifiex_adapter *adapter)
		adapter->if_ops.up_dev(adapter);

	adapter->hw_status = MWIFIEX_HW_STATUS_INITIALIZING;
	adapter->surprise_removed = false;
	clear_bit(MWIFIEX_SURPRISE_REMOVED, &adapter->work_flags);
	init_waitqueue_head(&adapter->init_wait_q);
	adapter->is_suspended = false;
	clear_bit(MWIFIEX_IS_SUSPENDED, &adapter->work_flags);
	adapter->hs_activated = false;
	adapter->is_cmd_timedout = 0;
	clear_bit(MWIFIEX_IS_CMD_TIMEDOUT, &adapter->work_flags);
	init_waitqueue_head(&adapter->hs_activate_wait_q);
	init_waitqueue_head(&adapter->cmd_wait_q.wait);
	adapter->cmd_wait_q.status = 0;
@@ -1552,7 +1555,7 @@ mwifiex_reinit_sw(struct mwifiex_adapter *adapter)
		adapter->if_ops.unregister_dev(adapter);

err_kmalloc:
	adapter->surprise_removed = true;
	set_bit(MWIFIEX_SURPRISE_REMOVED, &adapter->work_flags);
	mwifiex_terminate_workqueue(adapter);
	if (adapter->hw_status == MWIFIEX_HW_STATUS_READY) {
		mwifiex_dbg(adapter, ERROR,
@@ -1649,9 +1652,9 @@ mwifiex_add_card(void *card, struct completion *fw_done,
	adapter->fw_done = fw_done;

	adapter->hw_status = MWIFIEX_HW_STATUS_INITIALIZING;
	adapter->surprise_removed = false;
	clear_bit(MWIFIEX_SURPRISE_REMOVED, &adapter->work_flags);
	init_waitqueue_head(&adapter->init_wait_q);
	adapter->is_suspended = false;
	clear_bit(MWIFIEX_IS_SUSPENDED, &adapter->work_flags);
	adapter->hs_activated = false;
	init_waitqueue_head(&adapter->hs_activate_wait_q);
	init_waitqueue_head(&adapter->cmd_wait_q.wait);
@@ -1699,7 +1702,7 @@ mwifiex_add_card(void *card, struct completion *fw_done,
	if (adapter->if_ops.unregister_dev)
		adapter->if_ops.unregister_dev(adapter);
err_registerdev:
	adapter->surprise_removed = true;
	set_bit(MWIFIEX_SURPRISE_REMOVED, &adapter->work_flags);
	mwifiex_terminate_workqueue(adapter);
	if (adapter->hw_status == MWIFIEX_HW_STATUS_READY) {
		pr_debug("info: %s: shutdown mwifiex\n", __func__);
Loading