patches for DPDK stable branches
 help / color / mirror / Atom feed
From: Chaoyong He <chaoyong.he@corigine.com>
To: dev@dpdk.org
Cc: oss-drivers@corigine.com, Long Wu <long.wu@corigine.com>,
	peng.zhang@corigine.com, stable@dpdk.org,
	Chaoyong He <chaoyong.he@corigine.com>
Subject: [PATCH 1/6] net/nfp: fix check logic for device arguments
Date: Wed, 19 Jun 2024 11:06:50 +0800	[thread overview]
Message-ID: <20240619030655.3216268-2-chaoyong.he@corigine.com> (raw)
In-Reply-To: <20240619030655.3216268-1-chaoyong.he@corigine.com>

From: Long Wu <long.wu@corigine.com>

There is no check for NFP device argument now, so the users may
not be aware of the wrong device argument and feels confused
with the result in some case.

Add the check logic to fix this problem.

Fixes: b301fd736003 ("net/nfp: add force reload firmware option")
Cc: peng.zhang@corigine.com
Cc: stable@dpdk.org

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

diff --git a/drivers/net/nfp/nfp_ethdev.c b/drivers/net/nfp/nfp_ethdev.c
index 71c4f35c56..ddbbd736db 100644
--- a/drivers/net/nfp/nfp_ethdev.c
+++ b/drivers/net/nfp/nfp_ethdev.c
@@ -67,46 +67,64 @@ nfp_devarg_handle_int(const char *key,
 	return 0;
 }
 
-static void
-nfp_devarg_parse_force_reload_fw(struct rte_kvargs *kvlist,
-		bool *force_reload_fw)
+static int
+nfp_devarg_parse_bool_para(struct rte_kvargs *kvlist,
+		const char *key_match,
+		bool *value_ret)
 {
 	int ret;
+	uint32_t count;
 	uint64_t value;
 
+	count = rte_kvargs_count(kvlist, key_match);
+	if (count == 0)
+		return 0;
 
-	if (rte_kvargs_count(kvlist, NFP_PF_FORCE_RELOAD_FW) != 1)
-		return;
+	if (count > 1) {
+		PMD_DRV_LOG(ERR, "Too much bool arguments: %s", key_match);
+		return -EINVAL;
+	}
 
-	ret = rte_kvargs_process(kvlist, NFP_PF_FORCE_RELOAD_FW, &nfp_devarg_handle_int, &value);
+	ret = rte_kvargs_process(kvlist, key_match, &nfp_devarg_handle_int, &value);
 	if (ret != 0)
-		return;
+		return -EINVAL;
 
-	if (value == 1)
-		*force_reload_fw = true;
-	else if (value == 0)
-		*force_reload_fw = false;
-	else
+	if (value == 1) {
+		*value_ret = true;
+	} else if (value == 0) {
+		*value_ret = false;
+	} else {
 		PMD_DRV_LOG(ERR, "The param does not work, the format is %s=0/1",
-				NFP_PF_FORCE_RELOAD_FW);
+				key_match);
+		return -EINVAL;
+	}
+
+	return 0;
 }
 
-static void
+static int
 nfp_devargs_parse(struct nfp_devargs *nfp_devargs_param,
 		const struct rte_devargs *devargs)
 {
+	int ret;
 	struct rte_kvargs *kvlist;
 
 	if (devargs == NULL)
-		return;
+		return 0;
 
 	kvlist = rte_kvargs_parse(devargs->args, NULL);
 	if (kvlist == NULL)
-		return;
+		return -EINVAL;
 
-	nfp_devarg_parse_force_reload_fw(kvlist, &nfp_devargs_param->force_reload_fw);
+	ret = nfp_devarg_parse_bool_para(kvlist, NFP_PF_FORCE_RELOAD_FW,
+			&nfp_devargs_param->force_reload_fw);
+	if (ret != 0)
+		goto exit;
 
+exit:
 	rte_kvargs_free(kvlist);
+
+	return ret;
 }
 
 static void
@@ -1856,7 +1874,12 @@ nfp_pf_init(struct rte_pci_device *pci_dev)
 		nfp_eth_set_configured(cpp, index, 0);
 	}
 
-	nfp_devargs_parse(&pf_dev->devargs, pci_dev->device.devargs);
+	ret = nfp_devargs_parse(&pf_dev->devargs, pci_dev->device.devargs);
+	if (ret != 0) {
+		PMD_INIT_LOG(ERR, "Error when parsing device args");
+		ret = -EINVAL;
+		goto eth_table_cleanup;
+	}
 
 	if (nfp_fw_setup(pci_dev, cpp, nfp_eth_table, hwinfo,
 			dev_info, &pf_dev->multi_pf, pf_dev->devargs.force_reload_fw) != 0) {
-- 
2.39.1


       reply	other threads:[~2024-06-19  3:07 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20240619030655.3216268-1-chaoyong.he@corigine.com>
2024-06-19  3:06 ` Chaoyong He [this message]
2024-06-19  3:06 ` [PATCH 4/6] net/nfp: fix disable CPP service Chaoyong He

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240619030655.3216268-2-chaoyong.he@corigine.com \
    --to=chaoyong.he@corigine.com \
    --cc=dev@dpdk.org \
    --cc=long.wu@corigine.com \
    --cc=oss-drivers@corigine.com \
    --cc=peng.zhang@corigine.com \
    --cc=stable@dpdk.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).