| 1608 | } |
| 1609 | |
| 1610 | static int |
| 1611 | template_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 | |
| 1653 | static int |
| 1654 | table_alloc(uint32_t id, struct port_table **table, |
no test coverage detected