]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/commitdiff
[media] cec: improve flushing queue
authorHans Verkuil <hans.verkuil@cisco.com>
Fri, 10 Feb 2017 15:02:31 +0000 (13:02 -0200)
committerMauro Carvalho Chehab <mchehab@s-opensource.com>
Wed, 22 Mar 2017 14:09:04 +0000 (11:09 -0300)
When the adapter is unloaded or unconfigured, then all transmits and
pending waits should be flushed.

Move this code into its own function and improve the code that cancels
delayed work to avoid having to unlock adap->lock.

Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@s-opensource.com>
drivers/media/cec/cec-adap.c

index ccda41c2c9e41ed37969280420b7d98609c6641b..421472b492ee87c28a1c78deeb371252ceeb2b8a 100644 (file)
@@ -299,6 +299,40 @@ static void cec_data_cancel(struct cec_data *data)
        cec_data_completed(data);
 }
 
+/*
+ * Flush all pending transmits and cancel any pending timeout work.
+ *
+ * This function is called with adap->lock held.
+ */
+static void cec_flush(struct cec_adapter *adap)
+{
+       struct cec_data *data, *n;
+
+       /*
+        * If the adapter is disabled, or we're asked to stop,
+        * then cancel any pending transmits.
+        */
+       while (!list_empty(&adap->transmit_queue)) {
+               data = list_first_entry(&adap->transmit_queue,
+                                       struct cec_data, list);
+               cec_data_cancel(data);
+       }
+       if (adap->transmitting)
+               cec_data_cancel(adap->transmitting);
+
+       /* Cancel the pending timeout work. */
+       list_for_each_entry_safe(data, n, &adap->wait_queue, list) {
+               if (cancel_delayed_work(&data->work))
+                       cec_data_cancel(data);
+               /*
+                * If cancel_delayed_work returned false, then
+                * the cec_wait_timeout function is running,
+                * which will call cec_data_completed. So no
+                * need to do anything special in that case.
+                */
+       }
+}
+
 /*
  * Main CEC state machine
  *
@@ -350,37 +384,7 @@ int cec_thread_func(void *_adap)
 
                if ((!adap->is_configured && !adap->is_configuring) ||
                    kthread_should_stop()) {
-                       /*
-                        * If the adapter is disabled, or we're asked to stop,
-                        * then cancel any pending transmits.
-                        */
-                       while (!list_empty(&adap->transmit_queue)) {
-                               data = list_first_entry(&adap->transmit_queue,
-                                                       struct cec_data, list);
-                               cec_data_cancel(data);
-                       }
-                       if (adap->transmitting)
-                               cec_data_cancel(adap->transmitting);
-
-                       /*
-                        * Cancel the pending timeout work. We have to unlock
-                        * the mutex when flushing the work since
-                        * cec_wait_timeout() will take it. This is OK since
-                        * no new entries can be added to wait_queue as long
-                        * as adap->transmitting is NULL, which it is due to
-                        * the cec_data_cancel() above.
-                        */
-                       while (!list_empty(&adap->wait_queue)) {
-                               data = list_first_entry(&adap->wait_queue,
-                                                       struct cec_data, list);
-
-                               if (!cancel_delayed_work(&data->work)) {
-                                       mutex_unlock(&adap->lock);
-                                       flush_scheduled_work();
-                                       mutex_lock(&adap->lock);
-                               }
-                               cec_data_cancel(data);
-                       }
+                       cec_flush(adap);
                        goto unlock;
                }