Commit dcf443b5 authored by Alan Jenkins's avatar Alan Jenkins Committed by Len Brown

eeepc-laptop: use a mutex to serialize pci hotplug (resume vs. notify)

Commit d0265f0 "eeepc-laptop: fix hot-unplug on resume" used a workqueue
to protect pci hotplug against multiple simultaneous calls during
resume.  It seems to work, but a mutex would be more appropriate.

This is in preparation to fix the potential pci hotplug race on unload.
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 6d41839e
...@@ -143,7 +143,7 @@ struct eeepc_hotk { ...@@ -143,7 +143,7 @@ struct eeepc_hotk {
struct rfkill *bluetooth_rfkill; struct rfkill *bluetooth_rfkill;
struct rfkill *wwan3g_rfkill; struct rfkill *wwan3g_rfkill;
struct hotplug_slot *hotplug_slot; struct hotplug_slot *hotplug_slot;
struct work_struct hotplug_work; struct mutex hotplug_lock;
}; };
/* The actual device the driver binds to */ /* The actual device the driver binds to */
...@@ -661,7 +661,7 @@ static int eeepc_get_adapter_status(struct hotplug_slot *hotplug_slot, ...@@ -661,7 +661,7 @@ static int eeepc_get_adapter_status(struct hotplug_slot *hotplug_slot,
return 0; return 0;
} }
static void eeepc_hotplug_work(struct work_struct *work) static void eeepc_rfkill_hotplug(void)
{ {
struct pci_dev *dev; struct pci_dev *dev;
struct pci_bus *bus; struct pci_bus *bus;
...@@ -669,13 +669,15 @@ static void eeepc_hotplug_work(struct work_struct *work) ...@@ -669,13 +669,15 @@ static void eeepc_hotplug_work(struct work_struct *work)
rfkill_set_sw_state(ehotk->wlan_rfkill, blocked); rfkill_set_sw_state(ehotk->wlan_rfkill, blocked);
mutex_lock(&ehotk->hotplug_lock);
if (ehotk->hotplug_slot == NULL) if (ehotk->hotplug_slot == NULL)
return; goto out_unlock;
bus = pci_find_bus(0, 1); bus = pci_find_bus(0, 1);
if (!bus) { if (!bus) {
pr_warning("Unable to find PCI bus 1?\n"); pr_warning("Unable to find PCI bus 1?\n");
return; goto out_unlock;
} }
if (!blocked) { if (!blocked) {
...@@ -683,7 +685,7 @@ static void eeepc_hotplug_work(struct work_struct *work) ...@@ -683,7 +685,7 @@ static void eeepc_hotplug_work(struct work_struct *work)
if (dev) { if (dev) {
/* Device already present */ /* Device already present */
pci_dev_put(dev); pci_dev_put(dev);
return; goto out_unlock;
} }
dev = pci_scan_single_device(bus, 0); dev = pci_scan_single_device(bus, 0);
if (dev) { if (dev) {
...@@ -698,6 +700,9 @@ static void eeepc_hotplug_work(struct work_struct *work) ...@@ -698,6 +700,9 @@ static void eeepc_hotplug_work(struct work_struct *work)
pci_dev_put(dev); pci_dev_put(dev);
} }
} }
out_unlock:
mutex_unlock(&ehotk->hotplug_lock);
} }
static void eeepc_rfkill_notify(acpi_handle handle, u32 event, void *data) static void eeepc_rfkill_notify(acpi_handle handle, u32 event, void *data)
...@@ -705,7 +710,7 @@ static void eeepc_rfkill_notify(acpi_handle handle, u32 event, void *data) ...@@ -705,7 +710,7 @@ static void eeepc_rfkill_notify(acpi_handle handle, u32 event, void *data)
if (event != ACPI_NOTIFY_BUS_CHECK) if (event != ACPI_NOTIFY_BUS_CHECK)
return; return;
schedule_work(&ehotk->hotplug_work); eeepc_rfkill_hotplug();
} }
static void eeepc_hotk_notify(struct acpi_device *device, u32 event) static void eeepc_hotk_notify(struct acpi_device *device, u32 event)
...@@ -896,7 +901,7 @@ static int eeepc_hotk_resume(struct acpi_device *device) ...@@ -896,7 +901,7 @@ static int eeepc_hotk_resume(struct acpi_device *device)
rfkill_set_sw_state(ehotk->wlan_rfkill, wlan != 1); rfkill_set_sw_state(ehotk->wlan_rfkill, wlan != 1);
schedule_work(&ehotk->hotplug_work); eeepc_rfkill_hotplug();
} }
if (ehotk->bluetooth_rfkill) if (ehotk->bluetooth_rfkill)
...@@ -1097,7 +1102,7 @@ static int eeepc_rfkill_init(struct device *dev) ...@@ -1097,7 +1102,7 @@ static int eeepc_rfkill_init(struct device *dev)
{ {
int result = 0; int result = 0;
INIT_WORK(&ehotk->hotplug_work, eeepc_hotplug_work); mutex_init(&ehotk->hotplug_lock);
eeepc_register_rfkill_notifier("\\_SB.PCI0.P0P6"); eeepc_register_rfkill_notifier("\\_SB.PCI0.P0P6");
eeepc_register_rfkill_notifier("\\_SB.PCI0.P0P7"); eeepc_register_rfkill_notifier("\\_SB.PCI0.P0P7");
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment