Re: [PATCH iproute2-next 3/5] devlink: Supporting add and delete of devlink port
From: David Ahern <hidden>
Date: 2021-01-31 20:10:21
On 1/29/21 9:56 AM, Parav Pandit wrote:
quoted hunk ↗ jump to hunk
@@ -1383,6 +1389,37 @@ static int reload_limit_get(struct dl *dl, const char *limitstr, return 0; } +static int port_flavour_parse(const char *flavour, uint16_t *value) +{ + if (!flavour) + return -EINVAL; + + if (strcmp(flavour, "physical") == 0) { + *value = DEVLINK_PORT_FLAVOUR_PHYSICAL; + return 0; + } else if (strcmp(flavour, "cpu") == 0) { + *value = DEVLINK_PORT_FLAVOUR_CPU; + return 0; + } else if (strcmp(flavour, "dsa") == 0) { + *value = DEVLINK_PORT_FLAVOUR_DSA; + return 0; + } else if (strcmp(flavour, "pcipf") == 0) { + *value = DEVLINK_PORT_FLAVOUR_PCI_PF; + return 0; + } else if (strcmp(flavour, "pcivf") == 0) { + *value = DEVLINK_PORT_FLAVOUR_PCI_VF; + return 0; + } else if (strcmp(flavour, "pcisf") == 0) { + *value = DEVLINK_PORT_FLAVOUR_PCI_SF; + return 0; + } else if (strcmp(flavour, "virtual") == 0) { + *value = DEVLINK_PORT_FLAVOUR_VIRTUAL; + return 0; + } else { + return -EINVAL; + } +}
use a struct for the string - value conversions; that should have been done for port_flavour_name so it can be refactored to use that kind of relationship. This function is just the inverse of it.