Skip to content

Commit

Permalink
ethdev: fix potential leak in PCI probing helper
Browse files Browse the repository at this point in the history
[ upstream commit 1f00a6a037040a7c6ba883e2c312894c6ebc4c32 ]

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")

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 kevintraynor committed Jul 18, 2023
1 parent ac4f18b commit 9eda05b
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
1 change: 1 addition & 0 deletions .mailmap
Original file line number Diff line number Diff line change
Expand Up @@ -679,6 +679,7 @@ Juraj Linkeš <juraj.linkes@pantheon.tech>
Kai Ji <kai.ji@intel.com>
Kaijun Zeng <corezeng@gmail.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
4 changes: 3 additions & 1 deletion lib/ethdev/ethdev_pci.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,11 +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;

RTE_FUNC_PTR_OR_ERR_RET(*dev_init, -EINVAL);
ret = dev_init(eth_dev);
if (ret)
rte_eth_dev_release_port(eth_dev);
Expand Down

0 comments on commit 9eda05b

Please sign in to comment.