Commit 07e84aa9 authored by Alan Jenkins's avatar Alan Jenkins Committed by Len Brown
Browse files

eeepc-laptop: fix pci hotplug race on load and unload



Wifi rfkill state changes can race with pci hotplug cleanup.  A simple
fix is to refresh the hotplug state just before deregistering the pci
hotplug slot.

There is also potential for a hotplug notification to fire too early
during setup, while the structures it uses are still being initialised.
(This could only happen if the BIOS performs hotplug itself; a bug
triggered by removing the battery while hibernated).  Avoid this by
registering the notifier later.  The same refresh mechanism is used
to handle rfkill state changes which can now race with registration.

Signed-off-by: default avatarAlan Jenkins <alan-jenkins@tuffmail.co.uk>
Signed-off-by: default avatarCorentin Chary <corentincj@iksaif.net>
Signed-off-by: default avatarLen Brown <len.brown@intel.com>
parent dcf443b5
Loading
Loading
Loading
Loading
+45 −32
Original line number Diff line number Diff line
@@ -667,13 +667,12 @@ static void eeepc_rfkill_hotplug(void)
	struct pci_bus *bus;
	bool blocked = eeepc_wlan_rfkill_blocked();

	if (ehotk->wlan_rfkill)
		rfkill_set_sw_state(ehotk->wlan_rfkill, blocked);

	mutex_lock(&ehotk->hotplug_lock);

	if (ehotk->hotplug_slot == NULL)
		goto out_unlock;

	if (ehotk->hotplug_slot) {
		bus = pci_find_bus(0, 1);
		if (!bus) {
			pr_warning("Unable to find PCI bus 1?\n");
@@ -700,6 +699,7 @@ static void eeepc_rfkill_hotplug(void)
				pci_dev_put(dev);
			}
		}
	}

out_unlock:
	mutex_unlock(&ehotk->hotplug_lock);
@@ -1029,14 +1029,22 @@ static void eeepc_rfkill_exit(void)
{
	eeepc_unregister_rfkill_notifier("\\_SB.PCI0.P0P6");
	eeepc_unregister_rfkill_notifier("\\_SB.PCI0.P0P7");
	if (ehotk->wlan_rfkill)
	if (ehotk->wlan_rfkill) {
		rfkill_unregister(ehotk->wlan_rfkill);
		ehotk->wlan_rfkill = NULL;
	}
	/*
	 * Refresh pci hotplug in case the rfkill state was changed after
	 * eeepc_unregister_rfkill_notifier()
	 */
	eeepc_rfkill_hotplug();
	if (ehotk->hotplug_slot)
		pci_hp_deregister(ehotk->hotplug_slot);

	if (ehotk->bluetooth_rfkill)
		rfkill_unregister(ehotk->bluetooth_rfkill);
	if (ehotk->wwan3g_rfkill)
		rfkill_unregister(ehotk->wwan3g_rfkill);
	if (ehotk->hotplug_slot)
		pci_hp_deregister(ehotk->hotplug_slot);
}

static void eeepc_input_exit(void)
@@ -1104,9 +1112,6 @@ static int eeepc_rfkill_init(struct device *dev)

	mutex_init(&ehotk->hotplug_lock);

	eeepc_register_rfkill_notifier("\\_SB.PCI0.P0P6");
	eeepc_register_rfkill_notifier("\\_SB.PCI0.P0P7");

	result = eeepc_new_rfkill(&ehotk->wlan_rfkill,
				  "eeepc-wlan", dev,
				  RFKILL_TYPE_WLAN, CM_ASL_WLAN);
@@ -1136,6 +1141,14 @@ static int eeepc_rfkill_init(struct device *dev)
	if (result == -EBUSY)
		result = 0;

	eeepc_register_rfkill_notifier("\\_SB.PCI0.P0P6");
	eeepc_register_rfkill_notifier("\\_SB.PCI0.P0P7");
	/*
	 * Refresh pci hotplug in case the rfkill state was changed during
	 * setup.
	 */
	eeepc_rfkill_hotplug();

exit:
	if (result && result != -ENODEV)
		eeepc_rfkill_exit();