[media] cec: improve flushing queue

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>
This commit is contained in:
Hans Verkuil 2017-02-10 13:02:31 -02:00 committed by Mauro Carvalho Chehab
parent b94dffd65c
commit b39f93efc6

View 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;
}