Skip to contentSkip to conversation

common/mlx5: fix PCI location address routine

PATCH In review Viacheslav Ovsiienko 2 participants 2 messages Sep 13, 2020 – Oct 8, 2020

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 common/mlx5: fix PCI location address routine

mlx5 PMDs use the mlx5_dev_to_pci_addr() routine to convert Infiniband device name to the Bus-Device-Function location on the PCI bus. The routine returned success even in case of not found identification string. On caller side it likely caused the wrong match with the BDF of previous device resulting in wrong representor and master recognitions.

Fixes 79aa430721b1 ("common/mlx5: split common file under Linux directory")
---
 drivers/common/mlx5/linux/mlx5_common_os.c | 18 +++++++++++++-----
 1 file changed, 13 insertions(+), 5 deletions(-)
drivers/common/mlx5/linux/mlx5_common_os.c +13 -5
index 7bb3ba6..0edd78e 100644
@@ -39,6 +39,7 @@
 {
 	FILE *file;
 	char line[32];
+	int rc = -ENOENT;
 	MKSTR(path, "%s/device/uevent", dev_path);
 
 	file = fopen(path, "rb");
@@ -48,16 +49,19 @@
 	}
 	while (fgets(line, sizeof(line), file) == line) {
 		size_t len = strlen(line);
-		int ret;
 
 		/* Truncate long lines. */
-		if (len == (sizeof(line) - 1))
+		if (len == (sizeof(line) - 1)) {
 			while (line[(len - 1)] != '\n') {
-				ret = fgetc(file);
+				int ret = fgetc(file);
+
 				if (ret == EOF)
-					break;
+					goto exit;
 				line[(len - 1)] = ret;
 			}
+			/* No match for long lines. */
+			continue;
+		}
 		/* Extract information. */
 		if (sscanf(line,
 			   "PCI_SLOT_NAME="
@@ -66,11 +70,15 @@
 			   &pci_addr->bus,
 			   &pci_addr->devid,
 			   &pci_addr->function) == 4) {
+			rc = 0;
 			break;
 		}
 	}
+exit:
 	fclose(file);
-	return 0;
+	if (rc)
+		rte_errno = -rc;
+	return rc;
 }
 
 /**
Signature · 1 line
1.8.3.1
#1 lore raw

Hi,

Quoted 79 lines

-----Original Message-----
From: Viacheslav Ovsiienko <[email protected]>
Sent: Sunday, September 13, 2020 10:55 PM
To: [email protected]
Cc: Raslan Darawsheh <[email protected]>; Matan Azrad <[email protected]>; Ori Kam <[email protected]>; [email protected]
Subject: [PATCH] common/mlx5: fix PCI location address routine

mlx5 PMDs use the mlx5_dev_to_pci_addr() routine to convert Infiniband device name to the Bus-Device-Function location on the PCI bus. The routine returned success even in case of not found identification string. On caller side it likely caused the wrong match with the BDF of previous device resulting in wrong representor and master recognitions.

Fixes 79aa430721b1 ("common/mlx5: split common file under Linux

directory")
Cc: [email protected]

---
 drivers/common/mlx5/linux/mlx5_common_os.c | 18 +++++++++++++-----
 1 file changed, 13 insertions(+), 5 deletions(-)
drivers/common/mlx5/linux/mlx5_common_os.c +13 -6
index 7bb3ba6..0edd78e 100644
@@ -39,6 +39,7 @@
 {
 	FILE *file;
 	char line[32];
+	int rc = -ENOENT;
 	MKSTR(path, "%s/device/uevent", dev_path);
 
 	file = fopen(path, "rb");
@@ -48,16 +49,19 @@
 	}
 	while (fgets(line, sizeof(line), file) == line) {
 		size_t len = strlen(line);
-		int ret;
 
 		/* Truncate long lines. */
-		if (len == (sizeof(line) - 1))
+		if (len == (sizeof(line) - 1)) {
 			while (line[(len - 1)] != '\n') {
-				ret = fgetc(file);
+				int ret = fgetc(file);
+
 				if (ret == EOF)
-					break;
+					goto exit;
 				line[(len - 1)] = ret;
 			}
+			/* No match for long lines. */
+			continue;
+		}
 		/* Extract information. */
 		if (sscanf(line,
 			   "PCI_SLOT_NAME="
@@ -66,11 +70,15 @@
 			   &pci_addr->bus,
 			   &pci_addr->devid,
 			   &pci_addr->function) == 4) {
+			rc = 0;
 			break;
 		}
 	}
+exit:
 	fclose(file);
-	return 0;
+	if (rc)
+		rte_errno = -rc;
+	return rc;
 }
 
 /**
--
Quoted 1 line

1.8.3.1

Patch applied to next-net-mlx,

Kindest regards,
Raslan Darawsheh