Skip to content

Commit

Permalink
ethdev: fix potential leak in PCI probing helper
Browse files Browse the repository at this point in the history
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().

Fixes: dcd5c81 ("ethdev: add PCI driver helpers")
Cc: stable@dpdk.org

Signed-off-by: Kaiyu Zhang <squirrel.prog@gmail.com>
Reviewed-by: Chengwen Feng <fengchengwen@huawei.com>
Reviewed-by: Ferruh Yigit <ferruh.yigit@amd.com>
  • Loading branch information
kernel-guy authored and ferruhy committed Jul 11, 2023
1 parent 6bec7c5 commit 1f00a6a
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
1 change: 1 addition & 0 deletions .mailmap
Original file line number Diff line number Diff line change
Expand Up @@ -698,6 +698,7 @@ Kai Ji <kai.ji@intel.com>
Kaijun Zeng <corezeng@gmail.com>
Kaisen You <kaisenx.you@intel.com>
Kaiwen Deng <kaiwenx.deng@intel.com>
Kaiyu Zhang <squirrel.prog@gmail.com>
Kalesh AP <kalesh-anakkur.purayil@broadcom.com>
Kamalakannan R <kamalakannan.r@intel.com>
Kamalakshitha Aligeri <kamalakshitha.aligeri@arm.com>
Expand Down
5 changes: 3 additions & 2 deletions lib/ethdev/ethdev_pci.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 1f00a6a

Please sign in to comment.