diff --git a/drivers/media/cec/core/cec-adap.c b/drivers/media/cec/core/cec-adap.c index 5741adf09a2e..d94f92b7dc80 100644 --- a/drivers/media/cec/core/cec-adap.c +++ b/drivers/media/cec/core/cec-adap.c @@ -935,9 +935,8 @@ int cec_transmit_msg_fh(struct cec_adapter *adap, struct cec_msg *msg, * Release the lock and wait, retake the lock afterwards. */ mutex_unlock(&adap->lock); - wait_for_completion_killable(&data->c); - if (!data->completed) - cancel_delayed_work_sync(&data->work); + wait_for_completion_killable_timeout(&data->c, msecs_to_jiffies(adap->xfer_timeout_ms + 1000)); + cancel_delayed_work_sync(&data->work); mutex_lock(&adap->lock); /* Cancel the transmit if it was interrupted */ @@ -1563,10 +1562,12 @@ static int cec_config_thread_func(void *arg) cec_transmit_msg_fh(adap, &msg, NULL, false); } } + mutex_unlock(&adap->lock); + call_void_op(adap, configured); + mutex_lock(&adap->lock); adap->kthread_config = NULL; complete(&adap->config_completion); mutex_unlock(&adap->lock); - call_void_op(adap, configured); return 0; unconfigure: @@ -1592,6 +1593,12 @@ static void cec_claim_log_addrs(struct cec_adapter *adap, bool block) if (WARN_ON(adap->is_configuring || adap->is_configured)) return; + if (adap->kthread_config) { + mutex_unlock(&adap->lock); + wait_for_completion(&adap->config_completion); + mutex_lock(&adap->lock); + } + init_completion(&adap->config_completion); /* Ready to kick off the thread */ @@ -1599,8 +1606,8 @@ static void cec_claim_log_addrs(struct cec_adapter *adap, bool block) adap->kthread_config = kthread_run(cec_config_thread_func, adap, "ceccfg-%s", adap->name); if (IS_ERR(adap->kthread_config)) { - adap->kthread_config = NULL; adap->is_configuring = false; + adap->kthread_config = NULL; } else if (block) { mutex_unlock(&adap->lock); wait_for_completion(&adap->config_completion); diff --git a/drivers/media/cec/core/cec-api.c b/drivers/media/cec/core/cec-api.c index 67dc79ef1705..d64bb716f9c6 100644 --- a/drivers/media/cec/core/cec-api.c +++ b/drivers/media/cec/core/cec-api.c @@ -664,6 +664,8 @@ static int cec_release(struct inode *inode, struct file *filp) list_del_init(&data->xfer_list); } mutex_unlock(&adap->lock); + + mutex_lock(&fh->lock); while (!list_empty(&fh->msgs)) { struct cec_msg_entry *entry = list_first_entry(&fh->msgs, struct cec_msg_entry, list); @@ -681,6 +683,7 @@ static int cec_release(struct inode *inode, struct file *filp) kfree(entry); } } + mutex_unlock(&fh->lock); kfree(fh); cec_put_device(devnode);