summaryrefslogtreecommitdiff
path: root/net
diff options
context:
space:
mode:
authorJiri Pirko <jiri@nvidia.com>2021-05-27 13:48:19 +0300
committerJakub Kicinski <kuba@kernel.org>2021-05-28 00:21:12 +0300
commitf285f37cb1e6b29e7dc732c81510aa115463730f (patch)
tree89fb7ecc1f0c4de7c45ed3565344f714b8040739 /net
parent5ada57a9a6b0be0e6dfcbd4afa519b0347fd5649 (diff)
downloadlinux-f285f37cb1e6b29e7dc732c81510aa115463730f.tar.xz
devlink: append split port number to the port name
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>
Diffstat (limited to 'net')
-rw-r--r--net/core/devlink.c10
1 files changed, 4 insertions, 6 deletions
diff --git a/net/core/devlink.c b/net/core/devlink.c
index 4eb969518ee0..69681f19388e 100644
--- a/net/core/devlink.c
+++ b/net/core/devlink.c
@@ -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: