| 58 | } |
| 59 | |
| 60 | static int |
| 61 | pci_dbdf_parse(const char *input, struct rte_pci_addr *dev_addr) |
| 62 | { |
| 63 | const char *in = input; |
| 64 | unsigned long val; |
| 65 | char *end; |
| 66 | |
| 67 | /* PCI id starting with spaces is forbidden. |
| 68 | * Negative wrap-around is not reported as an error by strtoul. |
| 69 | */ |
| 70 | if (*in == ' ' || *in == '-') |
| 71 | return -EINVAL; |
| 72 | |
| 73 | errno = 0; |
| 74 | val = strtoul(in, &end, 16); |
| 75 | /* Empty string is not an error for strtoul, but the check |
| 76 | * end[0] != ':' |
| 77 | * will detect the issue. |
| 78 | */ |
| 79 | if (errno != 0 || end[0] != ':' || val > UINT32_MAX) |
| 80 | return -EINVAL; |
| 81 | dev_addr->domain = (uint32_t)val; |
| 82 | in = end + 1; |
| 83 | in = get_u8_pciaddr_field(in, &dev_addr->bus, ':'); |
| 84 | if (in == NULL) |
| 85 | return -EINVAL; |
| 86 | in = get_u8_pciaddr_field(in, &dev_addr->devid, '.'); |
| 87 | if (in == NULL) |
| 88 | return -EINVAL; |
| 89 | in = get_u8_pciaddr_field(in, &dev_addr->function, '\0'); |
| 90 | if (in == NULL) |
| 91 | return -EINVAL; |
| 92 | return 0; |
| 93 | } |
| 94 | |
| 95 | void |
| 96 | rte_pci_device_name(const struct rte_pci_addr *addr, |
no test coverage detected