DPDK patches and discussions
 help / color / mirror / Atom feed
From: Kaiyu Zhang <squirrel.prog@gmail.com>
To: thomas@monjalon.net, ferruh.yigit@amd.com, andrew.rybchenko@oktetlabs.ru
Cc: dev@dpdk.org, Kaiyu Zhang <squirrel.prog@gmail.com>
Subject: [PATCH] lib/ethdev: sanity check on callback before resource allocation
Date: Tue, 11 Jul 2023 01:18:09 +0000	[thread overview]
Message-ID: <20230711011809.96677-1-squirrel.prog@gmail.com> (raw)

sanity check is performed after a rte_eth_dev object is allocated.
The object is not freed if the check fails, though in the current
reality this never happens, but it's better programming paradigm
to move the quick check up front to the start of
rte_eth_dev_pci_generic_probe.

Signed-off-by: Kaiyu Zhang <squirrel.prog@gmail.com>
---
 lib/ethdev/ethdev_pci.h | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/lib/ethdev/ethdev_pci.h b/lib/ethdev/ethdev_pci.h
index 94b8fba5d7..320e3e0093 100644
--- a/lib/ethdev/ethdev_pci.h
+++ b/lib/ethdev/ethdev_pci.h
@@ -126,12 +126,13 @@ rte_eth_dev_pci_generic_probe(struct rte_pci_device *pci_dev,
 	struct rte_eth_dev *eth_dev;
 	int ret;
 
+	if (*dev_init == NULL)
+		return -EINVAL;
+
 	eth_dev = rte_eth_dev_pci_allocate(pci_dev, private_data_size);
 	if (!eth_dev)
 		return -ENOMEM;
 
-	if (*dev_init == NULL)
-		return -EINVAL;
 	ret = dev_init(eth_dev);
 	if (ret)
 		rte_eth_dev_release_port(eth_dev);
-- 
2.34.1


             reply	other threads:[~2023-07-11  1:18 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-07-11  1:18 Kaiyu Zhang [this message]
2023-07-11  1:48 ` fengchengwen
2023-07-11 13:37   ` Ferruh Yigit
2023-08-01 16:19 ` Stephen Hemminger

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=20230711011809.96677-1-squirrel.prog@gmail.com \
    --to=squirrel.prog@gmail.com \
    --cc=andrew.rybchenko@oktetlabs.ru \
    --cc=dev@dpdk.org \
    --cc=ferruh.yigit@amd.com \
    --cc=thomas@monjalon.net \
    /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).