From patchwork Thu May 2 11:38:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans Verkuil X-Patchwork-Id: 13651637 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 60A2D42044 for ; Thu, 2 May 2024 11:40:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714650008; cv=none; b=qFr1dKlbmBjC01W1vnzuBGe1f0ks1rD0ssYeVThSHIkFMX8MuEG33VgBAfIWmLtAL2xySUB8/5O3JLxtPcyCkku/d1GpFUJA4f18UImqujRRYkAC5zQ2M57gkq+mLDvDPT3w5M+9fHEBk5gtI/kB5WYX/G8Wu/9UPwNB/HV7OHw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714650008; c=relaxed/simple; bh=RTFy8zQW55Cx7n1Ay0Gu4qa7jplIYCQqMVCptBa45Qo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=bpOMMWN3xYqdaJZ+GLjuK6M/VI+RlpAlExwoo+Gp6jXjp8oqlSvPEdXT3o/Oe0oMCVea0Te31gToYPh2JUQUB5tM7oxcP5/zQfJOf6Ljw215z+25IZoOCo80dj9PSgHukEMba/goLCyzy5jql/wwnAT6Bonn6PpYZch4fPjlnho= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id BC3FDC4AF18; Thu, 2 May 2024 11:40:06 +0000 (UTC) From: Hans Verkuil To: linux-media@vger.kernel.org Cc: Yang, Chenyuan , Takashi Iwai , Hans Verkuil Subject: [PATCH for v6.10 1/4] media: cec: cec-adap: always cancel work in cec_transmit_msg_fh Date: Thu, 2 May 2024 13:38:41 +0200 Message-ID: X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Do not check for !data->completed, just always call cancel_delayed_work_sync(). This fixes a small race condition. Signed-off-by: Hans Verkuil Reported-by: Yang, Chenyuan Fixes: 490d84f6d73c ("media: cec: forgot to cancel delayed work") Closes: https://lore.kernel.org/linux-media/PH7PR11MB57688E64ADE4FE82E658D86DA09EA@PH7PR11MB5768.namprd11.prod.outlook.com/ --- drivers/media/cec/core/cec-adap.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/media/cec/core/cec-adap.c b/drivers/media/cec/core/cec-adap.c index 559a172ebc6cb..6fc7de744ee9a 100644 --- a/drivers/media/cec/core/cec-adap.c +++ b/drivers/media/cec/core/cec-adap.c @@ -936,8 +936,7 @@ int cec_transmit_msg_fh(struct cec_adapter *adap, struct cec_msg *msg, */ mutex_unlock(&adap->lock); wait_for_completion_killable(&data->c); - if (!data->completed) - cancel_delayed_work_sync(&data->work); + cancel_delayed_work_sync(&data->work); mutex_lock(&adap->lock); /* Cancel the transmit if it was interrupted */ From patchwork Thu May 2 11:38:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans Verkuil X-Patchwork-Id: 13651638 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B39B142044 for ; Thu, 2 May 2024 11:40:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714650009; cv=none; b=a4ZKQr64lWjlgmwcG9lqimis0Ncqbepjoa4qr2tvzZR38ycyp0vtGQVwu3ptUdbL/QxoVFmDEbym9Vqoz4G0kSqX4UUMaJ8k/rm1HldCn4EzW4RytgqE+SZUkCujE8BOd3e53ZkFHsNIiB7ssFfFYsuD0gzbQzFjoBGK0Q+PjTs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714650009; c=relaxed/simple; bh=W9HhDBpWeQe3XEfwcqjtQLoQU2nNZhK5NboNW/GmizI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=FmKV0OaVTFCGppMnfpZAYGQvU+3utmhH51NfVZpjJmBnYsQCDkjRdY57nsl0IaAPdYzr1aoFxWUU4HSYUyF5gzGRs0CxNDQ0BpvqqINpQ+s0AkS4ldIYsY5hNfTF2JqiNIzAuoiVrtzaW40Fdn+mFr9/CBq4RDbdx0RFPvuoN60= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5F993C113CC; Thu, 2 May 2024 11:40:08 +0000 (UTC) From: Hans Verkuil To: linux-media@vger.kernel.org Cc: Yang, Chenyuan , Takashi Iwai , Hans Verkuil Subject: [PATCH for v6.10 2/4] media: cec: cec-api: add locking in cec_release() Date: Thu, 2 May 2024 13:38:42 +0200 Message-ID: X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 When cec_release() uses fh->msgs it has to take fh->lock, otherwise the list can get corrupted. Signed-off-by: Hans Verkuil Reported-by: Yang, Chenyuan Fixes: ca684386e6e2 ("[media] cec: add HDMI CEC framework (api)") Closes: https://lore.kernel.org/linux-media/PH7PR11MB57688E64ADE4FE82E658D86DA09EA@PH7PR11MB5768.namprd11.prod.outlook.com/ --- drivers/media/cec/core/cec-api.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/media/cec/core/cec-api.c b/drivers/media/cec/core/cec-api.c index 67dc79ef17050..d64bb716f9c68 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); From patchwork Thu May 2 11:38:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans Verkuil X-Patchwork-Id: 13651639 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9B2AB42044 for ; Thu, 2 May 2024 11:40:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714650011; cv=none; b=gU2kb1x+vEv6Rxk0rcvbaAKttOZiWcFTKAsg7EHOnyhY0ZVvnWYXrMbQBnti3oQE1/TrEwC+VhiyRIsxnxC1ZhQ1teAqRkb1Jh7+jM3SoH3hH1vVVHGzxTqDBs27ZyQKljilrbphqZwVNy+465b+Tlo3JI2QGi3T6B6qF1BGkNQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714650011; c=relaxed/simple; bh=oz/kHA1GN13RsL69d5OjezLReqkEAfvQ61QcvOqwfoA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=tmOdTnRfcRame1sbvsMYQYQdEjeuYolHI9TsH0J2+5ZYPem1B8yHcarLBkcOB9AR4MVbJ0miJ46SBss10OTWZFC5XOlOvwn0nugonbFdCbk4EQAjSEMJ0MMF3/WW6AWK66UhvVWGCfQN95p1kn01PGxGyQ/MLXJiRK823iOppTQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0324FC4AF19; Thu, 2 May 2024 11:40:09 +0000 (UTC) From: Hans Verkuil To: linux-media@vger.kernel.org Cc: Yang, Chenyuan , Takashi Iwai , Hans Verkuil Subject: [PATCH for v6.10 3/4] media: cec: core: avoid recursive cec_claim_log_addrs Date: Thu, 2 May 2024 13:38:43 +0200 Message-ID: <171a0747fe4a63e8e85fb747738dfd528162843c.1714649924.git.hverkuil-cisco@xs4all.nl> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Keep track if cec_claim_log_addrs() is running, and return -EBUSY if it is when calling CEC_ADAP_S_LOG_ADDRS. This prevents a case where cec_claim_log_addrs() could be called while it was still in progress. Signed-off-by: Hans Verkuil Reported-by: Yang, Chenyuan Fixes: ca684386e6e2 ("[media] cec: add HDMI CEC framework (api)") Closes: https://lore.kernel.org/linux-media/PH7PR11MB57688E64ADE4FE82E658D86DA09EA@PH7PR11MB5768.namprd11.prod.outlook.com/ --- drivers/media/cec/core/cec-adap.c | 6 +++++- drivers/media/cec/core/cec-api.c | 2 +- include/media/cec.h | 1 + 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/drivers/media/cec/core/cec-adap.c b/drivers/media/cec/core/cec-adap.c index 6fc7de744ee9a..a493cbce24567 100644 --- a/drivers/media/cec/core/cec-adap.c +++ b/drivers/media/cec/core/cec-adap.c @@ -1574,9 +1574,12 @@ static int cec_config_thread_func(void *arg) */ static void cec_claim_log_addrs(struct cec_adapter *adap, bool block) { - if (WARN_ON(adap->is_configuring || adap->is_configured)) + if (WARN_ON(adap->is_claiming_log_addrs || + adap->is_configuring || adap->is_configured)) return; + adap->is_claiming_log_addrs = true; + init_completion(&adap->config_completion); /* Ready to kick off the thread */ @@ -1591,6 +1594,7 @@ static void cec_claim_log_addrs(struct cec_adapter *adap, bool block) wait_for_completion(&adap->config_completion); mutex_lock(&adap->lock); } + adap->is_claiming_log_addrs = false; } /* diff --git a/drivers/media/cec/core/cec-api.c b/drivers/media/cec/core/cec-api.c index d64bb716f9c68..3ef9153443044 100644 --- a/drivers/media/cec/core/cec-api.c +++ b/drivers/media/cec/core/cec-api.c @@ -178,7 +178,7 @@ static long cec_adap_s_log_addrs(struct cec_adapter *adap, struct cec_fh *fh, CEC_LOG_ADDRS_FL_ALLOW_RC_PASSTHRU | CEC_LOG_ADDRS_FL_CDC_ONLY; mutex_lock(&adap->lock); - if (!adap->is_configuring && + if (!adap->is_claiming_log_addrs && !adap->is_configuring && (!log_addrs.num_log_addrs || !adap->is_configured) && !cec_is_busy(adap, fh)) { err = __cec_s_log_addrs(adap, &log_addrs, block); diff --git a/include/media/cec.h b/include/media/cec.h index c8350258f10af..d3abe84c9c9e5 100644 --- a/include/media/cec.h +++ b/include/media/cec.h @@ -258,6 +258,7 @@ struct cec_adapter { u16 phys_addr; bool needs_hpd; bool is_enabled; + bool is_claiming_log_addrs; bool is_configuring; bool must_reconfigure; bool is_configured; From patchwork Thu May 2 11:38:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans Verkuil X-Patchwork-Id: 13651640 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4248942044 for ; Thu, 2 May 2024 11:40:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714650013; cv=none; b=NFfkhaJ8aJiaNJSqb10yPCKCUdL+Q6Hra+Dt8ZUTMBFW2LA1AqtfG32TjS+Lzco6pt6XlNWt/EeQJsSQAYH3b3GgSddKIBQU3y7IuQ9MWpZ+geyBTYkaCWBMsag3YyD1+ZVuP+WqcggSZtwaNj6wyW8KRdciKUIdh6RdmgnsOl0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714650013; c=relaxed/simple; bh=901TALhbGZrRgq1DIhVpSvuYy4QnaG9XUMO2wUCLjc0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=BRqHW0ahuLRRF7pSgCPzxmLfrnuLLv8KztHffwZxGVMkYrn2xn9YnYLZjPFSOfymi9beIbogTiZyrBtjhFLMr2jlB5dSUYx2Uy6ISV67hdLLiAfKNkFRML+5UmfiatEXajqOjS7E8r/+Iips0zitm4G15GwL6WvksCk1T07xPoQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9AD40C113CC; Thu, 2 May 2024 11:40:11 +0000 (UTC) From: Hans Verkuil To: linux-media@vger.kernel.org Cc: Yang, Chenyuan , Takashi Iwai , Hans Verkuil Subject: [PATCH for v6.10 4/4] media: cec: core: avoid confusing "transmit timed out" message Date: Thu, 2 May 2024 13:38:44 +0200 Message-ID: <70b13fcf5d43b567595fd7d4b25157ae793ab09c.1714649924.git.hverkuil-cisco@xs4all.nl> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 If, when waiting for a transmit to finish, the wait is interrupted, then you might get a "transmit timed out" message, even though the transmit was interrupted and did not actually time out. Set transmit_in_progress_aborted to true if the wait_for_completion_killable() call was interrupted and ensure that the transmit is properly marked as ABORTED. Signed-off-by: Hans Verkuil Reported-by: Yang, Chenyuan Fixes: 590a8e564c6ef ("media: cec: abort if the current transmit was canceled") Closes: https://lore.kernel.org/linux-media/PH7PR11MB57688E64ADE4FE82E658D86DA09EA@PH7PR11MB5768.namprd11.prod.outlook.com/ --- drivers/media/cec/core/cec-adap.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/drivers/media/cec/core/cec-adap.c b/drivers/media/cec/core/cec-adap.c index a493cbce24567..da09834990b87 100644 --- a/drivers/media/cec/core/cec-adap.c +++ b/drivers/media/cec/core/cec-adap.c @@ -490,6 +490,15 @@ int cec_thread_func(void *_adap) goto unlock; } + if (adap->transmit_in_progress && + adap->transmit_in_progress_aborted) { + if (adap->transmitting) + cec_data_cancel(adap->transmitting, + CEC_TX_STATUS_ABORTED, 0); + adap->transmit_in_progress = false; + adap->transmit_in_progress_aborted = false; + goto unlock; + } if (adap->transmit_in_progress && timeout) { /* * If we timeout, then log that. Normally this does @@ -771,6 +780,7 @@ int cec_transmit_msg_fh(struct cec_adapter *adap, struct cec_msg *msg, { struct cec_data *data; bool is_raw = msg_is_raw(msg); + int err; if (adap->devnode.unregistered) return -ENODEV; @@ -935,10 +945,13 @@ 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); + err = wait_for_completion_killable(&data->c); cancel_delayed_work_sync(&data->work); mutex_lock(&adap->lock); + if (err) + adap->transmit_in_progress_aborted = true; + /* Cancel the transmit if it was interrupted */ if (!data->completed) { if (data->msg.tx_status & CEC_TX_STATUS_OK)