devlink: append split port number to the port name
authorJiri Pirko <jiri@nvidia.com>
Thu, 27 May 2021 10:48:19 +0000 (12:48 +0200)
committerJakub Kicinski <kuba@kernel.org>
Thu, 27 May 2021 21:21:12 +0000 (14:21 -0700)
Instead of doing sprintf twice in case the port is split or not, append
the split port suffix in case the port is split.

Signed-off-by: Jiri Pirko <jiri@nvidia.com>
Link: https://lore.kernel.org/r/20210527104819.789840-1-jiri@resnulli.us
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
net/core/devlink.c

index 4eb9695..69681f1 100644 (file)
@@ -8632,12 +8632,10 @@ static int __devlink_port_phys_port_name_get(struct devlink_port *devlink_port,
        switch (attrs->flavour) {
        case DEVLINK_PORT_FLAVOUR_PHYSICAL:
        case DEVLINK_PORT_FLAVOUR_VIRTUAL:
-               if (!attrs->split)
-                       n = snprintf(name, len, "p%u", attrs->phys.port_number);
-               else
-                       n = snprintf(name, len, "p%us%u",
-                                    attrs->phys.port_number,
-                                    attrs->phys.split_subport_number);
+               n = snprintf(name, len, "p%u", attrs->phys.port_number);
+               if (n < len && attrs->split)
+                       n += snprintf(name + n, len - n, "s%u",
+                                     attrs->phys.split_subport_number);
                break;
        case DEVLINK_PORT_FLAVOUR_CPU:
        case DEVLINK_PORT_FLAVOUR_DSA: