[PATCH] lib/ethdev: sanity check on callback before resource allocation

fengchengwen fengchengwen at huawei.com
Tue Jul 11 03:48:54 CEST 2023


Please add Cc.
Reviewed-by: Chengwen Feng <fengchengwen at huawei.com>

On 2023/7/11 9:18, Kaiyu Zhang wrote:
> 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 at 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);
> 


More information about the dev mailing list