From: Andrew Rybchenko Date: Tue, 23 Jul 2019 12:11:21 +0000 (+0100) Subject: ethdev: avoid getting uninitialized info for bad port X-Git-Url: http://git.droids-corp.org/?a=commitdiff_plain;h=b6719879855d;p=dpdk.git ethdev: avoid getting uninitialized info for bad port rte_eth_dev_info_get() returns void and caller does know if the function does its job or not. Changing of the return value to int would be API/ABI breakage which requires deprecation process and cannot be backported to stable branches. For now, make sure that device info is initialized even in the case of invalid port ID. Fixes: a30268e9a2d0 ("ethdev: reset whole dev info structure before filling") Cc: stable@dpdk.org Signed-off-by: Andrew Rybchenko Acked-by: Thomas Monjalon --- diff --git a/lib/librte_ethdev/rte_ethdev.c b/lib/librte_ethdev/rte_ethdev.c index 64191737c7..17d183e1f0 100644 --- a/lib/librte_ethdev/rte_ethdev.c +++ b/lib/librte_ethdev/rte_ethdev.c @@ -2552,10 +2552,15 @@ rte_eth_dev_info_get(uint16_t port_id, struct rte_eth_dev_info *dev_info) .nb_mtu_seg_max = UINT16_MAX, }; + /* + * Init dev_info before port_id check since caller does not have + * return status and does not know if get is successful or not. + */ + memset(dev_info, 0, sizeof(struct rte_eth_dev_info)); + RTE_ETH_VALID_PORTID_OR_RET(port_id); dev = &rte_eth_devices[port_id]; - memset(dev_info, 0, sizeof(struct rte_eth_dev_info)); dev_info->rx_desc_lim = lim; dev_info->tx_desc_lim = lim; dev_info->device = dev->device;