* Internal helper to allocate memory once for several disparate objects. * * The most restrictive alignment constraint for standard objects is assumed * to be sizeof(double) and is used as a default value. * * C11 code would include stdalign.h and use alignof(max_align_t) however * we'll stick with C99 for the time being. */
| 50 | * we'll stick with C99 for the time being. |
| 51 | */ |
| 52 | static inline size_t |
| 53 | mlx4_mallocv_inline(const char *type, const struct mlx4_malloc_vec *vec, |
| 54 | unsigned int cnt, int zero, int socket) |
| 55 | { |
| 56 | unsigned int i; |
| 57 | size_t size; |
| 58 | size_t least; |
| 59 | uint8_t *data = NULL; |
| 60 | int fill = !vec[0].addr; |
| 61 | |
| 62 | fill: |
| 63 | size = 0; |
| 64 | least = 0; |
| 65 | for (i = 0; i < cnt; ++i) { |
| 66 | size_t align = (uintptr_t)vec[i].align; |
| 67 | |
| 68 | if (!align) { |
| 69 | align = sizeof(double); |
| 70 | } else if (!rte_is_power_of_2(align)) { |
| 71 | rte_errno = EINVAL; |
| 72 | goto error; |
| 73 | } |
| 74 | if (least < align) |
| 75 | least = align; |
| 76 | align = RTE_ALIGN_CEIL(size, align); |
| 77 | size = align + vec[i].size; |
| 78 | if (fill && vec[i].addr) |
| 79 | *vec[i].addr = data + align; |
| 80 | } |
| 81 | if (fill) |
| 82 | return size; |
| 83 | if (!zero) |
| 84 | data = rte_malloc_socket(type, size, least, socket); |
| 85 | else |
| 86 | data = rte_zmalloc_socket(type, size, least, socket); |
| 87 | if (data) { |
| 88 | fill = 1; |
| 89 | goto fill; |
| 90 | } |
| 91 | rte_errno = ENOMEM; |
| 92 | error: |
| 93 | for (i = 0; i != cnt; ++i) |
| 94 | if (vec[i].addr) |
| 95 | *vec[i].addr = NULL; |
| 96 | return 0; |
| 97 | } |
| 98 | |
| 99 | /** |
| 100 | * Allocate memory once for several disparate objects. |
no test coverage detected