From nobody Sun Jun 14 08:56:22 2026 Received: from mail-dy1-f178.google.com (mail-dy1-f178.google.com [74.125.82.178]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8C79C1D516C for ; Thu, 2 Apr 2026 00:20:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.178 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775089234; cv=none; b=daYZjgUzfSzdr50/+SaTeSVsuk1E1khOwaxAFezAY/nek6SdoUmA7X5YLSxCUOGPpVSUm34iBQqf8T+jvGNiHApONO2Oh15jtenpeEcZC9EKE1hxnYQMoZGFf+Q5IMURPepssMf97+HdsEQFIsyZIgBWe8/5hw+3Kae9OtTpoZE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775089234; c=relaxed/simple; bh=T/yW21uWgwThSJ3q/XO9IlViTDoB7m4P3V3VI/DLdi4=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:To:Cc; b=o7O4A0QtkbPeFomQu1zs2O+1Yk+i6YFnobCYcI3CE8rx0IhjAyq5QGYdzh+3j3HK879TuGMfFjiU9/FyqQ6jMvQ11qFsuRiIr+v4gxRJr2rTT+a9M6vfr+aT+wbdrPGFPJm+rOsqFo+/TlYOWzVBfHGS2fbKKBRfu+K4rSlecUw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=G13E5hfz; arc=none smtp.client-ip=74.125.82.178 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.b="G13E5hfz" Received: by mail-dy1-f178.google.com with SMTP id 5a478bee46e88-2c66eafc1easo718872eec.1 for ; Wed, 01 Apr 2026 17:20:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1775089233; x=1775694033; darn=vger.kernel.org; h=cc:to:message-id:content-transfer-encoding:mime-version:subject :date:from:from:to:cc:subject:date:message-id:reply-to; bh=Y7/uDI4r1aKHAAS9AZdsKf1B5Cq/o/kxHPNvRkLjnRs=; b=G13E5hfzh49+gcJXhroqVxZ4zsD1/0VDa4WWE6jHcGZwb4J1Fvc1yRs+/Lx/LFAl77 h1jBvZt0Wv1rS6Bd6EPBvznoVNrtwQI4NcCarXAaCAQS/IvgP/EOs2rJcKHdW4v4kJ4B hvTDUZeEhUVklPMy5jpkE/ClzXUMigLuTNF+tLDdA6bbYuVm++f+xVMeZekrIa0KO3kB LO7e9x656leueFifRo1cPtUACHZ6sDJsAAkETl9G0YAQwrkGe/mkdzsZ/MDJIGX59AHC yZEisYzh4qVenV+ZtbSpUetuReBMfqB2/7CnTgdsuA6N09moFsGaK5bCACbHc+xnlv7j MC/Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1775089233; x=1775694033; h=cc:to:message-id:content-transfer-encoding:mime-version:subject :date:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=Y7/uDI4r1aKHAAS9AZdsKf1B5Cq/o/kxHPNvRkLjnRs=; b=BZERYbPqfCwC8/4zpeyB7PG1T1ugzkjgchjSf9uHsd7dVXTdt7cd9aLqdrzOKLoScd B/XNX58qf50CfLdJwcSOi9p0AJbIwPVAywF6FnfDG4lE9ytVubl1t9+FRbg4cjkj+p01 7i32JkzPf5GaU3jHmq3YQ4J1ygX705zFKGN2ZrwylsRjjILJFkJe6r+KlCtgNtu8AxoT fudJk19DKQBAa7vVjZplA/naQg33Z0zgHXlHb0pPVM1AXcX22VNH1xLc1m+ONZyVhfU0 +irlGUJDlwjtQVTYPIEIEJzmpj8JGJfStFmj20U4UBaqp1PwG8JsBZcClk+tpL/37E1b hGzg== X-Forwarded-Encrypted: i=1; AJvYcCUTPiMZnXbihOQBWzVHZzXcRWmYzgdrqJbdR6RgvGwXJVdAHDukLMNqpelsgMYcA8Cm0aWBWmphLHHWODU=@vger.kernel.org X-Gm-Message-State: AOJu0YxNj4E5QIug9D7GausjQrL6l4uHT/9QexRY6SNRlKvdElg2TTYi bYQyc7iaMF/BoyzRA2toNW5LFyu67L6g8L2L9moCatadpIyY6RlbNmOF X-Gm-Gg: ATEYQzxeGW+iAtyDZW6mGGE3s+qM6euZCvWBqufsVbBmZyPptdwM/Fzq43i/JzQrGXN Mb9yEiPhaZG+cDnu/SKgV84ZkM8EuYRR31eoDofpcGx7jafSvF/9cMfTdeHzRN+g/W8VMzZzMub tOiOQgdt9yHfkpnpCS4Ev0jfZNfs+gQV+wgrGyh90wvlWyPYFzbAa4Um5a7qVSFGFzr1CD4cIMO bOV3Wn8x3N9pN5mAr/yovNrm+MtmOAk5AAtwKjhiNBSF7cjCxhRrTDv0kBuCfJFJuCXpFZMc7+x uiqRltHGauub2f84tiY/+HtW4ipBPgArw8qGKT7ZICQYAIdiW3mcL1KuonODeH0RyLmoEVrY7pb b9nKhcLfNiXIM2zaRsdDh832g1GAcu8OakueMyShpzkJJIfcS2fqze6In+z84hk6Evu902o+9kt FXdoyqw++DkAFYgAxv4eLZeDD3ksaHtxewbDkbPW/B70ZsL7Ql2w1yjpYdzC9sYsw2gggODQchC QBL X-Received: by 2002:a05:7300:c8cc:b0:2ca:f038:3d17 with SMTP id 5a478bee46e88-2caf038469cmr57410eec.4.1775089232574; Wed, 01 Apr 2026 17:20:32 -0700 (PDT) Received: from [192.168.1.18] (177-4-161-218.user3p.v-tal.net.br. [177.4.161.218]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-2cafd073194sm10440eec.28.2026.04.01.17.20.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Apr 2026 17:20:32 -0700 (PDT) From: =?utf-8?q?C=C3=A1ssio_Gabriel?= Date: Wed, 01 Apr 2026 21:20:21 -0300 Subject: [PATCH] ALSA: hda: Notify IEC958 Default PCM switch state changes Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260401-hda-spdif-share-notify-v1-1-707e422ed9d1@gmail.com> X-B4-Tracking: v=1; b=H4sIAAAAAAAC/yXMMQ6DMAxA0asgz7VkAmLoVaoOJnGIGQKKKWqFu HtTOr7h/wNMiorBvTmgyK6mS65obw34xHkS1FANjtxAXUeYAqOtQSNa4iKYl03jB52L3LMn4ra HGq9For6v8eP5t73GWfz2u8F5fgHso69legAAAA== X-Change-ID: 20260330-hda-spdif-share-notify-22fa4ac00a14 To: Takashi Iwai , Jaroslav Kysela Cc: linux-sound@vger.kernel.org, linux-kernel@vger.kernel.org, =?utf-8?q?C=C3=A1ssio_Gabriel?= X-Mailer: b4 0.15.1 X-Developer-Signature: v=1; a=openpgp-sha256; l=4964; i=cassiogabrielcontato@gmail.com; h=from:subject:message-id; bh=T/yW21uWgwThSJ3q/XO9IlViTDoB7m4P3V3VI/DLdi4=; b=owGbwMvMwCV2IdZeKur/u2bG02pJDJlnt/ltnzm1111pwu1JjvXnRbNjbGcFn3kWuFk9Uk54k 8J35lvTO0pZGMS4GGTFFFlWJy2y3NP14Gp93AoPmDmsTCBDGLg4BWAiL8MYGXpmCxkXNbKmpFhJ vuMr8Hsftt3k3P+SA7eWPN3kfGnKxveMDAdLbwh/VnF8+HD++UDn10Lz9v78mBofmtrJXH9K8n3 zU0YA X-Developer-Key: i=cassiogabrielcontato@gmail.com; a=openpgp; fpr=AB62A239BC8AE0D57F5EA848D05D3F1A5AFFEE83 The "IEC958 Default PCM Playback Switch" control is backed directly by mout->share_spdif. The share-switch callbacks currently access that state without serialization, and spdif_share_sw_put() always returns 0, so normal userspace writes never emit the standard ALSA control value notification. snd_hda_multi_out_analog_open() may also clear mout->share_spdif when the analog PCM capabilities and the SPDIF capabilities no longer intersect. That fallback is still needed to avoid creating an impossible hw constraint set, but it changes the mixer backing value without notifying subscribers. Protect the share-switch callbacks with spdif_mutex like the other SPDIF control handlers, return the actual change value from spdif_share_sw_put(), and notify the matching control when the open path forcibly disables shared SPDIF mode after dropping spdif_mutex. This keeps the existing auto-disable behavior while making switch state changes visible to userspace. Fixes: 9a08160bdbe3 ("[ALSA] hda-codec - Add "IEC958 Default PCM" switch") Fixes: 022b466fc353 ("ALSA: hda - Avoid invalid formats and rates with shar= ed SPDIF") Signed-off-by: C=C3=A1ssio Gabriel --- sound/hda/common/codec.c | 51 ++++++++++++++++++++++++++++++++++++++++++++= ---- 1 file changed, 47 insertions(+), 4 deletions(-) diff --git a/sound/hda/common/codec.c b/sound/hda/common/codec.c index 09b1329bb8f3..5e74b02c45f6 100644 --- a/sound/hda/common/codec.c +++ b/sound/hda/common/codec.c @@ -2529,7 +2529,10 @@ EXPORT_SYMBOL_GPL(snd_hda_spdif_ctls_assign); static int spdif_share_sw_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { + struct hda_codec *codec =3D (void *)kcontrol->private_value; struct hda_multi_out *mout =3D snd_kcontrol_chip(kcontrol); + + guard(mutex)(&codec->spdif_mutex); ucontrol->value.integer.value[0] =3D mout->share_spdif; return 0; } @@ -2537,9 +2540,15 @@ static int spdif_share_sw_get(struct snd_kcontrol *k= control, static int spdif_share_sw_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { + struct hda_codec *codec =3D (void *)kcontrol->private_value; struct hda_multi_out *mout =3D snd_kcontrol_chip(kcontrol); - mout->share_spdif =3D !!ucontrol->value.integer.value[0]; - return 0; + bool val =3D !!ucontrol->value.integer.value[0]; + int change; + + guard(mutex)(&codec->spdif_mutex); + change =3D mout->share_spdif !=3D val; + mout->share_spdif =3D val; + return change; } =20 static const struct snd_kcontrol_new spdif_share_sw =3D { @@ -2550,6 +2559,33 @@ static const struct snd_kcontrol_new spdif_share_sw = =3D { .put =3D spdif_share_sw_put, }; =20 +static struct snd_kcontrol *find_spdif_share_sw(struct hda_codec *codec, + struct hda_multi_out *mout) +{ + struct hda_nid_item *items =3D codec->mixers.list; + int i; + + for (i =3D 0; i < codec->mixers.used; i++) { + struct snd_kcontrol *kctl =3D items[i].kctl; + + if (snd_kcontrol_chip(kctl) =3D=3D mout && + !strcmp(kctl->id.name, spdif_share_sw.name)) + return kctl; + } + + return NULL; +} + +static void notify_spdif_share_sw(struct hda_codec *codec, + struct hda_multi_out *mout) +{ + struct snd_kcontrol *kctl =3D find_spdif_share_sw(codec, mout); + + if (kctl) + snd_ctl_notify_one(codec->card, SNDRV_CTL_EVENT_MASK_VALUE, + kctl, 0); +} + /** * snd_hda_create_spdif_share_sw - create Default PCM switch * @codec: the HDA codec @@ -2566,7 +2602,10 @@ int snd_hda_create_spdif_share_sw(struct hda_codec *= codec, kctl =3D snd_ctl_new1(&spdif_share_sw, mout); if (!kctl) return -ENOMEM; - /* ATTENTION: here mout is passed as private_data, instead of codec */ + /* snd_ctl_new1() stores @mout in private_data; stash @codec in + * private_value for the share-switch callbacks. + */ + kctl->private_value =3D (unsigned long)codec; return snd_hda_ctl_add(codec, mout->dig_out_nid, kctl); } EXPORT_SYMBOL_GPL(snd_hda_create_spdif_share_sw); @@ -3701,6 +3740,8 @@ int snd_hda_multi_out_analog_open(struct hda_codec *c= odec, struct hda_pcm_stream *hinfo) { struct snd_pcm_runtime *runtime =3D substream->runtime; + bool notify_share_sw =3D false; + runtime->hw.channels_max =3D mout->max_channels; if (mout->dig_out_nid) { if (!mout->analog_rates) { @@ -3729,10 +3770,12 @@ int snd_hda_multi_out_analog_open(struct hda_codec = *codec, hinfo->maxbps =3D mout->spdif_maxbps; } else { mout->share_spdif =3D 0; - /* FIXME: need notify? */ + notify_share_sw =3D true; } } } + if (notify_share_sw) + notify_spdif_share_sw(codec, mout); return snd_pcm_hw_constraint_step(substream->runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS, 2); } --- base-commit: 85d2c76df1f21fdd599cf2dbee29d59da47f8fa4 change-id: 20260330-hda-spdif-share-notify-22fa4ac00a14 Best regards, -- =20 C=C3=A1ssio Gabriel