DPDK patches and discussions
 help / color / mirror / Atom feed
* [PATCH] common/mlx5: fix the sysfs port name translation
@ 2022-11-10 15:57 Bing Zhao
  2022-11-10 16:21 ` Stephen Hemminger
  2023-03-22 11:34 ` [PATCH v2] " Bing Zhao
  0 siblings, 2 replies; 12+ messages in thread
From: Bing Zhao @ 2022-11-10 15:57 UTC (permalink / raw)
  To: viacheslavo, matan; +Cc: dev, rasland, stable

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


^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2023-03-28  8:39 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-10 15:57 [PATCH] common/mlx5: fix the sysfs port name translation Bing Zhao
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

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).