lib/ethdev: sanity check on callback before resource allocation
PATCH 1/1 lib/ethdev: sanity check on callback before resource allocation
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.
--- lib/ethdev/ethdev_pci.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
lib/ethdev/ethdev_pci.h +3 -2
@@ -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);
Signature · 1 line
2.34.1
Please add Cc.
Quoted 32 lines · Kaiyu Zhang
sanity check is performed after a
rte_eth_devobject 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 ofrte_eth_dev_pci_generic_probe.Signed-off-by Kaiyu Zhang <[email protected]>--- lib/ethdev/ethdev_pci.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)lib/ethdev/ethdev_pci.h +3
-2@@ -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);
Quoted 7 lines · fengchengwen
Quoted 6 lines · Kaiyu Zhang
sanity check is performed after a
rte_eth_devobject 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 ofrte_eth_dev_pci_generic_probe.
Quoted 5 lines
Quoted 2 lines
Signed-off-by Kaiyu Zhang <[email protected]>Reviewed-by Chengwen Feng <[email protected]>
Applied to dpdk-next-net/main, thanks.
Quoted 7 lines · On Tue, 11 Jul 2023 01:18:09 +0000 Kaiyu Zhang <[email protected]> wrote:
sanity check is performed after a
rte_eth_devobject 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 ofrte_eth_dev_pci_generic_probe.Signed-off-by Kaiyu Zhang <[email protected]>
The term sanity check is on the non-inclusive naming word list. Please don't use that term in DPDK.
There is an outstanding patchset to remove all use of the term.