Merge branch 'x86-mm-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git...
[cascardo/linux.git] / drivers / staging / rtl8192u / r8192U_core.c
index 849a95e..dd0970f 100644 (file)
@@ -235,7 +235,6 @@ static void CamResetAllEntry(struct net_device *dev)
         */
        ulcommand |= BIT(31) | BIT(30);
        write_nic_dword(dev, RWCAM, ulcommand);
-
 }
 
 
@@ -254,7 +253,7 @@ u32 read_cam(struct net_device *dev, u8 addr)
        return data;
 }
 
-void write_nic_byte_E(struct net_device *dev, int indx, u8 data)
+int write_nic_byte_E(struct net_device *dev, int indx, u8 data)
 {
        int status;
        struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
@@ -262,7 +261,7 @@ void write_nic_byte_E(struct net_device *dev, int indx, u8 data)
        u8 *usbdata = kzalloc(sizeof(data), GFP_KERNEL);
 
        if (!usbdata)
-               return;
+               return -ENOMEM;
        *usbdata = data;
 
        status = usb_control_msg(udev, usb_sndctrlpipe(udev, 0),
@@ -270,9 +269,12 @@ void write_nic_byte_E(struct net_device *dev, int indx, u8 data)
                                 indx | 0xfe00, 0, usbdata, 1, HZ / 2);
        kfree(usbdata);
 
-       if (status < 0)
+       if (status < 0){
                netdev_err(dev, "write_nic_byte_E TimeOut! status: %d\n",
                           status);
+               return status;
+       }
+       return 0;
 }
 
 int read_nic_byte_E(struct net_device *dev, int indx, u8 *data)
@@ -298,8 +300,9 @@ int read_nic_byte_E(struct net_device *dev, int indx, u8 *data)
 
        return 0;
 }
+
 /* as 92U has extend page from 4 to 16, so modify functions below. */
-void write_nic_byte(struct net_device *dev, int indx, u8 data)
+int write_nic_byte(struct net_device *dev, int indx, u8 data)
 {
        int status;
 
@@ -308,7 +311,7 @@ void write_nic_byte(struct net_device *dev, int indx, u8 data)
        u8 *usbdata = kzalloc(sizeof(data), GFP_KERNEL);
 
        if (!usbdata)
-               return;
+               return -ENOMEM;
        *usbdata = data;
 
        status = usb_control_msg(udev, usb_sndctrlpipe(udev, 0),
@@ -317,16 +320,17 @@ void write_nic_byte(struct net_device *dev, int indx, u8 data)
                                 usbdata, 1, HZ / 2);
        kfree(usbdata);
 
-       if (status < 0)
+       if (status < 0) {
                netdev_err(dev, "write_nic_byte TimeOut! status: %d\n", status);
+               return status;
+       }
 
-
+       return 0;
 }
 
 
-void write_nic_word(struct net_device *dev, int indx, u16 data)
+int write_nic_word(struct net_device *dev, int indx, u16 data)
 {
-
        int status;
 
        struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
@@ -334,7 +338,7 @@ void write_nic_word(struct net_device *dev, int indx, u16 data)
        u16 *usbdata = kzalloc(sizeof(data), GFP_KERNEL);
 
        if (!usbdata)
-               return;
+               return -ENOMEM;
        *usbdata = data;
 
        status = usb_control_msg(udev, usb_sndctrlpipe(udev, 0),
@@ -343,15 +347,17 @@ void write_nic_word(struct net_device *dev, int indx, u16 data)
                                 usbdata, 2, HZ / 2);
        kfree(usbdata);
 
-       if (status < 0)
+       if (status < 0) {
                netdev_err(dev, "write_nic_word TimeOut! status: %d\n", status);
+               return status;
+       }
 
+       return 0;
 }
 
 
