• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2020-2021 Huawei Device Co., Ltd.
3  *
4  * HDF is dual licensed: you can use it either under the terms of
5  * the GPL, or the BSD license, at your option.
6  * See the LICENSE file in the root of this repository for complete details.
7  */
8 
9 #include "osal_mem.h"
10 #include <stdlib.h>
11 #include <string.h>
12 #include "securec.h"
13 #include "hdf_log.h"
14 
15 #define HDF_LOG_TAG osal_mem
16 
OsalMemAlloc(size_t size)17 void *OsalMemAlloc(size_t size)
18 {
19     void *buf = NULL;
20 
21     if (size == 0) {
22         HDF_LOGE("%s invalid param", __func__);
23         return NULL;
24     }
25 
26     buf = malloc(size);
27 
28     return buf;
29 }
30 
OsalMemCalloc(size_t size)31 void *OsalMemCalloc(size_t size)
32 {
33     void *buf = NULL;
34 
35     if (size == 0) {
36         HDF_LOGE("%s invalid param", __func__);
37         return NULL;
38     }
39 
40     buf = OsalMemAlloc(size);
41     if (buf != NULL) {
42         (void)memset_s(buf, size, 0, size);
43     }
44 
45     return buf;
46 }
47 
OsalMemAllocAlign(size_t alignment,size_t size)48 void *OsalMemAllocAlign(size_t alignment, size_t size)
49 {
50     void *buf = NULL;
51     int ret;
52 
53     if (size == 0) {
54         HDF_LOGE("%s invalid param", __func__);
55         return NULL;
56     }
57 
58     ret = posix_memalign(&buf, alignment, size);
59     if (ret != 0) {
60         HDF_LOGE("%s memory alloc fail %d", __func__, ret);
61         buf = NULL;
62     }
63 
64     return buf;
65 }
66 
OsalMemFree(void * mem)67 void OsalMemFree(void *mem)
68 {
69     if (mem != NULL) {
70         free(mem);
71     }
72 }
73 
74