eal: introduce I/O device memory barriers
[dpdk.git] / lib / librte_eal / common / eal_common_memzone.c
index 452679e..64f4e0a 100644 (file)
@@ -119,6 +119,9 @@ find_heap_max_free_elem(int *s, unsigned align)
                }
        }
 
+       if (len < MALLOC_ELEM_OVERHEAD + align)
+               return 0;
+
        return len - MALLOC_ELEM_OVERHEAD - align;
 }
 
@@ -141,16 +144,16 @@ memzone_reserve_aligned_thread_unsafe(const char *name, size_t len,
                return NULL;
        }
 
-       /* zone already exist */
-       if ((memzone_lookup_thread_unsafe(name)) != NULL) {
-               RTE_LOG(DEBUG, EAL, "%s(): memzone <%s> already exists\n",
+       if (strlen(name) > sizeof(mz->name) - 1) {
+               RTE_LOG(DEBUG, EAL, "%s(): memzone <%s>: name too long\n",
                        __func__, name);
-               rte_errno = EEXIST;
+               rte_errno = ENAMETOOLONG;
                return NULL;
        }
 
-       if (strlen(name) >= sizeof(mz->name) - 1) {
-               RTE_LOG(DEBUG, EAL, "%s(): memzone <%s>: name too long\n",
+       /* zone already exist */
+       if ((memzone_lookup_thread_unsafe(name)) != NULL) {
+               RTE_LOG(DEBUG, EAL, "%s(): memzone <%s> already exists\n",
                        __func__, name);
                rte_errno = EEXIST;
                return NULL;
@@ -197,8 +200,13 @@ memzone_reserve_aligned_thread_unsafe(const char *name, size_t len,
        if (len == 0) {
                if (bound != 0)
                        requested_len = bound;
-               else
+               else {
                        requested_len = find_heap_max_free_elem(&socket_id, align);
+                       if (requested_len == 0) {
+                               rte_errno = ENOMEM;
+                               return NULL;
+                       }
+               }
        }
 
        if (socket_id == SOCKET_ID_ANY)
@@ -329,19 +337,7 @@ rte_memzone_free(const struct rte_memzone *mz)
        idx = ((uintptr_t)mz - (uintptr_t)mcfg->memzone);
        idx = idx / sizeof(struct rte_memzone);
 
-#ifdef RTE_LIBRTE_IVSHMEM
-       /*
-        * If ioremap_addr is set, it's an IVSHMEM memzone and we cannot
-        * free it.
-        */
-       if (mcfg->memzone[idx].ioremap_addr != 0) {
-               rte_rwlock_write_unlock(&mcfg->mlock);
-               return -EINVAL;
-       }
-#endif
-
        addr = mcfg->memzone[idx].addr;
-
        if (addr == NULL)
                ret = -EINVAL;
        else if (mcfg->memzone_cnt == 0) {