root/drivers/staging/rtl8188eu/os_dep/osdep_service.c

/* [<][>][^][v][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. _rtw_malloc
  2. _rtw_init_queue
  3. rtw_alloc_etherdev_with_old_priv
  4. rtw_free_netdev
  5. rtw_buf_free
  6. rtw_buf_update

   1 // SPDX-License-Identifier: GPL-2.0
   2 /******************************************************************************
   3  *
   4  * Copyright(c) 2007 - 2012 Realtek Corporation. All rights reserved.
   5  *
   6  ******************************************************************************/
   7 #define _OSDEP_SERVICE_C_
   8 
   9 #include <osdep_service.h>
  10 #include <osdep_intf.h>
  11 #include <drv_types.h>
  12 #include <recv_osdep.h>
  13 #include <linux/vmalloc.h>
  14 #include <rtw_ioctl_set.h>
  15 
  16 u8 *_rtw_malloc(u32 sz)
  17 {
  18         return kmalloc(sz, in_interrupt() ? GFP_ATOMIC : GFP_KERNEL);
  19 }
  20 
  21 void _rtw_init_queue(struct __queue *pqueue)
  22 {
  23         INIT_LIST_HEAD(&pqueue->queue);
  24         spin_lock_init(&pqueue->lock);
  25 }
  26 
  27 struct net_device *rtw_alloc_etherdev_with_old_priv(void *old_priv)
  28 {
  29         struct net_device *pnetdev;
  30         struct rtw_netdev_priv_indicator *pnpi;
  31 
  32         pnetdev = alloc_etherdev_mq(sizeof(struct rtw_netdev_priv_indicator), 4);
  33         if (!pnetdev)
  34                 goto RETURN;
  35 
  36         pnpi = netdev_priv(pnetdev);
  37         pnpi->priv = old_priv;
  38 
  39 RETURN:
  40         return pnetdev;
  41 }
  42 
  43 void rtw_free_netdev(struct net_device *netdev)
  44 {
  45         struct rtw_netdev_priv_indicator *pnpi;
  46 
  47         if (!netdev)
  48                 goto RETURN;
  49 
  50         pnpi = netdev_priv(netdev);
  51 
  52         if (!pnpi->priv)
  53                 goto RETURN;
  54 
  55         vfree(pnpi->priv);
  56         free_netdev(netdev);
  57 
  58 RETURN:
  59         return;
  60 }
  61 
  62 void rtw_buf_free(u8 **buf, u32 *buf_len)
  63 {
  64         *buf_len = 0;
  65         kfree(*buf);
  66         *buf = NULL;
  67 }
  68 
  69 void rtw_buf_update(u8 **buf, u32 *buf_len, u8 *src, u32 src_len)
  70 {
  71         u32 dup_len = 0;
  72         u8 *ori = NULL;
  73         u8 *dup = NULL;
  74 
  75         if (!buf || !buf_len)
  76                 return;
  77 
  78         if (!src || !src_len)
  79                 goto keep_ori;
  80 
  81         /* duplicate src */
  82         dup = rtw_malloc(src_len);
  83         if (dup) {
  84                 dup_len = src_len;
  85                 memcpy(dup, src, dup_len);
  86         }
  87 
  88 keep_ori:
  89         ori = *buf;
  90 
  91         /* replace buf with dup */
  92         *buf_len = 0;
  93         *buf = dup;
  94         *buf_len = dup_len;
  95 
  96         /* free ori */
  97         kfree(ori);
  98 }

/* [<][>][^][v][top][bottom][index][help] */