mei: Remove all bus devices from the mei_dev list when stopping the MEI
authorTomas Winkler <tomas.winkler@intel.com>
Mon, 17 Feb 2014 13:13:19 +0000 (15:13 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Tue, 18 Feb 2014 18:04:35 +0000 (10:04 -0800)
When stopping the MEI, we should remove and potentially unregister
all bus devices queued on the mei_dev linked list.

Signed-off-by: Tomas Winkler <tomas.winkler@intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/misc/mei/bus.c
drivers/misc/mei/init.c
drivers/misc/mei/mei_dev.h
drivers/misc/mei/nfc.c

index 4bc7d620d695f05c26a558cfe70992a4dae83963..cf4cc0bf2b17d4c8a574d49721062a0ba8860d5d 100644 (file)
@@ -524,6 +524,22 @@ void mei_cl_bus_rx_event(struct mei_cl *cl)
        schedule_work(&device->event_work);
 }
 
+void mei_cl_bus_remove_devices(struct mei_device *dev)
+{
+       struct mei_cl *cl, *next;
+
+       mutex_lock(&dev->device_lock);
+       list_for_each_entry_safe(cl, next, &dev->device_list, device_link) {
+               if (cl->device)
+                       mei_cl_remove_device(cl->device);
+
+               list_del(&cl->device_link);
+               mei_cl_unlink(cl);
+               kfree(cl);
+       }
+       mutex_unlock(&dev->device_lock);
+}
+
 int __init mei_cl_bus_init(void)
 {
        return bus_register(&mei_cl_bus_type);
index 214dcef9750a4853cc03fc4b0d904be5096cbace..4460975c0eefcc97c765dd83fcafc0a3f3290cd3 100644 (file)
@@ -288,6 +288,8 @@ void mei_stop(struct mei_device *dev)
 
        mei_nfc_host_exit(dev);
 
+       mei_cl_bus_remove_devices(dev);
+
        mutex_lock(&dev->device_lock);
 
        mei_wd_stop(dev);
index 21e52496bc6e68301ffcd0e33f6a275a676a5dd5..49025fa202ae4d3f9837da0eb92520767585ed1e 100644 (file)
@@ -296,6 +296,7 @@ int __mei_cl_async_send(struct mei_cl *cl, u8 *buf, size_t length);
 int __mei_cl_send(struct mei_cl *cl, u8 *buf, size_t length);
 int __mei_cl_recv(struct mei_cl *cl, u8 *buf, size_t length);
 void mei_cl_bus_rx_event(struct mei_cl *cl);
+void mei_cl_bus_remove_devices(struct mei_device *dev);
 int mei_cl_bus_init(void);
 void mei_cl_bus_exit(void);
 
index a58320c0c049c7342ca3d912e4f427bd487381de..7626dde5e1f53cae64b9e4a76d3a9b089a917ff0 100644 (file)
@@ -552,13 +552,7 @@ err:
 void mei_nfc_host_exit(struct mei_device *dev)
 {
        struct mei_nfc_dev *ndev = &nfc_dev;
-
        cancel_work_sync(&ndev->init_work);
+}
 
-       mutex_lock(&dev->device_lock);
-       if (ndev->cl && ndev->cl->device)
-               mei_cl_remove_device(ndev->cl->device);
 
-       mei_nfc_free(ndev);
-       mutex_unlock(&dev->device_lock);
-}