-void write_nic_dword(struct net_device *dev, int indx, u32 data)
+int write_nic_dword(struct net_device *dev, int indx, u32 data)
 {
-
        int status;
 
        struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
@@ -359,7 +365,7 @@ void write_nic_dword(struct net_device *dev, int indx, u32 data)
        u32 *usbdata = kzalloc(sizeof(data), GFP_KERNEL);
 
        if (!usbdata)
-               return;
+               return -ENOMEM;
        *usbdata = data;
 
        status = usb_control_msg(udev, usb_sndctrlpipe(udev, 0),
@@ -369,10 +375,13 @@ void write_nic_dword(struct net_device *dev, int indx, u32 data)
        kfree(usbdata);
 
 
-       if (status < 0)
+       if (status < 0) {
                netdev_err(dev, "write_nic_dword TimeOut! status: %d\n",
                           status);
+               return status;
+       }
 
+       return 0;
 }
 
 
@@ -738,7 +747,6 @@ void rtl8192_update_msr(struct net_device *dev)
         * master (see the create BSS/IBSS func)
         */
        if (priv->ieee80211->state == IEEE80211_LINKED) {
-
                if (priv->ieee80211->iw_mode == IW_MODE_INFRA)
                        msr |= (MSR_LINK_MANAGED << MSR_LINK_SHIFT);
                else if (priv->ieee80211->iw_mode == IW_MODE_ADHOC)
@@ -773,11 +781,10 @@ static void rtl8192_rx_isr(struct urb *urb);
 
 static u32 get_rxpacket_shiftbytes_819xusb(struct ieee80211_rx_stats *pstats)
 {
-
        return (sizeof(rx_desc_819x_usb) + pstats->RxDrvInfoSize
                + pstats->RxBufShift);
-
 }
+
 static int rtl8192_rx_initiate(struct net_device *dev)
 {
        struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
@@ -874,6 +881,7 @@ void rtl8192_set_rxconf(struct net_device *dev)
 
        write_nic_dword(dev, RCR, rxconf);
 }
+
 /* wait to be removed */
 void rtl8192_rx_enable(struct net_device *dev)
 {
@@ -943,9 +951,9 @@ inline u16 ieeerate2rtlrate(int rate)
                return 11;
        default:
                return 3;
-
        }
 }
+
 static u16 rtl_rate[] = {10, 20, 55, 110, 60, 90, 120, 180, 240, 360, 480, 540};
 inline u16 rtl8192_rate2rate(short rate)
 {
@@ -1050,7 +1058,7 @@ static void rtl8192_hard_data_xmit(struct sk_buff *skb, struct net_device *dev,
 
        spin_lock_irqsave(&priv->tx_lock, flags);
 
-       memcpy((unsigned char *)(skb->cb), &dev, sizeof(dev));
+       *(struct net_device **)(skb->cb) = dev;
        tcb_desc->bTxEnableFwCalcDur = 1;
        skb_push(skb, priv->ieee80211->tx_headroom);
        ret = rtl8192_tx(dev, skb);
@@ -1100,7 +1108,7 @@ static void rtl8192_tx_isr(struct urb *tx_urb)
        if (!skb)
                return;
 
-       dev = (struct net_device *)(skb->cb);
+       dev = *(struct net_device **)(skb->cb);
        tcb_desc = (cb_desc *)(skb->cb + MAX_DEV_ADDR_SIZE);
        queue_index = tcb_desc->queue_index;
 
@@ -1108,7 +1116,7 @@ static void rtl8192_tx_isr(struct urb *tx_urb)
 
        if (tcb_desc->queue_index != TXCMD_QUEUE) {
                if (tx_urb->status == 0) {
-                       dev->trans_start = jiffies;
+                       netif_trans_update(dev);
                        priv->stats.txoktotal++;
                        priv->ieee80211->LinkDetectInfo.NumTxOkInPeriod++;
                        priv->stats.txbytesunicast +=
@@ -1149,7 +1157,6 @@ static void rtl8192_tx_isr(struct urb *tx_urb)
                        return; /* avoid further processing AMSDU */
                }
        }
-
 }
 
 static void rtl8192_config_rate(struct net_device *dev, u16 *rate_config)
@@ -1272,11 +1279,10 @@ static void rtl8192_update_cap(struct net_device *dev, u16 cap)
                priv->slot_time = slot_time;
                write_nic_byte(dev, SLOT_TIME, slot_time);
        }
-
 }
+
 static void rtl8192_net_update(struct net_device *dev)
 {
-
        struct r8192_priv *priv = ieee80211_priv(dev);
        struct ieee80211_network *net;
        u16 BcnTimeCfg = 0, BcnCW = 6, BcnIFS = 0xf;
@@ -1303,9 +1309,6 @@ static void rtl8192_net_update(struct net_device *dev)
 
                write_nic_word(dev, BCN_TCFG, BcnTimeCfg);
        }
-
-
-
 }
 
 /* temporary hw beacon is not used any more.
@@ -1315,6 +1318,7 @@ void rtl819xusb_beacon_tx(struct net_device *dev, u16  tx_rate)
 {
 
 }
+
 inline u8 rtl8192_IsWirelessBMode(u16 rate)
 {
        if (((rate <= 110) && (rate != 60) && (rate != 90)) || (rate == 220))
@@ -1715,7 +1719,7 @@ short rtl8192_tx(struct net_device *dev, struct sk_buff *skb)
                                return -1;
                        }
                }
-               dev->trans_start = jiffies;
+               netif_trans_update(dev);
                atomic_inc(&priv->tx_pending[tcb_desc->queue_index]);
                return 0;
        }
@@ -1737,7 +1741,6 @@ static short rtl8192_usb_initendpoints(struct net_device *dev)
 
 #ifndef JACKSON_NEW_RX
        for (i = 0; i < (MAX_RX_URB + 1); i++) {
-
                priv->rx_urb[i] = usb_alloc_urb(0, GFP_KERNEL);
 
                priv->rx_urb[i]->transfer_buffer =
@@ -1782,8 +1785,8 @@ static short rtl8192_usb_initendpoints(struct net_device *dev)
 
        netdev_dbg(dev, "End of initendpoints\n");
        return 0;
-
 }
+
 #ifdef THOMAS_BEACON
 static void rtl8192_usb_deleteendpoints(struct net_device *dev)
 {
@@ -1820,7 +1823,6 @@ void rtl8192_usb_deleteendpoints(struct net_device *dev)
                }
                kfree(priv->rx_urb);
                priv->rx_urb = NULL;
-
        }
 #else
        kfree(priv->rx_urb);
@@ -1888,6 +1890,7 @@ static void rtl8192_update_beacon(struct work_struct *work)
                net->bssht.bdRT2RTLongSlotTime;
        rtl8192_update_cap(dev, net->capability);
 }
+
 /*
 * background support to run QoS activate functionality
 */
