staging: wilc1000: remove pointless kfree wrapper
[cascardo/linux.git] / drivers / staging / wilc1000 / wilc_wlan.c
index 7c53a2b..95897bf 100644 (file)
@@ -188,6 +188,7 @@ static struct txq_entry_t *wilc_wlan_txq_remove_from_head(void)
        struct txq_entry_t *tqe;
        wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
        unsigned long flags;
+
        p->os_func.os_spin_lock(p->txq_spinlock, &flags);
        if (p->txq_head) {
                tqe = p->txq_head;
@@ -368,6 +369,7 @@ static __inline int remove_TCP_related(void)
 {
        wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
        unsigned long flags;
+
        p->os_func.os_spin_lock(p->txq_spinlock, &flags);
 
        p->os_func.os_spin_unlock(p->txq_spinlock, &flags);
@@ -383,6 +385,7 @@ static __inline int tcp_process(struct txq_entry_t *tqe)
        int i;
        wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
        unsigned long flags;
+
        p->os_func.os_spin_lock(p->txq_spinlock, &flags);
 
        eth_hdr_ptr = &buffer[0];
@@ -398,12 +401,14 @@ static __inline int tcp_process(struct txq_entry_t *tqe)
                if (protocol == 0x06) {
                        uint8_t *tcp_hdr_ptr;
                        uint32_t IHL, Total_Length, Data_offset;
+
                        tcp_hdr_ptr = &ip_hdr_ptr[IP_HDR_LEN];
                        IHL = (ip_hdr_ptr[0] & 0xf) << 2;
                        Total_Length = (((uint32_t)ip_hdr_ptr[2]) << 8) + ((uint32_t)ip_hdr_ptr[3]);
                        Data_offset = (((uint32_t)tcp_hdr_ptr[12] & 0xf0) >> 2);
                        if (Total_Length == (IHL + Data_offset)) { /*we want to recognize the clear Acks(packet only carry Ack infos not with data) so data size must be equal zero*/
                                uint32_t seq_no, Ack_no;
+
                                seq_no  = (((uint32_t)tcp_hdr_ptr[4]) << 24) + (((uint32_t)tcp_hdr_ptr[5]) << 16) + (((uint32_t)tcp_hdr_ptr[6]) << 8) + ((uint32_t)tcp_hdr_ptr[7]);
 
                                Ack_no  = (((uint32_t)tcp_hdr_ptr[8]) << 24) + (((uint32_t)tcp_hdr_ptr[9]) << 16) + (((uint32_t)tcp_hdr_ptr[10]) << 8) + ((uint32_t)tcp_hdr_ptr[11]);
@@ -445,6 +450,7 @@ static int wilc_wlan_txq_filter_dup_tcp_ack(void)
        for (i = PendingAcks_arrBase; i < (PendingAcks_arrBase + Pending_Acks); i++) {
                if (Pending_Acks_info[i].ack_num < Acks_keep_track_info[Pending_Acks_info[i].Session_index].Bigger_Ack_num) {
                        struct txq_entry_t *tqe;
+
                        PRINT_D(TCP_ENH, "DROP ACK: %u\n", Pending_Acks_info[i].ack_num);
                        tqe = Pending_Acks_info[i].txqe;
                        if (tqe) {
@@ -453,7 +459,7 @@ static int wilc_wlan_txq_filter_dup_tcp_ack(void)
                                tqe->status = 1;                                /* mark the packet send */
                                if (tqe->tx_complete_func)
                                        tqe->tx_complete_func(tqe->priv, tqe->status);
-                               p->os_func.os_free(tqe);
+                               kfree(tqe);
                                Dropped++;
                        }
                }
@@ -505,7 +511,7 @@ static int wilc_wlan_txq_add_cfg_pkt(uint8_t *buffer, uint32_t buffer_size)
                return 0;
        }
 
-       tqe = (struct txq_entry_t *)p->os_func.os_malloc_atomic(sizeof(struct txq_entry_t));
+       tqe = kmalloc(sizeof(struct txq_entry_t), GFP_ATOMIC);
        if (tqe == NULL) {
                PRINT_ER("Failed to allocate memory\n");
                return 0;
@@ -538,7 +544,7 @@ static int wilc_wlan_txq_add_net_pkt(void *priv, uint8_t *buffer, uint32_t buffe
        if (p->quit)
                return 0;
 
-       tqe = (struct txq_entry_t *)p->os_func.os_malloc_atomic(sizeof(struct txq_entry_t));
+       tqe = kmalloc(sizeof(struct txq_entry_t), GFP_ATOMIC);
 
        if (tqe == NULL)
                return 0;
@@ -571,7 +577,7 @@ int wilc_wlan_txq_add_mgmt_pkt(void *priv, uint8_t *buffer, uint32_t buffer_size
        if (p->quit)
                return 0;
 
-       tqe = (struct txq_entry_t *)p->os_func.os_malloc_atomic(sizeof(struct txq_entry_t));
+       tqe = kmalloc(sizeof(struct txq_entry_t), GFP_KERNEL);
 
        if (tqe == NULL)
                return 0;
@@ -597,7 +603,7 @@ int wilc_FH_wlan_txq_add_net_pkt(void *priv, uint8_t *buffer, uint32_t buffer_si
        if (p->quit)
                return 0;
 
-       tqe = (struct txq_entry_t *)p->os_func.os_malloc_atomic(sizeof(struct txq_entry_t));
+       tqe = kmalloc(sizeof(struct txq_entry_t), GFP_ATOMIC);
 
        if (tqe == NULL)
                return 0;
@@ -778,6 +784,7 @@ INLINE void chip_wakeup(void)
                if (wilc_get_chipid(false) >= 0x1002b0) {
                        /* Enable PALDO back right after wakeup */
                        uint32_t val32;
+
                        g_wlan.hif_func.hif_read_reg(0x1e1c, &val32);
                        val32 |= (1 << 6);
                        g_wlan.hif_func.hif_write_reg(0x1e1c, val32);
@@ -793,6 +800,7 @@ INLINE void chip_wakeup(void)
 INLINE void chip_wakeup(void)
 {
        uint32_t reg, trials = 0;
+
        do {
                if ((g_wlan.io_func.io_type & 0x1) == HIF_SPI) {
                        g_wlan.hif_func.hif_read_reg(1, &reg);
@@ -833,6 +841,7 @@ INLINE void chip_wakeup(void)
                if (wilc_get_chipid(false) >= 0x1002b0) {
                        /* Enable PALDO back right after wakeup */
                        uint32_t val32;
+
                        g_wlan.hif_func.hif_read_reg(0x1e1c, &val32);
                        val32 |= (1 << 6);
                        g_wlan.hif_func.hif_write_reg(0x1e1c, val32);
@@ -885,6 +894,7 @@ static int wilc_wlan_handle_txq(uint32_t *pu32TxqCount)
        int counter;
        int timeout;
        uint32_t vmm_table[WILC_VMM_TBL_SIZE];
+
        p->txq_exit = 0;
        do {
                if (p->quit)
@@ -1125,6 +1135,7 @@ static int wilc_wlan_handle_txq(uint32_t *pu32TxqCount)
                                /* and WILC_DATA_PKT_MAC_HDR*/
                                else if (tqe->type == WILC_NET_PKT) {
                                        char *pBSSID = ((struct tx_complete_data *)(tqe->priv))->pBssid;
+
                                        buffer_offset = ETH_ETHERNET_HDR_OFFSET;
                                        /* copy the bssid at the sart of the buffer */
                                        memcpy(&txb[offset + 4], pBSSID, 6);
@@ -1149,7 +1160,7 @@ static int wilc_wlan_handle_txq(uint32_t *pu32TxqCount)
                                        Pending_Acks_info[tqe->tcp_PendingAck_index].txqe = NULL;
                                }
                                #endif
-                               p->os_func.os_free(tqe);
+                               kfree(tqe);
                        } else {
                                break;
                        }
@@ -1225,6 +1236,7 @@ static void wilc_wlan_handle_rxq(void)
                        uint32_t header;
                        uint32_t pkt_len, pkt_offset, tp_len;
                        int is_cfg_packet;
+
                        PRINT_D(RX_DBG, "In the 2nd do-while\n");
                        memcpy(&header, &buffer[offset], 4);
 #ifdef BIG_ENDIAN
@@ -1309,11 +1321,9 @@ static void wilc_wlan_handle_rxq(void)
 
 
 #ifndef MEMORY_STATIC
-               if (buffer != NULL)
-                       p->os_func.os_free((void *)buffer);
+               kfree(buffer);
 #endif
-               if (rqe != NULL)
-                       p->os_func.os_free((void *)rqe);
+               kfree(rqe);
 
                if (has_packet) {
                        if (p->net_func.rx_complete)
@@ -1402,7 +1412,7 @@ static void wilc_wlan_handle_isr_ext(uint32_t int_status)
                }
 
 #else
-               buffer = p->os_func.os_malloc(size);
+               buffer = kmalloc(size, GFP_KERNEL);
                if (buffer == NULL) {
                        wilc_debug(N_ERR, "[wilc isr]: fail alloc host memory...drop the packets (%d)\n", size);
                        usleep_range(100 * 1000, 100 * 1000);
@@ -1436,7 +1446,7 @@ _end_:
                        /**
                         *      add to rx queue
                         **/
-                       rqe = (struct rxq_entry_t *)p->os_func.os_malloc(sizeof(struct rxq_entry_t));
+                       rqe = kmalloc(sizeof(struct rxq_entry_t), GFP_KERNEL);
                        if (rqe != NULL) {
                                rqe->buffer = buffer;
                                rqe->buffer_size = size;
@@ -1446,8 +1456,7 @@ _end_:
                        }
                } else {
 #ifndef MEMORY_STATIC
-                       if (buffer != NULL)
-                               p->os_func.os_free(buffer);
+                       kfree(buffer);
 #endif
                }
        }
@@ -1505,15 +1514,7 @@ static int wilc_wlan_firmware_download(const uint8_t *buffer, uint32_t buffer_si
        blksz = (1ul << 12); /* Bug 4703: 4KB Good enough size for most platforms = PAGE_SIZE. */
        /* Allocate a DMA coherent  buffer. */
 
-#if (defined WILC_PREALLOC_AT_BOOT)
-       {
-               extern void *get_fw_buffer(void);
-               dma_buffer = (uint8_t *)get_fw_buffer();
-               PRINT_D(TX_DBG, "fw_buffer = 0x%x\n", dma_buffer);
-       }
-#else
-       dma_buffer = (uint8_t *)g_wlan.os_func.os_malloc(blksz);
-#endif
+       dma_buffer = kmalloc(blksz, GFP_KERNEL);
        if (dma_buffer == NULL) {
                /*EIO   5*/
                ret = -5;
@@ -1563,12 +1564,7 @@ static int wilc_wlan_firmware_download(const uint8_t *buffer, uint32_t buffer_si
 
 _fail_:
 
-#if (defined WILC_PREALLOC_AT_BOOT)
-
-#else
-       if (dma_buffer)
-               g_wlan.os_func.os_free(dma_buffer);
-#endif
+       kfree(dma_buffer);
 
 _fail_1:
 
@@ -1705,6 +1701,7 @@ void wilc_wlan_global_reset(void)
 {
 
        wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
+
        acquire_bus(ACQUIRE_AND_WAKEUP);
        p->hif_func.hif_write_reg(WILC_GLB_RESET_0, 0x0);
        release_bus(RELEASE_ONLY);
@@ -1799,7 +1796,7 @@ static void wilc_wlan_cleanup(void)
                        break;
                if (tqe->tx_complete_func)
                        tqe->tx_complete_func(tqe->priv, 0);
-               p->os_func.os_free((void *)tqe);
+               kfree(tqe);
        } while (1);
 
        do {
@@ -1807,29 +1804,20 @@ static void wilc_wlan_cleanup(void)
                if (rqe == NULL)
                        break;
 #ifdef MEMORY_DYNAMIC
-               p->os_func.os_free((void *)tqe->buffer);
+               kfree(tqe->buffer);
 #endif
-               p->os_func.os_free((void *)rqe);
+               kfree(rqe);
        } while (1);
 
        /**
         *      clean up buffer
         **/
 
-#if (defined WILC_PREALLOC_AT_BOOT)
-
-#else
        #ifdef MEMORY_STATIC
-       if (p->rx_buffer) {
-               p->os_func.os_free(p->rx_buffer);
-               p->rx_buffer = NULL;
-       }
+       kfree(p->rx_buffer);
+       p->rx_buffer = NULL;
        #endif
-       if (p->tx_buffer) {
-               p->os_func.os_free(p->tx_buffer);
-               p->tx_buffer = NULL;
-       }
-#endif
+       kfree(p->tx_buffer);
 
        acquire_bus(ACQUIRE_AND_WAKEUP);
 
@@ -2176,21 +2164,8 @@ int wilc_wlan_init(wilc_wlan_inp_t *inp, wilc_wlan_oup_t *oup)
        /**
         *      alloc tx, rx buffer
         **/
-#if (defined WILC_PREALLOC_AT_BOOT)
-       extern void *get_tx_buffer(void);
-       extern void *get_rx_buffer(void);
-
-       PRINT_D(TX_DBG, "malloc before, g_wlan.tx_buffer = 0x%x, g_wlan.rx_buffer = 0x%x\n", g_wlan.tx_buffer, g_wlan.rx_buffer);
-#endif
-
-
-
        if (g_wlan.tx_buffer == NULL)
-#if (defined WILC_PREALLOC_AT_BOOT)
-               g_wlan.tx_buffer = (uint8_t *)get_tx_buffer();
-#else
-               g_wlan.tx_buffer = (uint8_t *)g_wlan.os_func.os_malloc(g_wlan.tx_buffer_size);
-#endif
+               g_wlan.tx_buffer = kmalloc(g_wlan.tx_buffer_size, GFP_KERNEL);
        PRINT_D(TX_DBG, "g_wlan.tx_buffer = %p\n", g_wlan.tx_buffer);
 
        if (g_wlan.tx_buffer == NULL) {
@@ -2203,11 +2178,7 @@ int wilc_wlan_init(wilc_wlan_inp_t *inp, wilc_wlan_oup_t *oup)
 /* rx_buffer is not used unless we activate USE_MEM STATIC which is not applicable, allocating such memory is useless*/
 #if defined (MEMORY_STATIC)
        if (g_wlan.rx_buffer == NULL)
-  #if (defined WILC_PREALLOC_AT_BOOT)
-               g_wlan.rx_buffer = (uint8_t *)get_rx_buffer();
-  #else
-               g_wlan.rx_buffer = (uint8_t *)g_wlan.os_func.os_malloc(g_wlan.rx_buffer_size);
-  #endif
+               g_wlan.rx_buffer = kmalloc(g_wlan.rx_buffer_size, GFP_KERNEL);
        PRINT_D(TX_DBG, "g_wlan.rx_buffer =%p\n", g_wlan.rx_buffer);
        if (g_wlan.rx_buffer == NULL) {
                /* ENOBUFS      105 */
@@ -2259,20 +2230,12 @@ int wilc_wlan_init(wilc_wlan_inp_t *inp, wilc_wlan_oup_t *oup)
 
 _fail_:
 
-#if (defined WILC_PREALLOC_AT_BOOT)
-
-#else
   #ifdef MEMORY_STATIC
-       if (g_wlan.rx_buffer) {
-               g_wlan.os_func.os_free(g_wlan.rx_buffer);
-               g_wlan.rx_buffer = NULL;
-       }
+       kfree(g_wlan.rx_buffer);
+       g_wlan.rx_buffer = NULL;
   #endif
-       if (g_wlan.tx_buffer) {
-               g_wlan.os_func.os_free(g_wlan.tx_buffer);
-               g_wlan.tx_buffer = NULL;
-       }
-#endif
+       kfree(g_wlan.tx_buffer);
+       g_wlan.tx_buffer = NULL;
 
 #if defined(PLAT_RK3026_TCHIP) /* AMR : 0422 RK3026 Crash issue */
        if (!g_wilc_initialized)