On 2/9/2023 6:36 AM, Chengwen Feng wrote:
The memarea library is an allocator of variable-size object which based
on a memory region.

This patch provides rte_memarea_create() and rte_memarea_destroy() API.

Signed-off-by: Chengwen Feng <fengcheng...@huawei.com>
Reviewed-by: Dongdong Liu <liudongdo...@huawei.com>
Acked-by: Morten Brørup <m...@smartsharesystems.com>
---


+static int
+memarea_check_param(const struct rte_memarea_param *init)
+{
+#define MEMAREA_MIN_SIZE       1024
+       size_t len;
+
+       if (init == NULL) {
+               RTE_MEMAREA_LOG(ERR, "init param is NULL!");
+               return -EINVAL;
+       }
+
+       len = strnlen(init->name, RTE_MEMAREA_NAMESIZE);
+       if (len == 0 || len >= RTE_MEMAREA_NAMESIZE) {
+               RTE_MEMAREA_LOG(ERR, "name size: %zu invalid!", len);
+               return -EINVAL;
+       }
+
+       if (init->source != RTE_MEMAREA_SOURCE_HEAP &&
+           init->source != RTE_MEMAREA_SOURCE_LIBC &&
+           init->source != RTE_MEMAREA_SOURCE_MEMAREA) {
+               RTE_MEMAREA_LOG(ERR, "%s source: %d not supported!",
+                       init->name, init->source);
+               return -EINVAL;
+       }
+
+       if (init->total_sz < MEMAREA_MIN_SIZE) {
+               RTE_MEMAREA_LOG(ERR, "%s total-size: %zu too small!",
+                       init->name, init->total_sz);
+               return -EINVAL;
+       }
+
+       if (init->source == RTE_MEMAREA_SOURCE_MEMAREA && init->src_ma == NULL) 
{
+               RTE_MEMAREA_LOG(ERR, "%s source memarea is NULL!", init->name);
+               return -EINVAL;
+       }
+
+       if (init->alg != RTE_MEMAREA_ALGORITHM_NEXTFIT) {
+               RTE_MEMAREA_LOG(ERR, "%s algorithm: %d not supported!",
+                       init->name, init->alg);
+               return -EINVAL;
+       }

Also, you're returning a lot of `errno` type values from this function, but you do not appear to use these values anywhere. I think it'd be better if you used the return value to set `rte_errno` to indicate what kind of error there was. The entire API could benefit from doing a pass on setting rte_errno in error cases, and documenting them.

--
Thanks,
Anatoly

Reply via email to