@@ -1992,7 +1995,6 @@ static int rtl8192_handle_beacon(struct net_device *dev,
        rtl8192_qos_handle_probe_response(priv, 1, network);
        schedule_delayed_work(&priv->update_beacon_wq, 0);
        return 0;
-
 }
 
 /*
@@ -2007,7 +2009,7 @@ static int rtl8192_qos_association_resp(struct r8192_priv *priv,
        u32 size = sizeof(struct ieee80211_qos_parameters);
        int set_qos_param = 0;
 
-       if ((priv == NULL) || (network == NULL))
+       if (!priv || !network)
                return 0;
 
        if (priv->ieee80211->state != IEEE80211_LINKED)
@@ -2182,6 +2184,7 @@ static u8 rtl8192_getSupportedWireleeMode(struct net_device *dev)
        }
        return ret;
 }
+
 static void rtl8192_SetWirelessMode(struct net_device *dev, u8 wireless_mode)
 {
        struct r8192_priv *priv = ieee80211_priv(dev);
@@ -2223,8 +2226,8 @@ static void rtl8192_SetWirelessMode(struct net_device *dev, u8 wireless_mode)
                priv->ieee80211->pHTInfo->bEnableHT = 0;
        RT_TRACE(COMP_INIT, "Current Wireless Mode is %x\n", wireless_mode);
        rtl8192_refresh_supportrate(priv);
-
 }
+
 /* init priv variables here. only non_zero value should be initialized here. */
 static void rtl8192_init_priv_variable(struct net_device *dev)
 {
@@ -2373,8 +2376,7 @@ static void rtl8192_init_priv_lock(struct r8192_priv *priv)
 {
        spin_lock_init(&priv->tx_lock);
        spin_lock_init(&priv->irq_lock);
-       sema_init(&priv->wx_sem, 1);
-       sema_init(&priv->rf_sem, 1);
+       mutex_init(&priv->wx_mutex);
        mutex_init(&priv->mutex);
 }
 
@@ -2432,7 +2434,8 @@ static inline u16 endian_swap(u16 *data)
        *data = (tmp >> 8) | (tmp << 8);
        return *data;
 }
