linux/drivers/staging/rtl8188eu/os_dep/osdep_service.c
<<
>>
Prefs
   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
  16u8 *_rtw_malloc(u32 sz)
  17{
  18        return kmalloc(sz, in_interrupt() ? GFP_ATOMIC : GFP_KERNEL);
  19}
  20
  21void _rtw_init_queue(struct __queue *pqueue)
  22{
  23        INIT_LIST_HEAD(&pqueue->queue);
  24        spin_lock_init(&pqueue->lock);
  25}
  26
  27void rtw_buf_free(u8 **buf, u32 *buf_len)
  28{
  29        *buf_len = 0;
  30        kfree(*buf);
  31        *buf = NULL;
  32}
  33
  34void rtw_buf_update(u8 **buf, u32 *buf_len, u8 *src, u32 src_len)
  35{
  36        u32 dup_len = 0;
  37        u8 *ori = NULL;
  38        u8 *dup = NULL;
  39
  40        if (!buf || !buf_len)
  41                return;
  42
  43        if (!src || !src_len)
  44                goto keep_ori;
  45
  46        /* duplicate src */
  47        dup = rtw_malloc(src_len);
  48        if (dup) {
  49                dup_len = src_len;
  50                memcpy(dup, src, dup_len);
  51        }
  52
  53keep_ori:
  54        ori = *buf;
  55
  56        /* replace buf with dup */
  57        *buf_len = 0;
  58        *buf = dup;
  59        *buf_len = dup_len;
  60
  61        /* free ori */
  62        kfree(ori);
  63}
  64