From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.215.182 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795941215; b=L922P35UtW5SrNrctifTL3zJs7ALACGgJo3PItgbmOb+M78rO2KFvKsWRsmISQ7/MViA IUNkNhJkhNyxgR2pjiMLggSo1C6j2K0q/n+nOjDxKkiluuMZMSU4nJO00WsQeAijl57XV /dzTFIrmWrzC6qZ9JNsh0S/qG50eqk/xhsmgGlmJBys2tixJOSr0XSd31F9jwR5wNgz7i FDRDC7jLwylAZr7Ty1FQkMPzjq1M8+NKztpwXwt654Wjbcr0rB4uJjjaNJxDEzFuaiCK1 iB30EuFOygkbWa8ptjMmetnqJudUIcIwkeICOLxdvMbH0v7cBHmZgEV/T4sLYs8SoOw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795941215; 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=KS3nunnvWmb1P5alpTsNfthMcio1ANjxYmoKK1wKSltfpnu5+fmF5aXbnh75Z5B+TSED /JJ5gmvf9B7xMxX3td6RmLQyDIPKd2KxKNWRKYeHRophDTGsRT9GNSrsnKAiKXvp9w1ye LNNf3WVWp8Xv6r41OQDRDjHfG4jfVW3kMjfoKgnvxZoCzOquB5oJ3aylTxIuGOoKuj2yQ IhmGVMkne3XZqjwigup50tl9eA0orgp6DUqJrf0poEQD/nbNP65B6Wj6unRI1TZbBL4j4 stsGMDaml6cUIqn6lGrpzQ9AjwFNsYdLa7oan9cPiMvI7SgcTinwI1GL+I787C+ToHw== 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.182 Received: from mail-pg1-f182.google.com (mail-pg1-f182.google.com [209.85.215.182]) (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 782B7606A323 for ; Sun, 29 Nov 2026 08:33:35 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 782B7606A323 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-f182.google.com with SMTP id 41be03b00d2f7-cde4b4e936fso4337327a12.1 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=z1fkvudXdyxtmVLeR/rbtmkzA8YA7aKbjMeLTFyZlZW8qVzN+iSX2IRKrivU2KHKEu jLVIjyjHt8pg5zsvoe3r8Q2c4O8GS+vj96pUVUSCyE6ZUJ0yXki0vHF7OlC7jXMFQMvI /UvirwOuw6XLaXDVqDukePWC6hJ3obH5vbmZjBMZkvs+PN4l9dF+kNV3zE9P56tOu5Gx PtyCLk0tab7bIwEZNsSicJONZAJ/56gywelF41MKTY8EuGgdzm3JAWGNlGXEfaPqAulx s0Gbvj6Ec30Tfv2IpVy7IM9GiogjwoTOFOg8XbOHuzImmQ5yy3VVkyCC4NrIW4qDhK9r rSaQ== X-Forwarded-Encrypted: i=1; AL+hErGT5HSZu5uUoPsaLUXio1g/2Jcs2ZjSEm/tXiw/LGJ/aaSdnenx6RU3HrVdvvXS/Tt/eCrd6auuhW08rA==@vger.kernel.org X-Gm-Message-State: APuU4Z/R8a/5OvvZEQwBvh/hhG4doS9tfDI92isl3fJ/Dl2GtT+3+aSr v0b7dJbFhB/Ab+9OjGHY8J47kHr5fh4sonfpW5alezAWzXdZQjn/aqCl X-Gm-Gg: AZFdTZfr3RSKxS4gHpmFrIaQAhgp6+vXELk32V1ck4/fK0rL/UId7AYLLJZJlnQx8kA pj2UCnFAkXGxMjlO7JhIzAUHyCWAtt8AsdMGXVOhGVwcFbxB6SXqJKRUqJzvR+F/nHH+x3SH4xA EOO5rJqWeZ5F1e5nuES4UdtsTbzjNU1XBCGXow08vxHLCNQtK+h0VSEVwDT/33eIOkcXAYeshIj j5Mufsk2UxybMC4bUVgvmEXAnoWE7otoGU/qpYSCPGXq38aHjRNGCLcsXwTc/BaG+X9gxCn8IWI ZVf60ssHaZnoNo5yrDUD3u9hbZBdOo/0JJWM6DSq93PaMjEcksU7dd+dM4m4tUQbT5p5tZot3kE u1t5ietSrL1i5TGCmyiRV2ZGBy/2XG8H2zfpa7qk1dC7gIbQn+f9rnpkubT3aTroiiPbQIRkTjP cmUK/WZ2QSTH4x8m1HOxEeS5NZsoD5RgJkjpUVF+iaJA9RwEzrvh2Sisa46n24breNuX59FxsMS Zxz3i1+Xiw8GBJg6j9v6iSPnwgT+CQBBcAhs3DbRz67Uv2M/SW2knrRryxFDCYe9JVI5LPjEnEz KWJ0v7o/FyOkZhiw3JulnkYH/8tiHtnl/zDuTsapu8t3PCBfW48Qe5Yd6hdzJNgQMMdZfLmddGp QsWItuRw= 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-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: 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