-static void rtl8192_read_eeprom_info(struct net_device *dev)
+
+static int rtl8192_read_eeprom_info(struct net_device *dev)
 {
        u16 wEPROM_ID = 0;
        u8 bMac_Tmp_Addr[6] = {0x00, 0xe0, 0x4c, 0x00, 0x00, 0x02};
@@ -2440,9 +2443,13 @@ static void rtl8192_read_eeprom_info(struct net_device *dev)
        struct r8192_priv *priv = ieee80211_priv(dev);
        u16 tmpValue = 0;
        int i;
+       int ret;
 
        RT_TRACE(COMP_EPROM, "===========>%s()\n", __func__);
-       wEPROM_ID = eprom_read(dev, 0); /* first read EEPROM ID out; */
+       ret = eprom_read(dev, 0); /* first read EEPROM ID out; */
+       if (ret < 0)
+               return ret;
+       wEPROM_ID = (u16)ret;
        RT_TRACE(COMP_EPROM, "EEPROM ID is 0x%x\n", wEPROM_ID);
 
        if (wEPROM_ID != RTL8190_EEPROM_ID)
@@ -2454,13 +2461,25 @@ static void rtl8192_read_eeprom_info(struct net_device *dev)
 
        if (bLoad_From_EEPOM) {
                tmpValue = eprom_read(dev, EEPROM_VID >> 1);
+               ret = eprom_read(dev, EEPROM_VID >> 1);
+               if (ret < 0)
+                       return ret;
+               tmpValue = (u16)ret;
                priv->eeprom_vid = endian_swap(&tmpValue);
-               priv->eeprom_pid = eprom_read(dev, EEPROM_PID >> 1);
-               tmpValue = eprom_read(dev, EEPROM_ChannelPlan >> 1);
+               ret = eprom_read(dev, EEPROM_PID >> 1);
+               if (ret < 0)
+                       return ret;
+               priv->eeprom_pid = (u16)ret;
+               ret = eprom_read(dev, EEPROM_ChannelPlan >> 1);
+               if (ret < 0)
+                       return ret;
+               tmpValue = (u16)ret;
                priv->eeprom_ChannelPlan = (tmpValue & 0xff00) >> 8;
                priv->btxpowerdata_readfromEEPORM = true;
-               priv->eeprom_CustomerID =
-                       eprom_read(dev, (EEPROM_Customer_ID >> 1)) >> 8;
+               ret = eprom_read(dev, (EEPROM_Customer_ID >> 1)) >> 8;
+               if (ret < 0)
+                       return ret;
+               priv->eeprom_CustomerID = (u16)ret;
        } else {
                priv->eeprom_vid = 0;
                priv->eeprom_pid = 0;
@@ -2478,10 +2497,10 @@ static void rtl8192_read_eeprom_info(struct net_device *dev)
                int i;
 
                for (i = 0; i < 6; i += 2) {
-                       u16 tmp = 0;
-
-                       tmp = eprom_read(dev, (u16)((EEPROM_NODE_ADDRESS_BYTE_0 + i) >> 1));
-                       *(u16 *)(&dev->dev_addr[i]) = tmp;
+                       ret = eprom_read(dev, (u16)((EEPROM_NODE_ADDRESS_BYTE_0 + i) >> 1));
+                       if (ret < 0)
+                               return ret;
+                       *(u16 *)(&dev->dev_addr[i]) = (u16)ret;
                }
        } else {
                memcpy(dev->dev_addr, bMac_Tmp_Addr, 6);
@@ -2493,52 +2512,72 @@ static void rtl8192_read_eeprom_info(struct net_device *dev)
 
        if (priv->card_8192_version == (u8)VERSION_819xU_A) {
                /* read Tx power gain offset of legacy OFDM to HT rate */
-               if (bLoad_From_EEPOM)
-                       priv->EEPROMTxPowerDiff = (eprom_read(dev, (EEPROM_TxPowerDiff >> 1)) & 0xff00) >> 8;
-               else
+               if (bLoad_From_EEPOM) {
+                       ret = eprom_read(dev, (EEPROM_TxPowerDiff >> 1));
+                       if (ret < 0)
+                               return ret;
+                       priv->EEPROMTxPowerDiff = ((u16)ret & 0xff00) >> 8;
+               } else
                        priv->EEPROMTxPowerDiff = EEPROM_Default_TxPower;
                RT_TRACE(COMP_EPROM, "TxPowerDiff:%d\n", priv->EEPROMTxPowerDiff);
                /* read ThermalMeter from EEPROM */
-               if (bLoad_From_EEPOM)
-                       priv->EEPROMThermalMeter = (u8)(eprom_read(dev, (EEPROM_ThermalMeter >> 1)) & 0x00ff);
-               else
+               if (bLoad_From_EEPOM) {
+                       ret = eprom_read(dev, (EEPROM_ThermalMeter >> 1));
+                       if (ret < 0)
+                               return ret;
+                       priv->EEPROMThermalMeter = (u8)((u16)ret & 0x00ff);
+               } else
                        priv->EEPROMThermalMeter = EEPROM_Default_ThermalMeter;
                RT_TRACE(COMP_EPROM, "ThermalMeter:%d\n", priv->EEPROMThermalMeter);
                /* for tx power track */
                priv->TSSI_13dBm = priv->EEPROMThermalMeter * 100;
                /* read antenna tx power offset of B/C/D to A from EEPROM */
-               if (bLoad_From_EEPOM)
-                       priv->EEPROMPwDiff = (eprom_read(dev, (EEPROM_PwDiff >> 1)) & 0x0f00) >> 8;
-               else
+               if (bLoad_From_EEPOM) {
+                       ret = eprom_read(dev, (EEPROM_PwDiff >> 1));
+                       if (ret < 0)
+                               return ret;
+                       priv->EEPROMPwDiff = ((u16)ret & 0x0f00) >> 8;
+               } else
                        priv->EEPROMPwDiff = EEPROM_Default_PwDiff;
                RT_TRACE(COMP_EPROM, "TxPwDiff:%d\n", priv->EEPROMPwDiff);
                /* Read CrystalCap from EEPROM */
-               if (bLoad_From_EEPOM)
-                       priv->EEPROMCrystalCap = (eprom_read(dev, (EEPROM_CrystalCap >> 1)) & 0x0f);
-               else
+               if (bLoad_From_EEPOM) {
+                       ret = eprom_read(dev, (EEPROM_CrystalCap >> 1));
+                       if (ret < 0)
+                               return ret;
+                       priv->EEPROMCrystalCap = (u16)ret & 0x0f;
+               } else
                        priv->EEPROMCrystalCap = EEPROM_Default_CrystalCap;
                RT_TRACE(COMP_EPROM, "CrystalCap = %d\n", priv->EEPROMCrystalCap);
                /* get per-channel Tx power level */
-               if (bLoad_From_EEPOM)
-                       priv->EEPROM_Def_Ver = (eprom_read(dev, (EEPROM_TxPwIndex_Ver >> 1)) & 0xff00) >> 8;
-               else
+               if (bLoad_From_EEPOM) {
+                       ret = eprom_read(dev, (EEPROM_TxPwIndex_Ver >> 1));
+                       if (ret < 0)
+                               return ret;
+                       priv->EEPROM_Def_Ver = ((u16)ret & 0xff00) >> 8;
+               } else
                        priv->EEPROM_Def_Ver = 1;
                RT_TRACE(COMP_EPROM, "EEPROM_DEF_VER:%d\n", priv->EEPROM_Def_Ver);
                if (priv->EEPROM_Def_Ver == 0) { /* old eeprom definition */
                        int i;
 
-                       if (bLoad_From_EEPOM)
-                               priv->EEPROMTxPowerLevelCCK = (eprom_read(dev, (EEPROM_TxPwIndex_CCK >> 1)) & 0xff) >> 8;
-                       else
+                       if (bLoad_From_EEPOM) {
+                               ret = eprom_read(dev, (EEPROM_TxPwIndex_CCK >> 1));
+                               if (ret < 0)
+                                       return ret;
+                               priv->EEPROMTxPowerLevelCCK = ((u16)ret & 0xff) >> 8;
+                       } else
                                priv->EEPROMTxPowerLevelCCK = 0x10;
                        RT_TRACE(COMP_EPROM, "CCK Tx Power Levl: 0x%02x\n", priv->EEPROMTxPowerLevelCCK);
                        for (i = 0; i < 3; i++) {
                                if (bLoad_From_EEPOM) {
-                                       tmpValue = eprom_read(dev, (EEPROM_TxPwIndex_OFDM_24G + i) >> 1);
+                                       ret = eprom_read(dev, (EEPROM_TxPwIndex_OFDM_24G + i) >> 1);
+                                       if ( ret < 0)
+                                               return ret;
                                        if (((EEPROM_TxPwIndex_OFDM_24G + i) % 2) == 0)
-                                               tmpValue = tmpValue & 0x00ff;
+                                               tmpValue = (u16)ret & 0x00ff;
                                        else
-                                               tmpValue = (tmpValue & 0xff00) >> 8;
+                                               tmpValue = ((u16)ret & 0xff00) >> 8;
                                } else {
                                        tmpValue = 0x10;
                                }
@@ -2547,17 +2586,21 @@ static void rtl8192_read_eeprom_info(struct net_device *dev)
                        }
                } else if (priv->EEPROM_Def_Ver == 1) {
                        if (bLoad_From_EEPOM) {
-                               tmpValue = eprom_read(dev,
-                                               EEPROM_TxPwIndex_CCK_V1 >> 1);
-                               tmpValue = (tmpValue & 0xff00) >> 8;
+                               ret = eprom_read(dev, EEPROM_TxPwIndex_CCK_V1 >> 1);
+                               if (ret < 0)
+                                       return ret;
+                               tmpValue = ((u16)ret & 0xff00) >> 8;
                        } else {
                                tmpValue = 0x10;
                        }
                        priv->EEPROMTxPowerLevelCCK_V1[0] = (u8)tmpValue;
 
-                       if (bLoad_From_EEPOM)
-                               tmpValue = eprom_read(dev, (EEPROM_TxPwIndex_CCK_V1 + 2) >> 1);
-                       else
+                       if (bLoad_From_EEPOM) {
+                               ret = eprom_read(dev, (EEPROM_TxPwIndex_CCK_V1 + 2) >> 1);
+                               if (ret < 0)
+                                       return ret;
+                               tmpValue = (u16)ret;
+                       } else
                                tmpValue = 0x1010;
                        *((u16 *)(&priv->EEPROMTxPowerLevelCCK_V1[1])) = tmpValue;
                        if (bLoad_From_EEPOM)
@@ -2627,7 +2670,6 @@ static void rtl8192_read_eeprom_info(struct net_device *dev)
        default:
                priv->CustomerID = RT_CID_DEFAULT;
                break;
-
        }
 
        switch (priv->CustomerID) {
@@ -2642,7 +2684,6 @@ static void rtl8192_read_eeprom_info(struct net_device *dev)
        default:
                priv->LedStrategy = SW_LED_MODE0;
                break;
-
        }
 
 
@@ -2657,6 +2698,8 @@ static void rtl8192_read_eeprom_info(struct net_device *dev)
        init_rate_adaptive(dev);
 
        RT_TRACE(COMP_EPROM, "<===========%s()\n", __func__);
+
+       return 0;
 }
 
 static short rtl8192_get_channel_map(struct net_device *dev)
@@ -2676,8 +2719,8 @@ static short rtl8192_get_channel_map(struct net_device *dev)
 
 static short rtl8192_init(struct net_device *dev)
 {
-
        struct r8192_priv *priv = ieee80211_priv(dev);
+       int err;
 
        memset(&(priv->stats), 0, sizeof(struct Stats));
        memset(priv->txqueue_to_outpipemap, 0, 9);
@@ -2699,7 +2742,14 @@ static short rtl8192_init(struct net_device *dev)
        rtl8192_init_priv_lock(priv);
        rtl8192_init_priv_task(dev);
        rtl8192_get_eeprom_size(dev);
-       rtl8192_read_eeprom_info(dev);
+       err = rtl8192_read_eeprom_info(dev);
+       if (err) {
+               DMESG("Reading EEPROM info failed");
+               kfree(priv->pFirmware);
+               priv->pFirmware = NULL;
+               free_ieee80211(dev);
+               return err;
+       }
        rtl8192_get_channel_map(dev);
        init_hal_dm(dev);
        setup_timer(&priv->watch_dog_timer, watch_dog_timer_callback,
@@ -2797,8 +2847,6 @@ static void rtl8192_hwconfig(struct net_device *dev)
        /* Set Tx Antenna including Feedback control */
 
        /* Set Auto Rate fallback control */
-
-
 }
 
 
@@ -3027,7 +3075,6 @@ static bool rtl8192_adapter_start(struct net_device *dev)
                                                     bMaskByte2);
 
                        for (i = 0; i < CCKTxBBGainTableLength; i++) {
-
                                if (TempCCk == priv->cck_txbbgain_table[i].ccktxbb_valuearray[0]) {
                                        priv->cck_present_attentuation_20Mdefault = (u8)i;
                                        break;
@@ -3037,7 +3084,6 @@ static bool rtl8192_adapter_start(struct net_device *dev)
                        priv->cck_present_attentuation_difference = 0;
                        priv->cck_present_attentuation =
                                priv->cck_present_attentuation_20Mdefault;
-
                }
        }
        write_nic_byte(dev, 0x87, 0x0);
@@ -3222,7 +3268,6 @@ static RESET_TYPE rtl819x_ifcheck_resetornot(struct net_device *dev)
        } else {
                return RESET_TYPE_NORESET;
        }
-
 }
 
 static void rtl8192_cancel_deferred_work(struct r8192_priv *priv);
@@ -3250,7 +3295,6 @@ static void CamRestoreAllEntry(struct net_device *dev)
 
        if ((priv->ieee80211->pairwise_key_type == KEY_TYPE_WEP40) ||
            (priv->ieee80211->pairwise_key_type == KEY_TYPE_WEP104)) {
-
                for (EntryId = 0; EntryId < 4; EntryId++) {
                        MacAddr = CAM_CONST_ADDR[EntryId];
                        setKey(dev, EntryId, EntryId,
@@ -3259,7 +3303,6 @@ static void CamRestoreAllEntry(struct net_device *dev)
                }
 
        } else if (priv->ieee80211->pairwise_key_type == KEY_TYPE_TKIP) {
-
                if (priv->ieee80211->iw_mode == IW_MODE_ADHOC)
                        setKey(dev, 4, 0, priv->ieee80211->pairwise_key_type,
                               (u8 *)dev->dev_addr, 0, NULL);
@@ -3267,7 +3310,6 @@ static void CamRestoreAllEntry(struct net_device *dev)
                        setKey(dev, 4, 0, priv->ieee80211->pairwise_key_type,
                               MacAddr, 0, NULL);
        } else if (priv->ieee80211->pairwise_key_type == KEY_TYPE_CCMP) {
-
                if (priv->ieee80211->iw_mode == IW_MODE_ADHOC)
                        setKey(dev, 4, 0, priv->ieee80211->pairwise_key_type,
                               (u8 *)dev->dev_addr, 0, NULL);
@@ -3301,6 +3343,7 @@ static void CamRestoreAllEntry(struct net_device *dev)
                               CAM_CONST_ADDR[0], 0, NULL);
        }
 }
