From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795058047; b=X6WRGjl62U1fCLbGeHl2iXQ//gAzn5+P7ep0ayvEX72n9VLjC3gUkM6B8HS+9fFzPM2g Hy+HIt8kGF8DPuCdkSblj6Vv+gpqBJW4ive6ng23eKMtZU2DaUht0H2j6emQF3UYxCzry niXm09flsU8fbjy15NJBhLDtPKSzWJsNvisBjHR9HJmice9PPGNi08PJD83vcxz5uMQww CsVyuiRuJIi+6DRGBpNt84/KP9BidzqeByAXI3Wma4ATjOZxOwSQ8evP54XeTGtQY+s4g I+uB8U7QwAjSFYC1fT0d3JHcwIj8zkUaoMi4pL8IJOPCXX4GPVNYN2AgtP9Dy7Yitzw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795058047; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=XNnSAt5U3jiRdRp5cLUhMuoidVTq66Y8HGngKYhHMTQ=; b=t33kdwkJDw9B/UcU3/EAfhW3R0ciJE9VjHCP8PbzbHCiE4VgnmqIfrnGhlWxjQv4Ma6I Gy+WMMSRUikpKZ+Nikxi4s3rCoCWBpNj7msxkuruHuVk5dkvMOU1XOb9ElMr0LZFI6RYC ctvJ4sb4zGKEfFJXTgW9AWDRjrmiJR338iHnpDulwv9Hk0H0MDJVAmbk4NTiDIF/+OYOo TdqgH1atvybjLk0rOm2uNebRU88Zgt1K9wq3fZy5wX140LojWMLbBCyU3fmNuXtD0zhHv 9JVeyfP3rJ+3COq1v9J4uhN2aqbeladB/J2T33RdJFTlbInFz7Ac5jNxU25ie0DPiNA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=vMwrwBlL; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 50B26606A31C; Thu, 19 Nov 2026 03:14:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=vMwrwBlL Received: by smtp.kernel.org (Postfix) with ESMTPSA id A1F401F000C4; Thu, 19 Nov 2026 03:14:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1795058047; bh=XNnSAt5U3jiRdRp5cLUhMuoidVTq66Y8HGngKYhHMTQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=vMwrwBlLIph4YOOtAwGNPvenG92a2gLY96CYUB4wROtfNlzdlx4O89UA7HFuqs8Gw h9vkW44GkypsLTtDAWuWUdvZiQnbPpsN4Uxx6Yx1N88xRtTMJWF+ByvJlEManvgKWf jm1OqmV18hzFmcsfp0uEhSqzuAdqmXtR1IFYA7Yo= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Sean Young , Hans Verkuil , Sasha Levin Subject: [PATCH 5.10 0345/1848] media: rc: Fix ABBA deadlock by making locks more fine grained Date: Wed, 18 Nov 2026 15:39:43 +0100 Message-ID: <20261118145927.085978758@linuxfoundation.org> X-Mailer: git-send-email 2.56.0 In-Reply-To: <20261118145911.150052362@linuxfoundation.org> References: <20261118145911.150052362@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: patches@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 5.10-stable review patch. If anyone has any objections, please let me know. ------------------ From: Sean Young [ Upstream commit c6d68866ad8aa1e957a3e5a6ede971148f1e3d59 ] The ir_raw_event_unregister() function takes the ir_raw_handler_lock first and then the rc_dev->lock. Other functions like change_protocol do this in the reverse order. This means that an ir decoder module unload and writing to the protocol sysfs file can cause a deadlock. ir_raw_handler_lock protects the client list, amongst other things. Split this out into a separate lock so we can ensure the locking order is always the same. Fixes: 93cffffc18f6 ("[media] media: rc: fix decoder module unloading") Signed-off-by: Sean Young Cc: stable@vger.kernel.org Acked-by: Hans Verkuil [ sashal: replaced unavailable lockdep_assert_not_held() with a CONFIG_LOCKDEP-guarded WARN_ON(debug_locks && lockdep_is_held(&dev->lock)) check ] Signed-off-by: Sasha Levin --- drivers/media/rc/rc-ir-raw.c | 40 +++++++++++++++++++++++------------- 1 file changed, 26 insertions(+), 14 deletions(-) diff --git a/drivers/media/rc/rc-ir-raw.c b/drivers/media/rc/rc-ir-raw.c index c65bba4ec4739..d5f960b3d1a47 100644 --- a/drivers/media/rc/rc-ir-raw.c +++ b/drivers/media/rc/rc-ir-raw.c @@ -10,7 +10,8 @@ #include #include "rc-core-priv.h" -/* Used to keep track of IR raw clients, protected by ir_raw_handler_lock */ +/* Used to keep track of IR raw clients, protected by ir_raw_client_lock */ +static DEFINE_MUTEX(ir_raw_client_lock); static LIST_HEAD(ir_raw_client_list); /* Used to handle IR raw handler extensions */ @@ -290,13 +291,6 @@ static int change_protocol(struct rc_dev *dev, u64 *rc_proto) return 0; } -static void ir_raw_disable_protocols(struct rc_dev *dev, u64 protocols) -{ - mutex_lock(&dev->lock); - dev->enabled_protocols &= ~protocols; - mutex_unlock(&dev->lock); -} - /** * ir_raw_gen_manchester() - Encode data with Manchester (bi-phase) modulation. * @ev: Pointer to pointer to next free event. *@ev is incremented for @@ -634,15 +628,20 @@ int ir_raw_event_register(struct rc_dev *dev) { struct task_struct *thread; + /* Holding dev->lock could result in a dead-lock */ +#ifdef CONFIG_LOCKDEP + WARN_ON(debug_locks && lockdep_is_held(&dev->lock)); +#endif + thread = kthread_run(ir_raw_event_thread, dev->raw, "rc%u", dev->minor); if (IS_ERR(thread)) return PTR_ERR(thread); dev->raw->thread = thread; - mutex_lock(&ir_raw_handler_lock); + mutex_lock(&ir_raw_client_lock); list_add_tail(&dev->raw->list, &ir_raw_client_list); - mutex_unlock(&ir_raw_handler_lock); + mutex_unlock(&ir_raw_client_lock); return 0; } @@ -666,8 +665,10 @@ void ir_raw_event_unregister(struct rc_dev *dev) kthread_stop(dev->raw->thread); del_timer_sync(&dev->raw->edge_handle); - mutex_lock(&ir_raw_handler_lock); + mutex_lock(&ir_raw_client_lock); list_del(&dev->raw->list); + + mutex_lock(&ir_raw_handler_lock); list_for_each_entry(handler, &ir_raw_handler_list, list) if (handler->raw_unregister && (handler->protocols & dev->enabled_protocols)) @@ -683,6 +684,8 @@ void ir_raw_event_unregister(struct rc_dev *dev) * "device gone" is checked. */ mutex_unlock(&ir_raw_handler_lock); + + mutex_unlock(&ir_raw_client_lock); } /* @@ -705,15 +708,24 @@ void ir_raw_handler_unregister(struct ir_raw_handler *ir_raw_handler) struct ir_raw_event_ctrl *raw; u64 protocols = ir_raw_handler->protocols; + mutex_lock(&ir_raw_client_lock); + mutex_lock(&ir_raw_handler_lock); list_del(&ir_raw_handler->list); + atomic64_andnot(protocols, &available_protocols); + mutex_unlock(&ir_raw_handler_lock); + list_for_each_entry(raw, &ir_raw_client_list, list) { + mutex_lock(&raw->dev->lock); + mutex_lock(&ir_raw_handler_lock); if (ir_raw_handler->raw_unregister && (raw->dev->enabled_protocols & protocols)) ir_raw_handler->raw_unregister(raw->dev); - ir_raw_disable_protocols(raw->dev, protocols); + raw->dev->enabled_protocols &= ~protocols; + mutex_unlock(&ir_raw_handler_lock); + mutex_unlock(&raw->dev->lock); } - atomic64_andnot(protocols, &available_protocols); - mutex_unlock(&ir_raw_handler_lock); + + mutex_unlock(&ir_raw_client_lock); } EXPORT_SYMBOL(ir_raw_handler_unregister); -- 2.53.0