Skip to content

Commit 57a1681

Browse files
mudonglianggregkh
authored andcommitted
ipack: tpci200: fix many double free issues in tpci200_pci_probe
The function tpci200_register called by tpci200_install and tpci200_unregister called by tpci200_uninstall are in pair. However, tpci200_unregister has some cleanup operations not in the tpci200_register. So the error handling code of tpci200_pci_probe has many different double free issues. Fix this problem by moving those cleanup operations out of tpci200_unregister, into tpci200_pci_remove and reverting the previous commit 9272e5d ("ipack/carriers/tpci200: Fix a double free in tpci200_pci_probe"). Fixes: 9272e5d ("ipack/carriers/tpci200: Fix a double free in tpci200_pci_probe") Cc: [email protected] Reported-by: Dongliang Mu <[email protected]> Signed-off-by: Dongliang Mu <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent d777725 commit 57a1681

File tree

1 file changed

+18
-18
lines changed

1 file changed

+18
-18
lines changed

drivers/ipack/carriers/tpci200.c

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -89,16 +89,13 @@ static void tpci200_unregister(struct tpci200_board *tpci200)
8989
free_irq(tpci200->info->pdev->irq, (void *) tpci200);
9090

9191
pci_iounmap(tpci200->info->pdev, tpci200->info->interface_regs);
92-
pci_iounmap(tpci200->info->pdev, tpci200->info->cfg_regs);
9392

9493
pci_release_region(tpci200->info->pdev, TPCI200_IP_INTERFACE_BAR);
9594
pci_release_region(tpci200->info->pdev, TPCI200_IO_ID_INT_SPACES_BAR);
9695
pci_release_region(tpci200->info->pdev, TPCI200_MEM16_SPACE_BAR);
9796
pci_release_region(tpci200->info->pdev, TPCI200_MEM8_SPACE_BAR);
98-
pci_release_region(tpci200->info->pdev, TPCI200_CFG_MEM_BAR);
9997

10098
pci_disable_device(tpci200->info->pdev);
101-
pci_dev_put(tpci200->info->pdev);
10299
}
103100

104101
static void tpci200_enable_irq(struct tpci200_board *tpci200,
@@ -527,7 +524,7 @@ static int tpci200_pci_probe(struct pci_dev *pdev,
527524
tpci200->info = kzalloc(sizeof(struct tpci200_infos), GFP_KERNEL);
528525
if (!tpci200->info) {
529526
ret = -ENOMEM;
530-
goto out_err_info;
527+
goto err_tpci200;
531528
}
532529

533530
pci_dev_get(pdev);
@@ -538,15 +535,15 @@ static int tpci200_pci_probe(struct pci_dev *pdev,
538535
if (ret) {
539536
dev_err(&pdev->dev, "Failed to allocate PCI Configuration Memory");
540537
ret = -EBUSY;
541-
goto out_err_pci_request;
538+
goto err_tpci200_info;
542539
}
543540
tpci200->info->cfg_regs = ioremap(
544541
pci_resource_start(pdev, TPCI200_CFG_MEM_BAR),
545542
pci_resource_len(pdev, TPCI200_CFG_MEM_BAR));
546543
if (!tpci200->info->cfg_regs) {
547544
dev_err(&pdev->dev, "Failed to map PCI Configuration Memory");
548545
ret = -EFAULT;
549-
goto out_err_ioremap;
546+
goto err_request_region;
550547
}
551548

552549
/* Disable byte swapping for 16 bit IP module access. This will ensure
@@ -569,7 +566,7 @@ static int tpci200_pci_probe(struct pci_dev *pdev,
569566
if (ret) {
570567
dev_err(&pdev->dev, "error during tpci200 install\n");
571568
ret = -ENODEV;
572-
goto out_err_install;
569+
goto err_cfg_regs;
573570
}
574571

575572
/* Register the carrier in the industry pack bus driver */
@@ -581,7 +578,7 @@ static int tpci200_pci_probe(struct pci_dev *pdev,
581578
dev_err(&pdev->dev,
582579
"error registering the carrier on ipack driver\n");
583580
ret = -EFAULT;
584-
goto out_err_bus_register;
581+
goto err_tpci200_install;
585582
}
586583

587584
/* save the bus number given by ipack to logging purpose */
@@ -592,19 +589,16 @@ static int tpci200_pci_probe(struct pci_dev *pdev,
592589
tpci200_create_device(tpci200, i);
593590
return 0;
594591

595-
out_err_bus_register:
592+
err_tpci200_install:
596593
tpci200_uninstall(tpci200);
597-
/* tpci200->info->cfg_regs is unmapped in tpci200_uninstall */
598-
tpci200->info->cfg_regs = NULL;
599-
out_err_install:
600-
if (tpci200->info->cfg_regs)
601-
iounmap(tpci200->info->cfg_regs);
602-
out_err_ioremap:
594+
err_cfg_regs:
595+
pci_iounmap(tpci200->info->pdev, tpci200->info->cfg_regs);
596+
err_request_region:
603597
pci_release_region(pdev, TPCI200_CFG_MEM_BAR);
604-
out_err_pci_request:
605-
pci_dev_put(pdev);
598+
err_tpci200_info:
606599
kfree(tpci200->info);
607-
out_err_info:
600+
pci_dev_put(pdev);
601+
err_tpci200:
608602
kfree(tpci200);
609603
return ret;
610604
}
@@ -614,6 +608,12 @@ static void __tpci200_pci_remove(struct tpci200_board *tpci200)
614608
ipack_bus_unregister(tpci200->info->ipack_bus);
615609
tpci200_uninstall(tpci200);
616610

611+
pci_iounmap(tpci200->info->pdev, tpci200->info->cfg_regs);
612+
613+
pci_release_region(tpci200->info->pdev, TPCI200_CFG_MEM_BAR);
614+
615+
pci_dev_put(tpci200->info->pdev);
616+
617617
kfree(tpci200->info);
618618
kfree(tpci200);
619619
}

0 commit comments

Comments
 (0)