+
 /* This function is used to fix Tx/Rx stop bug temporarily.
  * This function will do "system reset" to NIC when Tx or Rx is stuck.
  * The method checking Tx/Rx stuck of this function is supported by FW,
@@ -3324,12 +3367,12 @@ RESET_START:
 
                /* Set the variable for reset. */
                priv->ResetProgress = RESET_TYPE_SILENT;
-               down(&priv->wx_sem);
+               mutex_lock(&priv->wx_mutex);
                if (priv->up == 0) {
                        RT_TRACE(COMP_ERR,
                                 "%s():the driver is not up! return\n",
                                 __func__);
-                       up(&priv->wx_sem);
+                       mutex_unlock(&priv->wx_mutex);
                        return;
                }
                priv->up = 0;
@@ -3344,19 +3387,19 @@ RESET_START:
 
                ieee->sync_scan_hurryup = 1;
                if (ieee->state == IEEE80211_LINKED) {
-                       down(&ieee->wx_sem);
+                       mutex_lock(&ieee->wx_mutex);
                        netdev_dbg(dev, "ieee->state is IEEE80211_LINKED\n");
                        ieee80211_stop_send_beacons(priv->ieee80211);
                        del_timer_sync(&ieee->associate_timer);
                        cancel_delayed_work(&ieee->associate_retry_wq);
                        ieee80211_stop_scan(ieee);
                        netif_carrier_off(dev);
-                       up(&ieee->wx_sem);
+                       mutex_unlock(&ieee->wx_mutex);
                } else {
                        netdev_dbg(dev, "ieee->state is NOT LINKED\n");
                        ieee80211_softmac_stop_protocol(priv->ieee80211);
                }
-               up(&priv->wx_sem);
+               mutex_unlock(&priv->wx_mutex);
                RT_TRACE(COMP_RESET,
                         "%s():<==========down process is finished\n",
                         __func__);
@@ -3468,7 +3511,6 @@ static void rtl819x_watchdog_wqcallback(struct work_struct *work)
        /* for AP roaming */
        if (priv->ieee80211->state == IEEE80211_LINKED &&
            priv->ieee80211->iw_mode == IW_MODE_INFRA) {
-
                rtl819x_update_rxcounts(priv, &TotalRxBcnNum, &TotalRxDataNum);
                if ((TotalRxBcnNum + TotalRxDataNum) == 0) {
 #ifdef TODO
@@ -3485,7 +3527,6 @@ static void rtl819x_watchdog_wqcallback(struct work_struct *work)
                        priv->ieee80211->link_change(dev);
                        queue_work(priv->ieee80211->wq,
                                   &priv->ieee80211->associate_procedure_wq);
-
                }
        }
        priv->ieee80211->LinkDetectInfo.NumRecvBcnInPeriod = 0;
@@ -3510,7 +3551,6 @@ static void rtl819x_watchdog_wqcallback(struct work_struct *work)
        priv->bForcedSilentReset = false;
        priv->bResetInProgress = false;
        RT_TRACE(COMP_TRACE, " <==RtUsbCheckForHangWorkItemCallback()\n");
-
 }
 
 static void watch_dog_timer_callback(unsigned long data)
@@ -3521,6 +3561,7 @@ static void watch_dog_timer_callback(unsigned long data)
        mod_timer(&priv->watch_dog_timer,
                  jiffies + msecs_to_jiffies(IEEE80211_WATCH_DOG_TIME));
 }
+
 static int _rtl8192_up(struct net_device *dev)
 {
        struct r8192_priv *priv = ieee80211_priv(dev);
@@ -3556,11 +3597,10 @@ static int rtl8192_open(struct net_device *dev)
        struct r8192_priv *priv = ieee80211_priv(dev);
        int ret;
 
-       down(&priv->wx_sem);
+       mutex_lock(&priv->wx_mutex);
        ret = rtl8192_up(dev);
-       up(&priv->wx_sem);
+       mutex_unlock(&priv->wx_mutex);
        return ret;
-
 }
 
 
@@ -3580,14 +3620,13 @@ static int rtl8192_close(struct net_device *dev)
        struct r8192_priv *priv = ieee80211_priv(dev);
        int ret;
 
-       down(&priv->wx_sem);
+       mutex_lock(&priv->wx_mutex);
 
        ret = rtl8192_down(dev);
 
-       up(&priv->wx_sem);
+       mutex_unlock(&priv->wx_mutex);
 
        return ret;
-
 }
 
 int rtl8192_down(struct net_device *dev)
@@ -3649,7 +3688,6 @@ void rtl8192_commit(struct net_device *dev)
 
        rtl8192_rtx_disable(dev);
        reset_status = _rtl8192_up(dev);
-
 }
 
 static void rtl8192_restart(struct work_struct *work)
@@ -3658,11 +3696,11 @@ static void rtl8192_restart(struct work_struct *work)
                                               reset_wq);
        struct net_device *dev = priv->ieee80211->dev;
 
-       down(&priv->wx_sem);
+       mutex_lock(&priv->wx_mutex);
 
        rtl8192_commit(dev);
 
-       up(&priv->wx_sem);
+       mutex_unlock(&priv->wx_mutex);
 }
 
 static void r8192_set_multicast(struct net_device *dev)
@@ -3685,12 +3723,12 @@ static int r8192_set_mac_adr(struct net_device *dev, void *mac)
        struct r8192_priv *priv = ieee80211_priv(dev);
        struct sockaddr *addr = mac;
 
