* [patch net-next] devlink: append split port number to the port name
@ 2021-05-26 10:35 Jiri Pirko
2021-05-27 0:05 ` Jakub Kicinski
0 siblings, 1 reply; 3+ messages in thread
From: Jiri Pirko @ 2021-05-26 10:35 UTC (permalink / raw)
To: netdev; +Cc: davem, kuba, mlxsw
From: Jiri Pirko <jiri@nvidia.com>
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>
---
net/core/devlink.c | 10 ++++------
1 file changed, 4 insertions(+), 6 deletions(-)
diff --git a/net/core/devlink.c b/net/core/devlink.c
index 06b2b1941dce..c7754c293010 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 (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:
--
2.31.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [patch net-next] devlink: append split port number to the port name
2021-05-26 10:35 [patch net-next] devlink: append split port number to the port name Jiri Pirko
@ 2021-05-27 0:05 ` Jakub Kicinski
2021-05-27 10:12 ` Jiri Pirko
0 siblings, 1 reply; 3+ messages in thread
From: Jakub Kicinski @ 2021-05-27 0:05 UTC (permalink / raw)
To: Jiri Pirko; +Cc: netdev, davem, mlxsw
On Wed, 26 May 2021 12:35:08 +0200 Jiri Pirko wrote:
> From: Jiri Pirko <jiri@nvidia.com>
>
> 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>
> diff --git a/net/core/devlink.c b/net/core/devlink.c
> index 06b2b1941dce..c7754c293010 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);
snprintf() can return n > len, you need to check for this before
passing len - n as an unsigned argument below.
> + if (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:
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [patch net-next] devlink: append split port number to the port name
2021-05-27 0:05 ` Jakub Kicinski
@ 2021-05-27 10:12 ` Jiri Pirko
0 siblings, 0 replies; 3+ messages in thread
From: Jiri Pirko @ 2021-05-27 10:12 UTC (permalink / raw)
To: Jakub Kicinski; +Cc: netdev, davem, mlxsw
Thu, May 27, 2021 at 02:05:56AM CEST, kuba@kernel.org wrote:
>On Wed, 26 May 2021 12:35:08 +0200 Jiri Pirko wrote:
>> From: Jiri Pirko <jiri@nvidia.com>
>>
>> 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>
>
>> diff --git a/net/core/devlink.c b/net/core/devlink.c
>> index 06b2b1941dce..c7754c293010 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);
>
>snprintf() can return n > len, you need to check for this before
>passing len - n as an unsigned argument below.
Correct, will send v2. Thanks!
>
>> + if (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:
>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2021-05-27 10:12 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-05-26 10:35 [patch net-next] devlink: append split port number to the port name Jiri Pirko
2021-05-27 0:05 ` Jakub Kicinski
2021-05-27 10:12 ` Jiri Pirko
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).