tbl_scope_pools_create() can return success after a failure. When
rte_zmalloc() fails for a pool manager, rc is still 0 from the
previous step, so the function jumps to cleanup and returns 0. For
the other failures, the cleanup loop assigns the results of
cfa_tim_tpm_inst_get() and cfa_tim_tpm_inst_set() to rc, replacing
the error that caused the cleanup.
Callers then carry on with a table scope that has no pool managers.
Return -ENOMEM when the allocation fails, and keep the original
error across the cleanup.
Fixes: 80317ff6adfd ("net/bnxt/tf_core: support Thor2")
Cc: [email protected]
Signed-off-by: Manish Kurup <[email protected]>
---
v2:
* Split out of "net/bnxt: fix multiple truflow defects" (one fix per
patch); this is the tbl_scope_pools_create() error return fix.
* Dropped the tpms[][] = NULL change, which was a no-op. Fix the actual
problem instead: the function could return success after a failure.
* Rewrote the commit message.
drivers/net/bnxt/tf_core/v3/tfc_tbl_scope.c | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)
diff --git a/drivers/net/bnxt/tf_core/v3/tfc_tbl_scope.c
b/drivers/net/bnxt/tf_core/v3/tfc_tbl_scope.c
index 0a5dce43fa..a761d9bdeb 100644
--- a/drivers/net/bnxt/tf_core/v3/tfc_tbl_scope.c
+++ b/drivers/net/bnxt/tf_core/v3/tfc_tbl_scope.c
@@ -574,6 +574,7 @@ static int tbl_scope_pools_create(struct tfc *tfcp, uint8_t
tsid,
struct tbl_scope_pools_create_parms *parms)
{
int rc;
+ int err;
int dir;
enum cfa_region_type region;
uint32_t tpm_db_size;
@@ -614,8 +615,10 @@ static int tbl_scope_pools_create(struct tfc *tfcp,
uint8_t tsid,
for (region = 0; region < CFA_REGION_TYPE_MAX; region++) {
for (dir = 0; dir < CFA_DIR_MAX; dir++) {
tpms[dir][region] = rte_zmalloc("TPM", tpm_db_size, 0);
- if (tpms[dir][region] == NULL)
+ if (tpms[dir][region] == NULL) {
+ rc = -ENOMEM;
goto cleanup;
+ }
rc = cfa_tpm_open(tpms[dir][region], tpm_db_size,
parms->max_pools);
if (rc)
@@ -637,6 +640,8 @@ static int tbl_scope_pools_create(struct tfc *tfcp, uint8_t
tsid,
return rc;
cleanup:
+ /* Keep the error that got us here; the calls below overwrite rc */
+ err = rc;
if (tim) {
for (region = 0; region < CFA_REGION_TYPE_MAX; region++) {
for (dir = 0; dir < CFA_DIR_MAX; dir++) {
@@ -666,7 +671,7 @@ static int tbl_scope_pools_create(struct tfc *tfcp, uint8_t
tsid,
}
}
- return rc;
+ return err;
}
/**
--
2.31.1