-       down(&priv->wx_sem);
+       mutex_lock(&priv->wx_mutex);
 
        ether_addr_copy(dev->dev_addr, addr->sa_data);
 
        schedule_work(&priv->reset_wq);
-       up(&priv->wx_sem);
+       mutex_unlock(&priv->wx_mutex);
 
        return 0;
 }
@@ -3707,7 +3745,7 @@ static int rtl8192_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
        struct iw_point *p = &wrq->u.data;
        struct ieee_param *ipw = NULL;
 
-       down(&priv->wx_sem);
+       mutex_lock(&priv->wx_mutex);
 
 
        if (p->length < sizeof(struct ieee_param) || !p->pointer) {
@@ -3800,7 +3838,7 @@ static int rtl8192_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
        kfree(ipw);
        ipw = NULL;
 out:
-       up(&priv->wx_sem);
+       mutex_unlock(&priv->wx_mutex);
        return ret;
 }
 
@@ -4111,7 +4149,6 @@ static void rtl8192_process_phyinfo(struct r8192_priv *priv, u8 *buffer,
                                (((priv->undecorated_smoothed_pwdb) * (Rx_Smooth_Factor - 1)) +
                                 (pprevious_stats->RxPWDBAll)) / (Rx_Smooth_Factor);
                }
-
        }
 
        /* Check EVM */
@@ -4159,8 +4196,6 @@ static void rtl8192_process_phyinfo(struct r8192_priv *priv, u8 *buffer,
                        }
                }
        }
-
-
 }
 
 /*-----------------------------------------------------------------------------
@@ -4201,6 +4236,7 @@ static u8 rtl819x_evm_dbtopercentage(char value)
                ret_val = 100;
        return ret_val;
 }
+
 /* We want good-looking for signal strength/quality */
 static long rtl819x_signal_scale_mapping(long currsig)
 {
@@ -4542,7 +4578,6 @@ static void TranslateRxSignalStuff819xUsb(struct sk_buff *skb,
                                  bpacket_match_bssid, bpacket_toself,
                                  bPacketBeacon, bToSelfBA);
        rtl8192_record_rxdesc_forlateruse(pstats, &previous_stats);
-
 }
 
 /**
@@ -4758,7 +4793,6 @@ static void query_rxdesc_status(struct sk_buff *skb,
                        RT_TRACE(COMP_RXDESC,
                                "driver_info->FirstAGGR = %d, driver_info->PartAggr = %d\n",
                                 driver_info->FirstAGGR, driver_info->PartAggr);
-
        }
 
        skb_pull(skb, sizeof(rx_desc_819x_usb));
@@ -4822,7 +4856,6 @@ static void rtl8192_rx_nomal(struct sk_buff *skb)
                netdev_dbg(dev, "actual_length: %d\n", skb->len);
                dev_kfree_skb_any(skb);
        }
-
 }
 
 static void rtl819xusb_process_received_packet(
@@ -4898,7 +4931,6 @@ static void rtl8192_rx_cmd(struct sk_buff *skb)
        };
 
        if ((skb->len >= (20 + sizeof(rx_desc_819x_usb))) && (skb->len < RX_URB_SIZE)) {
-
                query_rx_cmdpkt_desc_status(skb, &stats);
                /* prfd->queue_id = 1; */
 
@@ -4937,7 +4969,6 @@ static void rtl8192_irq_rx_tasklet(struct r8192_priv *priv)
                                 info->out_pipe);
                        dev_kfree_skb(skb);
                        break;
-
                }
        }
 }
@@ -4971,7 +5002,7 @@ static int rtl8192_usb_probe(struct usb_interface *intf,
        RT_TRACE(COMP_INIT, "Oops: i'm coming\n");
 
        dev = alloc_ieee80211(sizeof(struct r8192_priv));
-       if (dev == NULL)
+       if (!dev)
                return -ENOMEM;
 
        usb_set_intfdata(intf, dev);
@@ -5034,7 +5065,6 @@ fail:
  */
 static void rtl8192_cancel_deferred_work(struct r8192_priv *priv)
 {
-
        cancel_work_sync(&priv->reset_wq);
        cancel_delayed_work(&priv->watch_dog_wq);
        cancel_delayed_work(&priv->update_beacon_wq);
@@ -5191,13 +5221,12 @@ void setKey(struct net_device *dev, u8 EntryNo, u8 KeyIndex, u16 KeyType,
                        write_nic_dword(dev, RWCAM, TargetCommand);
                } else {
                        /* Key Material */
-                       if (KeyContent != NULL) {
+                       if (KeyContent) {
                                write_nic_dword(dev, WCAMI, (u32)(*(KeyContent + i - 2)));
                                write_nic_dword(dev, RWCAM, TargetCommand);
                        }
                }
        }
-
 }
 
 /***************************************************************************