[02/10] net/nfp: fix malloc name problem in secondary process

Message ID 20241010091716.3631747-3-chaoyong.he@corigine.com (mailing list archive)
State Superseded, archived
Delegated to: Ferruh Yigit
Headers
Series modify some logic of NFP PMD |

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

Chaoyong He Oct. 10, 2024, 9:17 a.m. UTC
The original logic keeps using the same name parameter when malloc
memory in secondary process, which may cause error when using
multiple PF cards.

Fixes: 3b00109d2b65 ("net/nfp: add PF ID used to format symbols")
Cc: peng.zhang@corigine.com
Cc: stable@dpdk.org

Signed-off-by: Chaoyong He <chaoyong.he@corigine.com>
Reviewed-by: Long Wu <long.wu@corigine.com>
Reviewed-by: Peng Zhang <peng.zhang@corigine.com>
---
 drivers/net/nfp/nfp_ethdev.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
  

Comments

Stephen Hemminger Oct. 10, 2024, 3:07 p.m. UTC | #1
On Thu, 10 Oct 2024 17:17:08 +0800
Chaoyong He <chaoyong.he@corigine.com> wrote:

> The original logic keeps using the same name parameter when malloc
> memory in secondary process, which may cause error when using
> multiple PF cards.
> 
> Fixes: 3b00109d2b65 ("net/nfp: add PF ID used to format symbols")
> Cc: peng.zhang@corigine.com
> Cc: stable@dpdk.org
> 
> Signed-off-by: Chaoyong He <chaoyong.he@corigine.com>
> Reviewed-by: Long Wu <long.wu@corigine.com>
> Reviewed-by: Peng Zhang <peng.zhang@corigine.com>

Huh? the name is ignored by rte_malloc(), it only shows up in tracing.
 in fact you could just always pass NULL.
  
Chaoyong He Oct. 11, 2024, 2:31 a.m. UTC | #2
> On Thu, 10 Oct 2024 17:17:08 +0800
> Chaoyong He <chaoyong.he@corigine.com> wrote:
> 
> > The original logic keeps using the same name parameter when malloc
> > memory in secondary process, which may cause error when using multiple
> > PF cards.
> >
> > Fixes: 3b00109d2b65 ("net/nfp: add PF ID used to format symbols")
> > Cc: peng.zhang@corigine.com
> > Cc: stable@dpdk.org
> >
> > Signed-off-by: Chaoyong He <chaoyong.he@corigine.com>
> > Reviewed-by: Long Wu <long.wu@corigine.com>
> > Reviewed-by: Peng Zhang <peng.zhang@corigine.com>
> 
> Huh? the name is ignored by rte_malloc(), it only shows up in tracing.
>  in fact you could just always pass NULL.

Yeah, I have learned this from some patch thread.
I will choose using 'NULL' in the newly added logic, treat this API as a 'white box'.
But for already exist logic like this one, I prefer to fix it, and treat it as a 'black box'.
  

Patch

diff --git a/drivers/net/nfp/nfp_ethdev.c b/drivers/net/nfp/nfp_ethdev.c
index 64a06440f5..3732abc9fe 100644
--- a/drivers/net/nfp/nfp_ethdev.c
+++ b/drivers/net/nfp/nfp_ethdev.c
@@ -2669,7 +2669,8 @@  nfp_pf_secondary_init(struct rte_pci_device *pci_dev)
 	}
 
 	/* Allocate memory for the PF "device" */
-	snprintf(name, sizeof(name), "nfp_pf%d", 0);
+	function_id = pci_dev->addr.function & 0x7;
+	snprintf(name, sizeof(name), "nfp_pf%d", function_id);
 	pf_dev = rte_zmalloc(name, sizeof(*pf_dev), 0);
 	if (pf_dev == NULL) {
 		PMD_INIT_LOG(ERR, "Can't allocate memory for the PF device");
@@ -2714,7 +2715,6 @@  nfp_pf_secondary_init(struct rte_pci_device *pci_dev)
 	}
 
 	/* Read the app ID of the firmware loaded */
-	function_id = pci_dev->addr.function & 0x7;
 	snprintf(app_name, sizeof(app_name), "_pf%u_net_app_id", function_id);
 	app_fw_id = nfp_rtsym_read_le(sym_tbl, app_name, &ret);
 	if (ret != 0) {