Search Linux Wireless

[PATCH 20/35] Protect at76_iw_handler_set_scan() with mutex

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This prevents a race condition when a response from an AP comes before
we set state to MAC_SCANNING, but after at76_quiesce().

Signed-off-by: Pavel Roskin <proski@xxxxxxx>
---

 drivers/net/wireless/at76_usb.c |   23 +++++++++++++++++------
 1 files changed, 17 insertions(+), 6 deletions(-)


diff --git a/drivers/net/wireless/at76_usb.c b/drivers/net/wireless/at76_usb.c
index 4a86b48..8b9f75a 100644
--- a/drivers/net/wireless/at76_usb.c
+++ b/drivers/net/wireless/at76_usb.c
@@ -2305,13 +2305,20 @@ static int at76_iw_handler_set_scan(struct net_device *netdev,
 
 	at76_dbg(DBG_IOCTL, "%s: SIOCSIWSCAN", netdev->name);
 
-	if (!netif_running(netdev))
-		return -ENETDOWN;
+	if (mutex_lock_interruptible(&priv->mtx))
+		return -EINTR;
+
+	if (!netif_running(netdev)) {
+		ret = -ENETDOWN;
+		goto exit;
+	}
 
 	/* jal: we don't allow "iwlist ethX scan" while we are
 	   in monitor mode */
-	if (priv->iw_mode == IW_MODE_MONITOR)
-		return -EBUSY;
+	if (priv->iw_mode == IW_MODE_MONITOR) {
+		ret = -EBUSY;
+		goto exit;
+	}
 
 	/* Discard old scan results */
 	if ((jiffies - priv->last_scan) > (20 * HZ))
@@ -2319,8 +2326,10 @@ static int at76_iw_handler_set_scan(struct net_device *netdev,
 	priv->last_scan = jiffies;
 
 	/* Initiate a scan command */
-	if (priv->scan_state == SCAN_IN_PROGRESS)
-		return -EBUSY;
+	if (priv->scan_state == SCAN_IN_PROGRESS) {
+		ret = -EBUSY;
+		goto exit;
+	}
 
 	priv->scan_state = SCAN_IN_PROGRESS;
 
@@ -2348,6 +2357,8 @@ static int at76_iw_handler_set_scan(struct net_device *netdev,
 	at76_set_mac_state(priv, MAC_SCANNING);
 	schedule_work(&priv->work_start_scan);
 
+exit:
+	mutex_unlock(&priv->mtx);
 	return ret;
 }
 
-
To unsubscribe from this list: send the line "unsubscribe linux-wireless" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Host AP]     [ATH6KL]     [Linux Bluetooth]     [Linux Netdev]     [Kernel Newbies]     [Linux Kernel]     [IDE]     [Security]     [Git]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux ATA RAID]     [Samba]     [Device Mapper]
  Powered by Linux