From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.215.176 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795941216; b=xbrPBPZFWaHTSKAiAWnWbAaHG/Y6tXZ4yCAi3SybK5SYIxL2jheJccXUdw+K2nNKefDs a+rJwg5Qgvdn6GWgOnpSBzXakNxTslYPNogWBbSqZsnLw4yxtF2EvzOSmaZxuKY9JfJop tuMHvZVIz/hQzBXNo3jkthwKpM4q6UpxPFkubayIcVmRHNFHI8PwzX/Yiav266IbVg8Cx Q3rW8J/gUvioQ1+n0OlrVP5DjzK6on6WqIjZeTPuLy2JK7rPOM+F/8We+QGV39DTjrm4u Qst6oPA5QU0yEfKEHRmLmz66GzuTH9ROJGEcShro6OGYWUr8evdsmgLVHnuBKDADOQA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795941216; 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:MIME-Version: Content-Transfer-Encoding; bh=4D4pI2IDz5maoql7tj1YE130LHHCIUniwZ4DJG4GSXs=; b=YoR9ifPmtTWFdrd0E4DfGPF+fb5FRUceJvqnOiyx3UKMOvGrSrcwElJ0rZuHrs5cufnD 6Uz2TuXUZRPcnRpIUbXfV1KSuuw2g4NFFScEY/YNk2MALh2GGYRHFJd1ckUfD+Dzvh7EM Uduo+2GJtq4rWhIRjVVxCuWcUYwajzQIkoJq/Ax5hamNYeIsRlpt+Mn8ocxp/YQR80Nhj 49UIOb4EW3RsmdkOPkq7SnJbmdt7WBNJXsx0NkqF8O99qHWiJ/xPNQwdMXXBH/WE6fgow 7Qc6WN2sgBPSzP6ib9xkluuCGIl8zV9CjCE+UKzN4KuU3EIiNN1V6kx3/94Nh//ycSQ== 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=I7j0wNyO; arc=none smtp.remote-ip=209.85.215.176 Received: from mail-pg1-f176.google.com (mail-pg1-f176.google.com [209.85.215.176]) (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 7AA59606A325 for ; Sun, 29 Nov 2026 08:33:35 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 7AA59606A325 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=I7j0wNyO Received: by mail-pg1-f176.google.com with SMTP id 41be03b00d2f7-cdb9f760337so5020486a12.0 for ; Sun, 29 Nov 2026 00:33:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1795941215; x=1796546015; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to:content-type; bh=4D4pI2IDz5maoql7tj1YE130LHHCIUniwZ4DJG4GSXs=; b=I7j0wNyOf2ypZ+GJhzrSqhepLlHOT4XfwMShTR76Uqb+713uU5E6ILNmxHCfTwGJ4G RdI5v5jht+OJPsmy2/0t6xrKm8DflKRjn0JE6dD/UJYlStg1cjzGHLrm/QVaCubb3EKG lbQ8H/NbMFuKBWRPdeZg5PlCpHSuTAAE8uPtjcMLOyEYp371AVlpEtr4pm86hvhE/a3y iQGguxzuY47/N8wnu4S9tsU4kQN/ZyR62NKeAwPhRzVnt727Lx7X9tW3bCpeqp8z2nRp 8SOWZRMa7SZWpeSRIbbieApaE9KQvGjJoOY7t2J5a4twU2427mo7nXesoFhBtGFc35Ow 8zUQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1795941215; x=1796546015; h=content-transfer-encoding:mime-version: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=4D4pI2IDz5maoql7tj1YE130LHHCIUniwZ4DJG4GSXs=; b=RqQ615rJ+BGTDoLqmBCKmpL8vycMgftepk9iF/qgnA2uARdshdUJbClhWSq3t1i3/2 XFg8iwCAEGmTAlByyAZbGXclVoyw6QVl/hPgAkRLcxE01vlMaJrXMoIN//SDv00776Jm 1xP0bWIPJbrXN3H2mKeOrUyPQBbmSf8EcmMCz+zxBgAFSNzd4S4poPFBArJeh/oaJQEe OL1A4KEqKSWfJx99YWk2dSUzB8l6ywyI40j94D8aJsKo7jdRRnOt/VveJeWDPSYve/In BGE8FeoqG44yVqswL9WZygNPexI9qeSdSooH4rrBdK195WNj5iGyEcefWT/qbQoLasPs rB3w== X-Forwarded-Encrypted: i=1; AL+hErEtNeBcvzbj9Qx5TNXLf7bqf3sktqZDdPAbrYs1+kSYPmKZlmTfLkHRVMtvgXOCHzimA7xuXyUFjxVu/rI=@vger.kernel.org X-Gm-Message-State: APuU4Z8UVbA4afhVWIEjnJwXdoL37YicDdZsrcSIM2BJzQMfkwTHcrpX xhDW/5xOwoScDSKCB/uTclcrcha4vWbnaIMgKxzALCDZIouNDN2zu+5m X-Gm-Gg: AZFdTZeOTewMo7puT2Xc4dnse58atzlci17HmFgHmHPc8EN+mC2ydYnknat6oAYF9Zz ndA7Up1sHGZTdn65EEGh/bA/pgfSakQbI+7VC6hFu/vcSw/q5i/Y32tzQaxd/GsWRqnFLPXM2NP sO7teUBrRoWhYd9l49S6glRmc/Fev6FHf9G+dBv+Ql91Rhze9stiTsLx1Ld8E2w+yGfPKZ708xo kdrTuT+WfqKHS7fRbeuqaaEbv6HGb6X4mnIVdKWWS/kt6JFa2NznDLYmwrQnee+8qQ87seDKCS0 qiM0scTA6W++l0KjKhWL6l4c5v+D3JCkG9yeauQxuRIhQ+wTnfewjUg76FLMZE2CIgC4zZWMtQE ayFBgOKqTx9atpxAdF/R3Zvrsiu04vTp6hzp8Ry7xaA0fkejoqbwZGzMQKv9meXfQbfGQBGXL9+ ROCr8FuP07ChVWVO46l9TZE1xgqos8bwKN1SdyRfi7HxyapevywihN7C5f/hky12ilLQHUoM07I WLa0cYRHK6PL9FmyqSxoKvWP0Cbs9uk8HU3PQ9J6UuOBII51oZAo8Z3SNC+FBOsi365hA1h9P1M auxS7zex7ZhIXO8BiE1XTgR4/PjigM5wYIEZMMYRTnnGIHdGDSRYqoN20qpVY6+d32DP/bwo9aR Y+HTXkwE= X-Received: by 2002:a17:90b:4483:b0:3a4:b509:88bd with SMTP id 98e67ed59e1d1-3b41c7bc7ccmr18832559a91.2.1795941214501; Sun, 29 Nov 2026 00:33:34 -0800 (PST) Received: from DESKTOP-TPPBPA1 (36-229-10-180.dynamic-ip.hinet.net. [36.229.10.180]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-3b409330ae8sm49664265a91.7.2026.11.29.00.33.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 29 Nov 2026 00:33:34 -0800 (PST) From: Roy To: Liam Girdwood , Mark Brown Cc: Jaroslav Kysela , Takashi Iwai , Dmitry Baryshkov , linux-sound@vger.kernel.org, linux-kernel@vger.kernel.org, Roy Subject: [PATCH] ASoC: hdmi-codec: Hold the lock while the ELD is updated or read Date: Sun, 29 Nov 2026 16:33:29 +0800 Message-ID: <20261129083329.786322-1-rongh7426@gmail.com> X-Mailer: git-send-email 2.51.1.windows.1 X-Mailing-List: linux-kernel@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: Roy --- Notes: This applies on top of my earlier patch "ASoC: hdmi-codec: Clear the parsed ELD on unplug": https://lore.kernel.org/all/20261126103757.655758-1-rongh7426@gmail.com/ sound/soc/codecs/hdmi-codec.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/sound/soc/codecs/hdmi-codec.c b/sound/soc/codecs/hdmi-codec.c index ff4fa9f..b1b1926 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, @@ -972,6 +976,7 @@ static void plugged_cb(struct device *dev, bool plugged) hdmi_codec_jack_report(hcp, SND_JACK_AVOUT); } else { hdmi_codec_jack_report(hcp, 0); + guard(mutex)(&hcp->lock); memset(hcp->eld, 0, sizeof(hcp->eld)); memset(&hcp->eld_parsed, 0, sizeof(hcp->eld_parsed)); } -- 2.51.1.windows.1