[19/21] common/cnxk: access valid pass value

Message ID 20230411091144.1087887-19-ndabilpuram@marvell.com (mailing list archive)
State Changes Requested, archived
Delegated to: Jerin Jacob
Headers
Series [01/21] common/cnxk: allocate dynamic BPIDs |

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

Nithin Dabilpuram April 11, 2023, 9:11 a.m. UTC
  From: Hanumanth Pothula <hpothula@marvell.com>

There is a possibility of accessing an invalid pass value on
rvu device look up failure, as the return value is dropped.

Hence pass through the return value of rvu device look, to make
sure valid pass value is accessed.

Signed-off-by: Hanumanth Pothula <hpothula@marvell.com>
---
 drivers/common/cnxk/roc_model.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
  

Patch

diff --git a/drivers/common/cnxk/roc_model.c b/drivers/common/cnxk/roc_model.c
index f4f2a38e70..6dc2afe7f0 100644
--- a/drivers/common/cnxk/roc_model.c
+++ b/drivers/common/cnxk/roc_model.c
@@ -148,6 +148,7 @@  cn10k_part_pass_get(uint32_t *part, uint32_t *pass)
 #define SYSFS_PCI_DEVICES "/sys/bus/pci/devices"
 	char dirname[PATH_MAX];
 	struct dirent *e;
+	int ret = -1;
 	DIR *dir;
 
 	dir = opendir(SYSFS_PCI_DEVICES);
@@ -165,18 +166,19 @@  cn10k_part_pass_get(uint32_t *part, uint32_t *pass)
 			 e->d_name);
 
 		/* Lookup for rvu device and get part pass information */
-		if (!rvu_device_lookup(dirname, part, pass))
+		ret = rvu_device_lookup(dirname, part, pass);
+		if (!ret)
 			break;
 	}
 
 	closedir(dir);
-	return 0;
+	return ret;
 }
 
 static bool
 populate_model(struct roc_model *model, uint32_t midr)
 {
-	uint32_t impl, major, part, minor, pass;
+	uint32_t impl, major, part, minor, pass = 0;
 	bool found = false;
 	size_t i;