Merge tag 'tty-3.20-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/tty
[firefly-linux-kernel-4.4.55.git] / drivers / bcma / main.c
index c3c5e0a2d5bed2b21344d750e77693f3e4baac24..38bde6eab8a41867d92de40f7083e411efe67aeb 100644 (file)
@@ -368,12 +368,19 @@ static void bcma_unregister_cores(struct bcma_bus *bus)
        struct bcma_device *core, *tmp;
 
        list_for_each_entry_safe(core, tmp, &bus->cores, list) {
+               if (!core->dev_registered)
+                       continue;
                list_del(&core->list);
-               if (core->dev_registered)
-                       device_unregister(&core->dev);
+               device_unregister(&core->dev);
        }
        if (bus->hosttype == BCMA_HOSTTYPE_SOC)
                platform_device_unregister(bus->drv_cc.watchdog);
+
+       /* Now noone uses internally-handled cores, we can free them */
+       list_for_each_entry_safe(core, tmp, &bus->cores, list) {
+               list_del(&core->list);
+               kfree(core);
+       }
 }
 
 int bcma_bus_register(struct bcma_bus *bus)
@@ -395,6 +402,13 @@ int bcma_bus_register(struct bcma_bus *bus)
                bcma_core_chipcommon_early_init(&bus->drv_cc);
        }
 
+       /* Early init PCIE core */
+       core = bcma_find_core(bus, BCMA_CORE_PCIE);
+       if (core) {
+               bus->drv_pci[0].core = core;
+               bcma_core_pci_early_init(&bus->drv_pci[0]);
+       }
+
        /* Cores providing flash access go before SPROM init */
        list_for_each_entry(core, &bus->cores, list) {
                if (bcma_is_core_needed_early(core->id.id))
@@ -467,7 +481,6 @@ int bcma_bus_register(struct bcma_bus *bus)
 
 void bcma_bus_unregister(struct bcma_bus *bus)
 {
-       struct bcma_device *cores[3];
        int err;
 
        err = bcma_gpio_unregister(&bus->drv_cc);
@@ -478,15 +491,7 @@ void bcma_bus_unregister(struct bcma_bus *bus)
 
        bcma_core_chipcommon_b_free(&bus->drv_cc_b);
 
-       cores[0] = bcma_find_core(bus, BCMA_CORE_MIPS_74K);
-       cores[1] = bcma_find_core(bus, BCMA_CORE_PCIE);
-       cores[2] = bcma_find_core(bus, BCMA_CORE_4706_MAC_GBIT_COMMON);
-
        bcma_unregister_cores(bus);
-
-       kfree(cores[2]);
-       kfree(cores[1]);
-       kfree(cores[0]);
 }
 
 /*