net/cxgb4: Fix referencing freed adapter
authorGavin Shan <shangw@linux.vnet.ibm.com>
Fri, 24 Jan 2014 09:12:03 +0000 (17:12 +0800)
committerDavid S. Miller <davem@davemloft.net>
Sat, 25 Jan 2014 00:00:37 +0000 (16:00 -0800)
The adapter is freed before we check its flags. It was caused
by commit 144be3d ("net/cxgb4: Avoid disabling PCI device for
towice"). The problem was reported by Intel's "0-day" tool.

The patch fixes it to avoid reverting commit 144be3d.

Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Gavin Shan <shangw@linux.vnet.ibm.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c

index 139a70405582c1fa094f7147c32928dd8b880190..43ab35fea48d2be9fe6dfcd4d1e9dc10651724be 100644 (file)
@@ -6163,13 +6163,13 @@ static void remove_one(struct pci_dev *pdev)
                iounmap(adapter->regs);
                if (!is_t4(adapter->params.chip))
                        iounmap(adapter->bar2);
-               kfree(adapter);
                pci_disable_pcie_error_reporting(pdev);
                if ((adapter->flags & DEV_ENABLED)) {
                        pci_disable_device(pdev);
                        adapter->flags &= ~DEV_ENABLED;
                }
                pci_release_regions(pdev);
+               kfree(adapter);
        } else
                pci_release_regions(pdev);
 }