| 611 | } |
| 612 | |
| 613 | int |
| 614 | rte_dev_iterator_init(struct rte_dev_iterator *it, |
| 615 | const char *dev_str) |
| 616 | { |
| 617 | struct rte_devargs devargs = { .bus = NULL }; |
| 618 | struct rte_class *cls = NULL; |
| 619 | struct rte_bus *bus = NULL; |
| 620 | |
| 621 | /* Having both bus_str and cls_str NULL is illegal, |
| 622 | * marking this iterator as invalid unless |
| 623 | * everything goes well. |
| 624 | */ |
| 625 | it->bus_str = NULL; |
| 626 | it->cls_str = NULL; |
| 627 | |
| 628 | /* Setting data field implies no malloc in parsing. */ |
| 629 | devargs.data = (void *)(intptr_t)dev_str; |
| 630 | if (rte_devargs_layers_parse(&devargs, dev_str)) |
| 631 | goto get_out; |
| 632 | |
| 633 | bus = devargs.bus; |
| 634 | cls = devargs.cls; |
| 635 | /* The string should have at least |
| 636 | * one layer specified. |
| 637 | */ |
| 638 | if (bus == NULL && cls == NULL) { |
| 639 | RTE_LOG(DEBUG, EAL, "Either bus or class must be specified.\n"); |
| 640 | rte_errno = EINVAL; |
| 641 | goto get_out; |
| 642 | } |
| 643 | if (bus != NULL && bus->dev_iterate == NULL) { |
| 644 | RTE_LOG(DEBUG, EAL, "Bus %s not supported\n", bus->name); |
| 645 | rte_errno = ENOTSUP; |
| 646 | goto get_out; |
| 647 | } |
| 648 | if (cls != NULL && cls->dev_iterate == NULL) { |
| 649 | RTE_LOG(DEBUG, EAL, "Class %s not supported\n", cls->name); |
| 650 | rte_errno = ENOTSUP; |
| 651 | goto get_out; |
| 652 | } |
| 653 | it->bus_str = devargs.bus_str; |
| 654 | it->cls_str = devargs.cls_str; |
| 655 | it->dev_str = dev_str; |
| 656 | it->bus = bus; |
| 657 | it->cls = cls; |
| 658 | it->device = NULL; |
| 659 | it->class_device = NULL; |
| 660 | get_out: |
| 661 | return -rte_errno; |
| 662 | } |
| 663 | |
| 664 | static char * |
| 665 | dev_str_sane_copy(const char *str) |
nothing calls this directly
no test coverage detected