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=1796053966; b=pTEMUsy5gcrg48L98d+Yg7fqRf2Ds85u0q71lAqo20hmE+Ptnp9cVFKXckbsm/ZDqRea zyME+1j+lZh7lf3l7UzOYGN6k4qe186JQNVDi9KIapw+p8UUv6V7m4yNAHEpgNgmBE/p8 ta3r4Mi9W76O/rLiA1eB+xRdwCscjiBYWc32Yne77AKcUrNvcmc6C67GknReGO3rlt7Tb fFd0WXCSPNjGGSttprkE9SejbktF+BJdEfll46Xz+dZk02aGy2YlTlegvdoanVMpW0bzG T3/Ze1KIIsntmuHQ98VGNtVJjoK/ByHyJFHIMWbkCUAc+7aHJeNfeiaPSy1T96N3u9g== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796053966; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=EqzT6fQmUqQorWxl44+pGAsNi217bWmAPki8rH/YxRM=; b=L/tZqNQjqOif6DBbDRijFdMXGGVyJ1LkqqoUJmkf/ZMbEWy0LubUPQlGdG1V4NoCBRwl ZsWHxcqxSx0Ze87+YO/DzxVaN2kJZJMEbdJ+qm5RAAfbacOrX9npZG33hDRaHND9/tWxn IftlamivzeSCCHNo8hZBU3YpIO361dnzQyG64vVmktJpASywlm0OxSlynbnglqhC83PeV lbnX2jmspJPQWilrzQzknAJIUP/DPtHKpIBQs3wycSuqlpmZUzlvY+7gezPOTWb6uNTJT V1iDGzD7PiIvajJQoCfn2brzxB9OrPGmhEfL6yGeybu0hl21b7FSbe0KmoNyBUiTjXg== 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=BPkJ7TyS; 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 068FB606A329; Mon, 30 Nov 2026 15:52:45 +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=BPkJ7TyS Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5A6D01F00899; Mon, 30 Nov 2026 15:52:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796053965; bh=EqzT6fQmUqQorWxl44+pGAsNi217bWmAPki8rH/YxRM=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=BPkJ7TySMrQnSPj03V11pgoHFFT1nX5Js/a23cnSVLPA7Hvp2ziwyUlhLIX/mYO1Y IWvT5b4mWk5OEg3JNX0TF0jA2hfCvF8Lzm63/PUAbwmUJVrqQoc8R5Vyp+91/747mq lF7REO+ROTSvxoM+C0prPnBcm9/9Rqn37Z295LMLXydJQcgJ3Vj6mjpT6KUfQq1BdF Qp/TefNobc4CY3RuRatNU0Vxm9S/L7zVbrlqiEhvKnF4sZmBGNjbNfDDfgjMdW+I8i eBGzY8gnbLvU/vAQ74wALATGy8eoEu6Shg53kAQRAXf5cGicZJbETdDAfDa9rhrixT 3Ok+nCP0X/CVw== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH 2/2] ASoC: codecs: aw88461: add the Awinic AW88461 speaker amplifier driver Reply-To: sashiko-reviews@lists.linux.dev To: "Qianhui Xu" Cc: linux-sound@vger.kernel.org, devicetree@vger.kernel.org, robh@kernel.org, conor+dt@kernel.org In-Reply-To: <20261130152838.979263-3-xiaqinghuan@mail.ustc.edu.cn> References: <20261130152838.979263-1-xiaqinghuan@mail.ustc.edu.cn> <20261130152838.979263-3-xiaqinghuan@mail.ustc.edu.cn> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Mon, 30 Nov 2026 15:52:44 +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 5 potential issues to consider: - [High] ASoC: aw88461: permanent device lockout via aw88461_fault() in aw88461_start() - [Medium] ASoC: aw88461: broken V1 ACF profile match in aw88461_load_profile() - [Medium] ASoC: aw88461: uninitialized volume in aw88461_probe() mutes output by default - [Medium] ASoC: aw88461: TOCTOU race on amp->running in aw88461_start() poll loops - [Low] ASoC: codecs: missing imply SND_SOC_AW88461 under SND_SOC_ALL_CODECS -- commit e138f0073130da2e91b260e4720f2680fa0ccf3d Author: Qianhui Xu ASoC: codecs: aw88461: add the Awinic AW88461 speaker amplifier driver This commit adds an ASoC codec driver for the Awinic AW88461 I2S speaker amplifier, reusing the AW88395 library to parse ACF firmware profiles. > diff --git a/sound/soc/codecs/Kconfig b/sound/soc/codecs/Kconfig > index 6239de3afa5a4..b6d4d7710728f 100644 > --- a/sound/soc/codecs/Kconfig > +++ b/sound/soc/codecs/Kconfig > @@ -671,6 +671,19 @@ config SND_SOC_AW8738 > SND_SOC_SIMPLE_AMPLIFIER, but additionally allows setting the > operation mode using the Awinic-specific one-wire pulse control. > =20 > +config SND_SOC_AW88461 > + tristate "Awinic AW88461 I2S amplifier" > + depends on I2C > + select REGMAP_I2C > + select GPIOLIB > + select FW_LOADER > + select SND_SOC_AW88395_LIB > + help > + Enable playback through the Awinic AW88461 amplifier, using the > + speaker tuning image named in devicetree. > + To compile this driver as a module, choose M here: the module > + will be called snd-soc-aw88461. > + [Severity: Low] Should SND_SOC_ALL_CODECS also have an "imply SND_SOC_AW88461" entry like the other Awinic codec drivers so it is included in all-codecs test builds? > diff --git a/sound/soc/codecs/aw88461.c b/sound/soc/codecs/aw88461.c > new file mode 100644 > index 0000000000000..73f37c253963c > --- /dev/null > +++ b/sound/soc/codecs/aw88461.c [ ... ] > +static int aw88461_fault(struct aw88461 *amp, int error) > +{ > + amp->powered =3D false; > + amp->faulted =3D true; > + aw88461_reset(amp); > + return error; > +} [ ... ] > +static int aw88461_start(struct aw88461 *amp) > +{ > + struct regmap *map =3D amp->aw_dev.regmap; > + unsigned int status =3D 0, noise_gate, ready; > + int ret; > + > + if (amp->faulted) > + return -EIO; > + if (amp->powered || !aw88461_active(amp)) > + return 0; > + ret =3D regmap_update_bits(map, AW88461_SYSCTRL, AW88461_PWDN, 0); > + if (ret) > + goto stop; > + amp->powered =3D true; > + usleep_range(2000, 2200); > + ret =3D regmap_read_poll_timeout(map, AW88461_SYSST, status, > + (status & AW88461_PLL_LOCK) =3D=3D AW88461_PLL_LOCK || > + !aw88461_active(amp), > + 2000, 100000); > + if (ret) { > + dev_err(amp->aw_dev.dev, "PLL lock failed: %d, status %#x\n", ret, sta= tus); > + goto stop; > + } > + if (!aw88461_active(amp)) > + return aw88461_stop(amp); [Severity: Medium] Can a concurrent PCM stop/start toggle cause aw88461_start() to proceed without AW88461_PLL_LOCK (or ready in the second poll loop)? aw88461_trigger() updates amp->running locklessly with WRITE_ONCE() while aw88461_start() holds amp->lock: kworker (aw88461_start_work) CPU1 (PCM trigger) aw88461_start() amp->powered =3D true regmap_read_poll_timeout() status has no PLL_LOCK aw88461_trigger(STOP) WRITE_ONCE(amp->running, false) !aw88461_active(amp) is true poll returns 0 aw88461_trigger(START) WRITE_ONCE(amp->running, true) if (!aw88461_active(amp)) -> false clears AMPPD, enables TXEN <-- runs without PLL lock Because amp->powered is already true, the newly queued start_work will also return 0 immediately without re-checking readiness. Checking whether the expected status bits are actually set in status after the poll loop (and calling aw88461_stop() if not) would avoid relying on a second read of aw88461_active(amp). > + ret =3D regmap_update_bits(map, AW88461_SYSCTRL, AW88461_AMPPD, 0); > + if (ret) > + goto stop; > + usleep_range(1000, 1200); > + ret =3D regmap_read(map, AW88461_NGCTRL3, &noise_gate); > + if (ret) > + goto stop; > + ready =3D AW88461_PLL_LOCK | AW88461_BOOST_READY; > + if (!(noise_gate & AW88461_NOISE_GATE)) > + ready |=3D AW88461_SWITCHING; > + ret =3D regmap_read_poll_timeout(map, AW88461_SYSST, status, > + (status & ready) =3D=3D ready || !aw88461_active(amp), > + 2000, 20000); > + if (ret) { > + dev_err(amp->aw_dev.dev, "amplifier ready failed: %d, status %#x\n", r= et, status); > + goto stop; > + } > + if (!aw88461_active(amp)) > + return aw88461_stop(amp); > + if (status & AW88461_FAULTS) { > + ret =3D -EIO; > + goto stop; > + } > + ret =3D regmap_update_bits(map, AW88461_SYSCTRL, AW88461_TXEN, > + amp->profile_txen); > + if (ret) > + goto stop; > + ret =3D regmap_update_bits(map, AW88461_SYSCTRL, > + AW88461_HMUTE | AW88461_ULS_HMUTE, 0); > + if (ret) > + goto stop; > + ret =3D aw88461_fade(amp, 1023, > + min(amp->profile_volume + 1023 - amp->volume, 1023U), 100); > + if (ret) > + goto stop; > + return 0; > +stop: > + return aw88461_fault(amp, ret); > +} [Severity: High] Does jumping to stop: on a poll timeout or transient status bit in aw88461_start() permanently disable the amplifier until reboot? aw88461_fault() asserts the hardware reset GPIO (wiping the register configuration loaded from the ACF firmware at probe) and latches amp->faulted =3D true, which is never cleared and causes all later start, hw_params, and volume updates to fail with -EIO. This is easy to hit during normal playback: 1. The second regmap_read_poll_timeout() exits as soon as (status & ready) =3D=3D ready without waiting for !(status & AW88461_FAULTS), so any transient fault bit still set on that read immediately triggers aw88461_fault(). 2. On PCM stop or pause, snd_soc_pcm_dai_trigger() stops the CPU DAI before calling aw88461_trigger(), so the I2S clock can stop while aw88461_start() is still polling AW88461_SYSST with amp->running =3D=3D = true, timing out the PLL lock poll or setting NOCLKS in AW88461_FAULTS. If startup fails or times out, powering the chip back down cleanly (setting AW88461_AMPPD | AW88461_PWDN) rather than asserting hardware reset and latching amp->faulted would allow subsequent playback streams to retry. > + > +static int aw88461_load_profile(struct aw88461 *amp) > +{ > + struct aw_device *aw_dev =3D &->aw_dev; > + const struct firmware *fw; > + struct aw_container *cfg; > + struct aw_sec_data_desc *regs =3D NULL; > + const char *name; > + unsigned int i, address, value; > + int ret; > + > + ret =3D device_property_read_string(aw_dev->dev, "firmware-name", &name= ); > + if (ret) > + return ret; > + ret =3D request_firmware(&fw, name, aw_dev->dev); > + if (ret) > + return ret; > + if (fw->size < sizeof(struct aw_cfg_hdr)) { > + ret =3D -EINVAL; > + goto release; > + } > + if (fw->size > INT_MAX) { > + ret =3D -EFBIG; > + goto release; > + } > + cfg =3D devm_kzalloc(aw_dev->dev, struct_size(cfg, data, fw->size), GFP= _KERNEL); > + if (!cfg) { > + ret =3D -ENOMEM; > + goto release; > + } > + cfg->len =3D fw->size; > + memcpy(cfg->data, fw->data, fw->size); > + ret =3D aw88395_dev_load_acf_check(aw_dev, cfg); > + if (ret) > + goto release; > + ret =3D aw88395_dev_cfg_load(aw_dev, cfg); > + if (ret) > + goto release; > + for (i =3D 0; i < aw_dev->prof_info.count; i++) { > + struct aw_prof_desc *profile =3D &aw_dev->prof_info.prof_desc[i]; > + > + if (profile->id =3D=3D AW88395_PROFILE_MUSIC) { > + regs =3D &profile->sec_desc[AW88395_DATA_TYPE_REG]; > + break; > + } > + } [Severity: Medium] Does checking profile->id =3D=3D AW88395_PROFILE_MUSIC work on V1 ACF firmw= are images (AW88395_CFG_HDR_VER_V1)? In aw88395_dev_cfg_load() -> aw_dev_load_cfg_by_hdr_v1() -> aw_dev_create_prof_name_list_v1(), the library overwrites prof_desc[i].id with the sequential loop index i: sound/soc/codecs/aw88395/aw88395_lib.c:aw_dev_create_prof_name_list_v1() { ... for (i =3D 0; i < prof_info->count; i++) { prof_desc[i].id =3D i; prof_info->prof_name_list[i] =3D prof_desc[i].prf_str; ... } Because AW88395_PROFILE_MUSIC is 0, this loop always picks prof_desc[0] on V1 ACF files regardless of which profile is at index 0, and cannot find the Music profile if it is placed at a non-zero index. Also, since aw88461_load_profile() writes the register values immediately and never uses cfg or prof_info after returning, allocating cfg with devm_kzalloc() keeps a copy of the firmware image allocated for the lifetime of the device. [ ... ] > +static int aw88461_probe(struct i2c_client *client) > +{ > + struct aw88461 *amp; > + unsigned int id; > + int ret; > + > + amp =3D devm_kzalloc(&client->dev, sizeof(*amp), GFP_KERNEL); > + if (!amp) > + return -ENOMEM; [Severity: Medium] Should aw88461_probe() initialize amp->volume to 1023? aw88461_start(), aw88461_stop(), and aw88461_volume_put() compute the hardware attenuation as: min(amp->profile_volume + 1023 - amp->volume, 1023U) With amp->volume left at 0 by devm_kzalloc(), the target attenuation is clamped to 1023 (maximum attenuation), so the startup fade in aw88461_start() fades from 1023 to 1023 and the amplifier stays muted after probe until userspace raises "Playback Volume" above amp->profile_volume. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261130152838.9792= 63-1-xiaqinghuan@mail.ustc.edu.cn?part=3D2