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: 794764 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);