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=1796415790; b=AZyiEv01qn4wxITe8n3cu4fNxST1KdVjvVOMQfBrsrNijlMfjEnnQ3ogGdtcuQgixZur NHnBcSfogUuqhSx7xJ0Qj2dIR9cN+5VmC3TrEPKSXOwaNYCRzgGzlr7wsLzPJv374Fdua sWxYjwEkGBncUBv+0UMyY/7bSC/8UKrNgCkwgYW3iQHvxv5fKg/FjbJ1HndTSFQq3f7Zg AsSgpPUYiWUxe5as0ebF6DcP7wLz7u1iE4AARG9EpKQ+plGQckUktiljx4GHLsqY6qI54 zE+FCMeeV24FVT3b7kf3+QXKoi5604+WuHcxrzP0DWdwuA727mWZIna59G8WujZza5w== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796415790; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=0Dra3BZnBdUYFl/818ahzFCni6kOZY0p7rrRYy6SyJA=; b=Vx7IgB12x8xdz20PHBFCP7cCRZacFymhOL+JMHwD0TZuhUSWE1w/cJ2iRV0eNSNMoVYF nhZC826U3p7lE9cfSuW6qjx9vuY1DjalUtZHBdVdnT3qDPvp0vey8rW/Xb50sotBZFxGf mD+99lnI3zau8HJjxt0PBnaNsy2SZVkUlf7gGqhybw2U7EU4KTztHl6p59XiNdGN8ZvjI aOiPUWTWiLfkmeqZqHdt8CCIHWGLNuVhtlRyI5LRDpLNCL+IwIClZTI/VrrZoBMCx6mxw +Hp9+hlJ4MMhDsBNcifwFiDRm5+X9NwTFwIbxzkwvoU0XVQUTZyvbocZG4K5mB5ewcw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=KkjXccdr; 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 6DE05606A322 for ; Fri, 4 Dec 2026 20:23:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=KkjXccdr Received: by smtp.kernel.org (Postfix) with ESMTPSA id 201A51F00A06; Fri, 4 Dec 2026 20:23:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796415790; bh=0Dra3BZnBdUYFl/818ahzFCni6kOZY0p7rrRYy6SyJA=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=KkjXccdrIHmsMqF4WqyrrVJFNoT8YwRTAnJJ9rcAyuZ05tIr3Rl8TMAQqwI/Onpae 6Ae/9/naA1qUmH2LgUO00LfvGiho6GodTqpp83UIp5lL4rFOh29uWErI4DRy2J6DvN Es8wIPzsbsQ61t/IOvYVCozodc4pMi7GdqNaqLvTYcJHDaTrtS2kFUEtztIB3P2mNg 4GHNUJep0JQsnQMG/RklE4+Y53v3wYiDksfqxCPzXEgY34rfpZwnpergG9BrabXBHh QJXk0MFcR03tgUnlgsbpRwhSISo1yOPAySNu3O82vPr9S1mg96vo7OTyv3dGdGSjg9 pX+4wvCJUuMPg== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH] ASoC: amd: acp: add DMIC capture switch with mic mute LED support Reply-To: sashiko-reviews@lists.linux.dev To: =?utf-8?b?QmFoYWTEsXIgSGFtemEgw5Z6dMO8cms=?= Cc: linux-sound@vger.kernel.org In-Reply-To: <20261204200115.10636-1-bahadirhamza2@gmail.com> References: <20261204200115.10636-1-bahadirhamza2@gmail.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Fri, 04 Dec 2026 20:23:07 +0000 X-Mailing-List: linux-sound@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Thank you for your contribution! Sashiko AI review found 7 potential issues to consider: - [High] ASoC: amd: acp: NULL deref in acp_pcm_probe() before dev_set_drvdata() - [Medium] ASoC: amd: acp: mmap readers bypass DMIC soft mute while mute LED is on - [Medium] ASoC: amd: acp: stale mute_pos leaks audio after prepare or resume - [Medium] ASoC: amd: acp: modulo mute_pos misses full-buffer wraparound in pointer - [Medium] ASoC: amd: acp: missing snd_ctl_led_request() and SND_CTL_LED Kconfig select - [Medium] ASoC: amd: acp: unmuting in acp_dmic_switch_put() leaks pending muted audio - [Medium] ASoC: amd: acp: unconditional MIC_LED flag breaks mic mute LED state -- commit c6c200b5312901dd7e1038bc5492d1be0b4d966a Author: Bahad=C4=B1r Hamza =C3=96zt=C3=BCrk ASoC: amd: acp: add DMIC capture switch with mic mute LED support This commit adds a "DMIC Capture Switch" mixer control with SNDRV_CTL_ELEM_ACCESS_MIC_LED to the ACP PCM component when a PDM controller is present, and implements muting in software by zeroing newly captured samples in the .pointer callback. > diff --git a/sound/soc/amd/acp/acp-platform.c b/sound/soc/amd/acp/acp-pla= tform.c > index f2c8853775ad3..2163e233e6cba 100644 > --- a/sound/soc/amd/acp/acp-platform.c > +++ b/sound/soc/amd/acp/acp-platform.c > @@ -268,10 +268,33 @@ static int acp_dma_hw_params(struct snd_soc_compone= nt *component, > /* Configure ACP DMA block with params */ > config_pte_for_stream(chip, stream); > config_acp_dma(chip, stream, size); > + stream->mute_pos =3D 0; [Severity: Medium] Can stream->mute_pos go stale across prepare or system resume and leak unmuted audio? stream->mute_pos is only reset here in acp_dma_hw_params(), not in acp_dmic_prepare(), acp_dmic_dai_trigger(), or restore_acp_pdm_params(). After system suspend/resume (where acp_reset() zeroes the hardware byte counter) or STOP/XRUN recovery, DMA restarts at offset 0 while stream->mute_pos still holds its previous non-zero offset. When acp_dma_pointer() next observes pos >=3D stream->mute_pos while muted, acp_dmic_soft_mute() only zeroes [start, pos) and skips [0, start), delivering live audio to userspace while the mute LED is on. Additionally, unlike acp_i2s_trigger(), acp_dmic_dai_trigger() never snapshots stream->bytescount on start, so reopening a stream without an ACP reset can begin at a non-zero ring offset that does not match mute_pos =3D 0. > =20 > return 0; > } > =20 > +/* > + * The ACP PDM block has no mute control, so mute the DMIC in software: > + * every captured byte between the last handled position and the > + * current hardware position is cleared before user space can see it. > + * This is called from the .pointer callback, which runs before any > + * hw_ptr update, so it covers both period interrupts and mmap readers > + * that query the position in between. > + */ > +static void acp_dmic_soft_mute(struct snd_pcm_substream *substream, > + struct acp_stream *stream, u32 pos, u32 buffersize) > +{ > + unsigned char *area =3D substream->runtime->dma_area; > + u32 start =3D stream->mute_pos; > + > + if (start <=3D pos) { > + memset(area + start, 0, pos - start); > + } else { > + memset(area + start, 0, buffersize - start); > + memset(area, 0, pos); > + } > +} [Severity: Medium] Can mmap capture readers still read live microphone audio while muted? Both acp_pcm_hardware_capture and acp6x_pcm_hardware_capture advertise SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_MMAP_VALID, mapping substream->runtime->dma_area directly into userspace. Because PDM DMA continues writing live samples into those pages and acp_dmic_soft_mute() only zeroes them retroactively in acp_dma_pointer(), an mmap reader inspecting the buffer ahead of hw_ptr can capture unmuted audio while the hardware mic mute LED stays lit. Scrubbing up to 64 KB with memset() here also runs in hardirq atomic context while holding both chip->acp_lock (from acp_irq_handler()) and the PCM substream spinlock. [ ... ] > @@ -291,6 +314,13 @@ static snd_pcm_uframes_t acp_dma_pointer(struct snd_= soc_component *component, > =20 > pos =3D do_div(bytescount, buffersize); > =20 > + if (stream->dai_id =3D=3D DMIC_INSTANCE && > + substream->stream =3D=3D SNDRV_PCM_STREAM_CAPTURE) { > + if (READ_ONCE(chip->dmic_mute)) > + acp_dmic_soft_mute(substream, stream, pos, buffersize); > + stream->mute_pos =3D pos; > + } [Severity: Medium] Will a full-buffer wraparound between .pointer() calls bypass the soft mute? do_div(bytescount, buffersize) discards the unwrapped byte progression before calling acp_dmic_soft_mute(). With a 2-period buffer (as small as 2048 bytes) under a delayed or coalesced interrupt, or under no_period_wakeup, DMA can advance by buffersize bytes so pos equals stream->mute_pos. acp_dmic_soft_mute() then clears zero bytes while snd_pcm_update_hw_ptr0() detects the wrap via jiffies and advances hw_ptr by runtime->buffer_size, exposing the full unmuted buffer to userspace. Tracking the unwrapped 64-bit byte count before do_div() and clearing the whole ring buffer whenever the delta reaches buffersize (or moves backwards) would avoid this. [ ... ] > +static int acp_dmic_switch_put(struct snd_kcontrol *kcontrol, > + struct snd_ctl_elem_value *ucontrol) > +{ > + struct snd_soc_component *component =3D snd_kcontrol_chip(kcontrol); > + struct acp_chip_info *chip =3D dev_get_drvdata(component->dev->parent); > + bool mute =3D !ucontrol->value.integer.value[0]; > + > + if (mute =3D=3D READ_ONCE(chip->dmic_mute)) > + return 0; > + > + WRITE_ONCE(chip->dmic_mute, mute); > + return 1; > +} [Severity: Medium] Does clearing chip->dmic_mute here leak audio that was captured while muted? While muted, PDM DMA keeps writing live samples ahead of stream->mute_pos. Clearing chip->dmic_mute without first zeroing the pending [stream->mute_pos, current_hw_pos) range causes the next acp_dma_pointer() call to skip acp_dmic_soft_mute() and advance hw_ptr over up to a full period of audio recorded while the mute LED was on. > + > +static const struct snd_kcontrol_new acp_dmic_controls[] =3D { > + { > + .iface =3D SNDRV_CTL_ELEM_IFACE_MIXER, > + .name =3D "DMIC Capture Switch", > + .access =3D SNDRV_CTL_ELEM_ACCESS_READWRITE | > + SNDRV_CTL_ELEM_ACCESS_MIC_LED, > + .info =3D snd_ctl_boolean_mono_info, > + .get =3D acp_dmic_switch_get, > + .put =3D acp_dmic_switch_put, > + }, > +}; [Severity: Medium] Does setting SNDRV_CTL_ELEM_ACCESS_MIC_LED unconditionally on this control regress mic mute LED handling on other ACP platforms? Because chip->dmic_mute defaults to false (switch on), adding this control with SNDRV_CTL_ELEM_ACCESS_MIC_LED registers an always-on entry in the global snd_ctl_leds mic list in sound/core/control_led.c. On ACP 7.0/7.1/7.2 laptops, snd_amd_acp_acpi_find_config() defaults to FLAG_AMD_LEGACY_ONLY_DMIC and registers acp-pdm-mach as a second card alongside snd_hda_intel; since existing userspace does not toggle the new DMIC switch on acp-pdm-mach, snd_ctl_led_set_state() keeps the mic mute LED permanently off even when HDA capture is muted. On legacy I2S+DMIC cards such as acp3x-es83xx, none of the codec capture switches or headset mic pin switches carry SNDRV_CTL_ELEM_ACCESS_MIC_LED, so muting DMIC lights the mic mute LED even while the analog headset mic is live. > + > +static int acp_pcm_probe(struct snd_soc_component *component) > +{ > + struct acp_chip_info *chip =3D dev_get_drvdata(component->dev->parent); > + > + if (!chip->is_pdm_dev) > + return 0; [Severity: High] Can dev_get_drvdata(component->dev->parent) return NULL here and crash during probe? In acp_pci_probe(), both create_acp_platform_devs() and acp_machine_select() run before dev_set_drvdata(&pci->dev, chip): sound/soc/amd/acp/acp-pci.c:acp_pci_probe() { ... acp_machine_select(chip); INIT_LIST_HEAD(&chip->stream_list); spin_lock_init(&chip->acp_lock); skip_pdev_creation: dev_set_drvdata(&pci->dev, chip); ... } When the platform, DMIC codec, and machine drivers are built in or already loaded, acp_machine_select() synchronously calls devm_snd_soc_register_card() -> snd_soc_component_probe() -> acp_pcm_probe(), causing a NULL pointer dereference on chip->is_pdm_dev. Even if acp_pcm_probe() avoided parent drvdata, snd_card_register() -> snd_ctl_led_register() synchronously invokes acp_dmic_switch_get() for SNDRV_CTL_ELEM_ACCESS_MIC_LED controls, which also dereferences dev_get_drvdata(component->dev->parent). Setting dev_set_drvdata(&pci->dev, chip) in acp_pci_probe() before creating the child platform devices would avoid both crashes. > + > + return snd_soc_add_component_controls(component, acp_dmic_controls, > + ARRAY_SIZE(acp_dmic_controls)); > +} [Severity: Medium] Should acp_pcm_probe() call snd_ctl_led_request(), and should SND_SOC_AMD_ACP_PCM select SND_CTL_LED? Adding a control with SNDRV_CTL_ELEM_ACCESS_MIC_LED does not auto-load snd-ctl-led on its own, so when CONFIG_SND_CTL_LED=3Dm and no HDA or SOF driver requests the layer, the mic mute LED stays inactive. In addition, SND_CTL_LED in sound/core/Kconfig has no prompt, so AMD ACP ASoC-only configurations without CONFIG_SND_HDA_GENERIC_LEDS cannot enable it at all unless SND_SOC_AMD_ACP_PCM selects it. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261204200115.1063= 6-1-bahadirhamza2@gmail.com?part=3D1