From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.210.178 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796010491; b=BN4D8AyG+rO1915TFPwQtn9KHOnMpeWyYkAObWRfrYMHPnt6vgv0y5GQpVbHyZHx5Se+ B+jqr8fKxW6YtK2HTJJ63UdDdj9p0X9L+mi0UUuKOTPqW/5uM+/Hrdt42pDSCgufmdJeL yUoO5TGeK2Fa1TDekiw9WLfI1uqYgXlqZyhRQ9BtpGzN7ZsYmyYo+wgw4z4CeF/tLW1CQ p56Xh7IDguUd027PD6uhnzeN0Igg7NyNFtehnizBf+bBtDpvvo3/I/VbKEr3hEcEXAJy4 HpQMnsu7QCv7IXpYjZ7buiks98JiYDjBL93klHmK5IdSsknWsvmBOOtOUYu8Fqa/7kA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796010491; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: From:To:Cc:Subject:Date:Message-ID:X-Mailer:In-Reply-To:References: MIME-Version:Content-Transfer-Encoding; bh=GgI1qJM0gQu9lb6/SFF/sQm7kSnyZh/UVGfvKAr1AfY=; b=wOMe0WWYApCeogDkNB+/cj28kOM0lOPN0+uGLx+K3uPhuRhzz+f5f/F7dy3vqZghlcI/ 8n6vDmUJpE3HLK4YWS4/UssWWD1FdZAO/QA2Zeu137BUqJc9Pc+bBVIZsRaNsKLPwAi3h eVpo/OL/QS5g+aGZtP8mfe7IO9jG6KE8yEpQrAsFcHy3J37edYnABGxbmr70B8KhgAb+Z wy6Gc6NJzs3VYuKX9srfl0U1/ZQkwobabWnujFshUcS4rILbzgQA6JmZjLJzffnk7jmzm ZtVilxBi5A5aF4os0UhCT1JXEvPvIG+SCjrmuiZn3zicWoXLQHRdP3Q+ARcSBjvlk+g== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=TcDuhOBR; arc=none smtp.remote-ip=209.85.210.178 Received: from mail-pf1-f178.google.com (mail-pf1-f178.google.com [209.85.210.178]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E4406606A33A for ; Mon, 30 Nov 2026 03:48:10 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org E4406606A33A Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=TcDuhOBR Received: by mail-pf1-f178.google.com with SMTP id d2e1a72fcca58-8b58d6f67a5so4811038b3a.2 for ; Sun, 29 Nov 2026 19:48:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796010490; x=1796615290; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=GgI1qJM0gQu9lb6/SFF/sQm7kSnyZh/UVGfvKAr1AfY=; b=TcDuhOBRcFOscQ8HnFhPPw2PhEk2/alfVxoEEu6OrVmgzh/S+Ph9fWNdX7sJumxYoO rLTwPQb24OU6O+gyspZ7Y7R7wzvonhA8KahZsYXII5y9kaoFWwtc1XMClrj0gWuyuuso WdmVXWd7C+yI6obZPGvKl49Cet42jEvrdC1C0GjBSCph+TiBXzLtGhi2BiojlMVFLiwx LzGMBbHayFH2w2yap647ssNC+/hPsgRydMPwVjUs2w9ZQAvx0m5isPhMQOvDWMtX+uGF O1JE7CPU87X9gfwf7PDv2MQruEASBJvN4dxL1C4KgEcK7dGf/oVnnz1jMOuU6f4/mNq8 qeew== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796010490; x=1796615290; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=GgI1qJM0gQu9lb6/SFF/sQm7kSnyZh/UVGfvKAr1AfY=; b=OnuHA+7gvoqbCEPKEXX5IXbN12JKIbI57NSXV1jGl3uFQQf1txKZTupDeR0mJH/pFM zs2ZUyrtMlUpjzGsz0NxY1UTDVIlJYrn7ogGWFd7kYNeF4eGpMoTLVA/qF8WF1w9LEzl YdAEkDzRxgbWRUuibrJEzLeL7pnjb7OIPg6sJz0D6tF009pnuZbKOomA5daFIMYte/37 Eq4aoQokl8FFEZPh/3u9xgYrlXh8oxQuBs0Jd6P6GnIWXtpVMLZfm1M4qYoz2qKGY4xF NPZzKy0TJ6JlYUZoVR7Bw54fmqoltEjl/pryUEoI8C06yCKUaoY583zR9id1JaSwfUoT 2agw== X-Forwarded-Encrypted: i=1; AL+hErH4cqJlCmnFo5z3iFDGgHuTbvbZSm4JuQsSe7e/FpZP+xsCE5jUtvQbOcrCD/g0A/2WrhXMhmBGPwfXhA==@vger.kernel.org X-Gm-Message-State: APuU4Z8kL+YWhB8Qs6YnPdQn345doiCEqUTOoK7muMdpLYuX1SjvLfSz bJ7miJcPFHg3ps29fCaviBl2+Ilt9sgS9uBYTxf2bBSRuErM8ngZdK9p X-Gm-Gg: AZFdTZfHlL0vWbzr9fMbX2/bLJ/DaBS4+zxAr3qdGj1KIR41pfqxB8+8dv42HPh3HSW PDTCr7FCqtK2qAbpjEfIPEXteMf0tDwrWhQQG0Xk9CkZN6VOFN1A+SSmXRQvlr32RyDoxapBLpw iFG+eWME166KYtcSmZfoE1FlTBybkQYjJZcYl5bagdx7912NLRVyExbzlP9s4PqgFN83ZwswslZ 4nqApBocjqpOg3/l0Vh1K8DPDKjeDPIkdDwPMZAfclxO+k0Q3Qk4hdp+txLKkSzVSQyRPnu2Ugv 0dva9Dhqpy0TIviU9F1IOMV9GY6+XX2WJaDMoMCilOPcxJAJest5WfQbusGxwG072KD9RAQ6pbL wpetT9qBm2YXKuz7Cjx7HRfubABloaTlvnzeJ7y378tesb0L+PAwueO1O/AEqtyT0Re1aOx7jBZ SD4Bx4RV5pXrkDEBQ5FK4H5Jzqwu34k7uuzMH+gOLOySWqEpIsJL8aq81rqioU37KxSEd1/X5Tn RYd8a+aXz3cVwXjCYf2oHkhEOgN7DqmZdHEKNzg0/e98lM9PG+317pT0CoUE3nHF7Ek472qX3Re 6FSvHvwnYd6xrzHsK4fNvqqI2q35uSwn9MwLlb7mLR8UdbFwok2AY9k5ThyknMENoidm5ba3T/U VSmFVdfU= X-Received: by 2002:a05:6a00:9283:b0:8b0:5438:86a4 with SMTP id d2e1a72fcca58-8c87bdb534dmr31915268b3a.16.1796010490190; Sun, 29 Nov 2026 19:48:10 -0800 (PST) Received: from DESKTOP-TPPBPA1 (36-226-254-86.dynamic-ip.hinet.net. [36.226.254.86]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-8ca64ec4b9esm14602129b3a.24.2026.11.29.19.48.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 29 Nov 2026 19:48:09 -0800 (PST) From: Lin Tzu Yang To: Liam Girdwood , Mark Brown Cc: Jaroslav Kysela , Takashi Iwai , Dmitry Baryshkov , linux-sound@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 2/2] ASoC: hdmi-codec: Hold the lock while the ELD is updated or read Date: Mon, 30 Nov 2026 11:48:00 +0800 Message-ID: <20261130034800.824934-3-rongh7426@gmail.com> X-Mailer: git-send-email 2.51.1.windows.1 In-Reply-To: <20261130034800.824934-1-rongh7426@gmail.com> References: <20261130034800.824934-1-rongh7426@gmail.com> X-Mailing-List: linux-sound@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit plugged_cb() rewrites hcp->eld and hcp->eld_parsed without taking hcp->lock, while the ELD control, the ELD proc file and hw_params read them without it too. Only startup() takes the lock. A reader that runs during a hotplug can see a half-copied or half-cleared ELD. On a Raspberry Pi 5 (vc4) I toggled the connector between forced off and on while reading the ELD control in a loop. In 120 seconds 3 of about 266 million reads returned an ELD that was neither the monitor's nor all zero: the header copied and the rest still zero, or the first 16 bytes cleared and the monitor name still there. Take hcp->lock around the ELD update in plugged_cb() and around the readers. None of the drivers that call plugged_cb() take a lock that startup() also takes under hcp->lock, so this adds no lock inversion. With this patch the same test gave no torn reads in about 255 million reads, and repeated playback during hotplug still worked with no hung tasks. Tested as an out-of-tree module on 6.18.39. The problem was found by the sashiko review bot, and the patch was written with the help of an AI coding assistant (Claude). I reproduced it, tested it on hardware and reviewed the change. Fixes: 25ce4f2b3593 ("ASoC: hdmi-codec: Get ELD in before reporting plugged event") Fixes: 0ecd24a6d8b2 ("ASoC: hdmi-codec: dump ELD through procfs") Signed-off-by: Lin Tzu Yang --- v2: rebased on v2 of patch 1; the unplug path takes the lock only around the memsets and reports the jack after dropping it. Build tested; runtime testing above was on v1. sound/soc/codecs/hdmi-codec.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/sound/soc/codecs/hdmi-codec.c b/sound/soc/codecs/hdmi-codec.c index 7946f61..d3bbca2 100644 --- a/sound/soc/codecs/hdmi-codec.c +++ b/sound/soc/codecs/hdmi-codec.c @@ -318,6 +318,7 @@ static int hdmi_eld_ctl_get(struct snd_kcontrol *kcontrol, struct snd_soc_component *component = snd_kcontrol_chip(kcontrol); struct hdmi_codec_priv *hcp = snd_soc_component_get_drvdata(component); + guard(mutex)(&hcp->lock); memcpy(ucontrol->value.bytes.data, hcp->eld, sizeof(hcp->eld)); return 0; @@ -526,7 +527,8 @@ static int hdmi_codec_fill_codec_params(struct snd_soc_dai *dai, if (pcm_audio) { /* Select a channel allocation that matches with ELD and pcm channels */ - idx = hdmi_codec_get_ch_alloc_table_idx(hcp, channels); + scoped_guard(mutex, &hcp->lock) + idx = hdmi_codec_get_ch_alloc_table_idx(hcp, channels); if (idx < 0) { dev_err(dai->dev, "Not able to map channels to speakers (%d)\n", @@ -841,6 +843,7 @@ static void print_eld_info(struct snd_info_entry *entry, { struct hdmi_codec_priv *hcp = entry->private_data; + guard(mutex)(&hcp->lock); snd_print_eld_info(&hcp->eld_parsed, buffer); } @@ -960,6 +963,7 @@ static void plugged_cb(struct device *dev, bool plugged) if (plugged) { if (hcp->hcd.ops->get_eld) { + guard(mutex)(&hcp->lock); hcp->hcd.ops->get_eld(dev->parent, hcp->hcd.data, hcp->eld, sizeof(hcp->eld)); ret = snd_parse_eld(dev, &hcp->eld_parsed, @@ -971,8 +975,10 @@ static void plugged_cb(struct device *dev, bool plugged) } hdmi_codec_jack_report(hcp, SND_JACK_AVOUT); } else { - memset(hcp->eld, 0, sizeof(hcp->eld)); - memset(&hcp->eld_parsed, 0, sizeof(hcp->eld_parsed)); + scoped_guard(mutex, &hcp->lock) { + memset(hcp->eld, 0, sizeof(hcp->eld)); + memset(&hcp->eld_parsed, 0, sizeof(hcp->eld_parsed)); + } hdmi_codec_jack_report(hcp, 0); } } -- 2.51.1.windows.1