DPDK patches and discussions
 help / color / mirror / Atom feed
From: Bing Zhao <bingz@nvidia.com>
To: <viacheslavo@nvidia.com>, <matan@nvidia.com>
Cc: <dev@dpdk.org>, <rasland@nvidia.com>, <stable@dpdk.org>
Subject: [PATCH] common/mlx5: fix the sysfs port name translation
Date: Thu, 10 Nov 2022 17:57:26 +0200	[thread overview]
Message-ID: <20221110155726.649190-1-bingz@nvidia.com> (raw)

With some OFED or upstream kernel of mlx5, the port name fetched from
"/sys/class/net/[DEV]/phys_port_name" may have a tailing "\n" as the
EOL. The sscanf() will return the scanned items number with this EOL.

In such case, the "equal to" condition is considered as false and
the function mlx5_translate_port_name() will recognize the port type
wrongly with UNKNOWN result.

By changing the condition from "equal to" to "more than or equal
to", the port type can be recognized successfully.

Fixes: 654810b56828 ("common/mlx5: share Netlink commands")
Fixes: 420bbdae89f2 ("net/mlx5: fix host physical function representor naming")

Signed-off-by: Bing Zhao <bingz@nvidia.com>
Acked-by: Viacheslav Ovsiienko <viacheslavo@nvidia.com>
---
 drivers/common/mlx5/linux/mlx5_common_os.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/common/mlx5/linux/mlx5_common_os.c b/drivers/common/mlx5/linux/mlx5_common_os.c
index aafff60eeb..655347a7c8 100644
--- a/drivers/common/mlx5/linux/mlx5_common_os.c
+++ b/drivers/common/mlx5/linux/mlx5_common_os.c
@@ -108,7 +108,7 @@ mlx5_translate_port_name(const char *port_name_in,
 	sc_items = sscanf(port_name_in, "%c%c%d%c%c%d%c",
 			  &pf_c1, &pf_c2, &port_info_out->pf_num,
 			  &vf_c1, &vf_c2, &port_info_out->port_name, &eol);
-	if (sc_items == 6 && pf_c1 == 'p' && pf_c2 == 'f') {
+	if (sc_items >= 6 && pf_c1 == 'p' && pf_c2 == 'f') {
 		if (vf_c1 == 'v' && vf_c2 == 'f') {
 			/* Kernel ver >= 5.0 or OFED ver >= 4.6 */
 			port_info_out->name_type =
@@ -128,7 +128,7 @@ mlx5_translate_port_name(const char *port_name_in,
 	 */
 	sc_items = sscanf(port_name_in, "%c%d%c",
 			  &pf_c1, &port_info_out->port_name, &eol);
-	if (sc_items == 2 && pf_c1 == 'p') {
+	if (sc_items >= 2 && pf_c1 == 'p') {
 		port_info_out->name_type = MLX5_PHYS_PORT_NAME_TYPE_UPLINK;
 		return;
 	}
@@ -138,7 +138,7 @@ mlx5_translate_port_name(const char *port_name_in,
 	 */
 	sc_items = sscanf(port_name_in, "%c%c%d%c",
 			  &pf_c1, &pf_c2, &port_info_out->pf_num, &eol);
-	if (sc_items == 3 && pf_c1 == 'p' && pf_c2 == 'f') {
+	if (sc_items >= 3 && pf_c1 == 'p' && pf_c2 == 'f') {
 		port_info_out->port_name = -1;
 		port_info_out->name_type = MLX5_PHYS_PORT_NAME_TYPE_PFHPF;
 		return;
-- 
2.21.0


             reply	other threads:[~2022-11-10 15:57 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-10 15:57 Bing Zhao [this message]
2022-11-10 16:21 ` Stephen Hemminger
2022-11-11  5:41   ` Bing Zhao
2022-11-11 17:38     ` Stephen Hemminger
2023-03-22 11:34 ` [PATCH v2] " Bing Zhao
2023-03-22 14:58   ` Stephen Hemminger
2023-03-23  8:20     ` Bing Zhao
2023-03-22 14:59   ` Stephen Hemminger
2023-03-23  8:23     ` Bing Zhao
2023-03-23 10:54   ` [PATCH v3] net/mlx5: " Bing Zhao
2023-03-27 15:00     ` Matan Azrad
2023-03-28  8:39     ` Raslan Darawsheh

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20221110155726.649190-1-bingz@nvidia.com \
    --to=bingz@nvidia.com \
    --cc=dev@dpdk.org \
    --cc=matan@nvidia.com \
    --cc=rasland@nvidia.com \
    --cc=stable@dpdk.org \
    --cc=viacheslavo@nvidia.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).