Bluetooth: hci_nokia: prevent crash on module removal
authorIan Molton <ian@mnementh.co.uk>
Sat, 8 Jul 2017 13:43:34 +0000 (14:43 +0100)
committerMarcel Holtmann <marcel@holtmann.org>
Thu, 20 Jul 2017 09:18:35 +0000 (11:18 +0200)
Only cancel any ongoing work after making sure, that no new work
can be scheduled. This fixes a race condition in the remove handler.

Signed-off-by: Ian Molton <ian@mnementh.co.uk>
Reviewed-by: Sebastian Reichel <sebastian.reichel@collabora.co.uk>
Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
drivers/bluetooth/hci_nokia.c

index 181a15b549e59983d3ef015f128147ee80409775..bc1f4496583e46cdc15b6c85bf7c18ff0a1a217d 100644 (file)
@@ -770,10 +770,12 @@ static void nokia_bluetooth_serdev_remove(struct serdev_device *serdev)
        struct hci_uart *hu = &btdev->hu;
        struct hci_dev *hdev = hu->hdev;
 
-       cancel_work_sync(&hu->write_work);
 
        hci_unregister_dev(hdev);
        hci_free_dev(hdev);
+
+       cancel_work_sync(&hu->write_work);
+
        hu->proto->close(hu);
 
        pm_runtime_disable(&btdev->serdev->dev);