MCPcopy Create free account
hub / github.com/F-Stack/f-stack / template_alloc

Function template_alloc

dpdk/app/test-pmd/config.c:1610–1651  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1608}
1609
1610static int
1611template_alloc(uint32_t id, struct port_template **template,
1612 struct port_template **list)
1613{
1614 struct port_template *lst = *list;
1615 struct port_template **ppt;
1616 struct port_template *pt = NULL;
1617
1618 *template = NULL;
1619 if (id == UINT32_MAX) {
1620 /* taking first available ID */
1621 if (lst) {
1622 if (lst->id == UINT32_MAX - 1) {
1623 printf("Highest template ID is already"
1624 " assigned, delete it first\n");
1625 return -ENOMEM;
1626 }
1627 id = lst->id + 1;
1628 } else {
1629 id = 0;
1630 }
1631 }
1632 pt = calloc(1, sizeof(*pt));
1633 if (!pt) {
1634 printf("Allocation of port template failed\n");
1635 return -ENOMEM;
1636 }
1637 ppt = list;
1638 while (*ppt && (*ppt)->id > id)
1639 ppt = &(*ppt)->next;
1640 if (*ppt && (*ppt)->id == id) {
1641 printf("Template #%u is already assigned,"
1642 " delete it first\n", id);
1643 free(pt);
1644 return -EINVAL;
1645 }
1646 pt->next = *ppt;
1647 pt->id = id;
1648 *ppt = pt;
1649 *template = pt;
1650 return 0;
1651}
1652
1653static int
1654table_alloc(uint32_t id, struct port_table **table,

Calls 3

callocFunction · 0.85
printfFunction · 0.50
freeFunction · 0.50

Tested by

no test coverage detected