From: Jie Liu <[email protected]>

sxe2_dev_pci_map_uinit() calls sxe2_dev_pci_seg_unmap() and walks
bar_info unconditionally. Only perform the unmap and free when
bar_info has been allocated, so an uninitialized map context is
handled cleanly.

Fixes: 66a10eb60e ("net/sxe2: add PCI BAR mapping")
Cc: [email protected]
Cc: [email protected]
Signed-off-by: Jie Liu <[email protected]>
---
 drivers/net/sxe2/sxe2_ethdev.c | 14 ++++++--------
 1 file changed, 6 insertions(+), 8 deletions(-)

diff --git a/drivers/net/sxe2/sxe2_ethdev.c b/drivers/net/sxe2/sxe2_ethdev.c
index f76d4db6f7..7e3eb6432c 100644
--- a/drivers/net/sxe2/sxe2_ethdev.c
+++ b/drivers/net/sxe2/sxe2_ethdev.c
@@ -1777,14 +1777,13 @@ void sxe2_dev_pci_map_uinit(struct rte_eth_dev *dev)
        uint8_t i = 0;
 
        PMD_INIT_FUNC_TRACE();
+       if (map_ctxt->bar_info != NULL) {
+               (void)sxe2_dev_pci_seg_unmap(adapter, 
SXE2_PCI_MAP_RES_DOORBELL_RX_TAIL);
+               (void)sxe2_dev_pci_seg_unmap(adapter, 
SXE2_PCI_MAP_RES_DOORBELL_TX);
+               (void)sxe2_dev_pci_seg_unmap(adapter, SXE2_PCI_MAP_RES_IRQ_DYN);
+               (void)sxe2_dev_pci_seg_unmap(adapter, SXE2_PCI_MAP_RES_IRQ_ITR);
+               (void)sxe2_dev_pci_seg_unmap(adapter, 
SXE2_PCI_MAP_RES_IRQ_MSIX);
 
-       (void)sxe2_dev_pci_seg_unmap(adapter, 
SXE2_PCI_MAP_RES_DOORBELL_RX_TAIL);
-       (void)sxe2_dev_pci_seg_unmap(adapter, SXE2_PCI_MAP_RES_DOORBELL_TX);
-       (void)sxe2_dev_pci_seg_unmap(adapter, SXE2_PCI_MAP_RES_IRQ_DYN);
-       (void)sxe2_dev_pci_seg_unmap(adapter, SXE2_PCI_MAP_RES_IRQ_ITR);
-       (void)sxe2_dev_pci_seg_unmap(adapter, SXE2_PCI_MAP_RES_IRQ_MSIX);
-
-       if (map_ctxt != NULL && map_ctxt->bar_info != NULL) {
                for (i = 0; i < map_ctxt->bar_cnt; i++) {
                        bar_info = &map_ctxt->bar_info[i];
                        if (bar_info != NULL && bar_info->seg_info != NULL) {
@@ -1795,7 +1794,6 @@ void sxe2_dev_pci_map_uinit(struct rte_eth_dev *dev)
                rte_free(map_ctxt->bar_info);
                map_ctxt->bar_info = NULL;
        }
-
        adapter->dev_info.dev_data = NULL;
 }
 
-- 
2.52.0

Reply via email to