From: sashiko-bot@kernel.org
To: "Qianhui Xu" <xiaqinghuan@mail.ustc.edu.cn>
Cc: linux-sound@vger.kernel.org, devicetree@vger.kernel.org,
robh@kernel.org, conor+dt@kernel.org
Subject: Re: [PATCH 2/2] ASoC: codecs: aw88461: add the Awinic AW88461 speaker amplifier driver
Date: Mon, 30 Nov 2026 15:52:44 +0000 [thread overview]
Message-ID: <sashiko-outbox-241519@kernel.org> (raw)
In-Reply-To: <20261130152838.979263-3-xiaqinghuan@mail.ustc.edu.cn>
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 <xiaqinghuan@mail.ustc.edu.cn>
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.
>
> +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 = false;
> + amp->faulted = true;
> + aw88461_reset(amp);
> + return error;
> +}
[ ... ]
> +static int aw88461_start(struct aw88461 *amp)
> +{
> + struct regmap *map = amp->aw_dev.regmap;
> + unsigned int status = 0, noise_gate, ready;
> + int ret;
> +
> + if (amp->faulted)
> + return -EIO;
> + if (amp->powered || !aw88461_active(amp))
> + return 0;
> + ret = regmap_update_bits(map, AW88461_SYSCTRL, AW88461_PWDN, 0);
> + if (ret)
> + goto stop;
> + amp->powered = true;
> + usleep_range(2000, 2200);
> + ret = regmap_read_poll_timeout(map, AW88461_SYSST, status,
> + (status & AW88461_PLL_LOCK) == AW88461_PLL_LOCK ||
> + !aw88461_active(amp),
> + 2000, 100000);
> + if (ret) {
> + dev_err(amp->aw_dev.dev, "PLL lock failed: %d, status %#x\n", ret, status);
> + 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 = 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 = regmap_update_bits(map, AW88461_SYSCTRL, AW88461_AMPPD, 0);
> + if (ret)
> + goto stop;
> + usleep_range(1000, 1200);
> + ret = regmap_read(map, AW88461_NGCTRL3, &noise_gate);
> + if (ret)
> + goto stop;
> + ready = AW88461_PLL_LOCK | AW88461_BOOST_READY;
> + if (!(noise_gate & AW88461_NOISE_GATE))
> + ready |= AW88461_SWITCHING;
> + ret = regmap_read_poll_timeout(map, AW88461_SYSST, status,
> + (status & ready) == ready || !aw88461_active(amp),
> + 2000, 20000);
> + if (ret) {
> + dev_err(amp->aw_dev.dev, "amplifier ready failed: %d, status %#x\n", ret, status);
> + goto stop;
> + }
> + if (!aw88461_active(amp))
> + return aw88461_stop(amp);
> + if (status & AW88461_FAULTS) {
> + ret = -EIO;
> + goto stop;
> + }
> + ret = regmap_update_bits(map, AW88461_SYSCTRL, AW88461_TXEN,
> + amp->profile_txen);
> + if (ret)
> + goto stop;
> + ret = regmap_update_bits(map, AW88461_SYSCTRL,
> + AW88461_HMUTE | AW88461_ULS_HMUTE, 0);
> + if (ret)
> + goto stop;
> + ret = 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 = 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)
== 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 == 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 = &->aw_dev;
> + const struct firmware *fw;
> + struct aw_container *cfg;
> + struct aw_sec_data_desc *regs = NULL;
> + const char *name;
> + unsigned int i, address, value;
> + int ret;
> +
> + ret = device_property_read_string(aw_dev->dev, "firmware-name", &name);
> + if (ret)
> + return ret;
> + ret = request_firmware(&fw, name, aw_dev->dev);
> + if (ret)
> + return ret;
> + if (fw->size < sizeof(struct aw_cfg_hdr)) {
> + ret = -EINVAL;
> + goto release;
> + }
> + if (fw->size > INT_MAX) {
> + ret = -EFBIG;
> + goto release;
> + }
> + cfg = devm_kzalloc(aw_dev->dev, struct_size(cfg, data, fw->size), GFP_KERNEL);
> + if (!cfg) {
> + ret = -ENOMEM;
> + goto release;
> + }
> + cfg->len = fw->size;
> + memcpy(cfg->data, fw->data, fw->size);
> + ret = aw88395_dev_load_acf_check(aw_dev, cfg);
> + if (ret)
> + goto release;
> + ret = aw88395_dev_cfg_load(aw_dev, cfg);
> + if (ret)
> + goto release;
> + for (i = 0; i < aw_dev->prof_info.count; i++) {
> + struct aw_prof_desc *profile = &aw_dev->prof_info.prof_desc[i];
> +
> + if (profile->id == AW88395_PROFILE_MUSIC) {
> + regs = &profile->sec_desc[AW88395_DATA_TYPE_REG];
> + break;
> + }
> + }
[Severity: Medium]
Does checking profile->id == AW88395_PROFILE_MUSIC work on V1 ACF firmware
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 = 0; i < prof_info->count; i++) {
prof_desc[i].id = i;
prof_info->prof_name_list[i] = 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 = 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.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261130152838.979263-1-xiaqinghuan@mail.ustc.edu.cn?part=2
prev parent reply other threads:[~2026-11-30 15:52 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-30 15:28 [PATCH 0/2] ASoC: aw88461: add the Awinic AW88461 speaker amplifier Qianhui Xu
2026-11-30 15:28 ` [PATCH 1/2] ASoC: dt-bindings: awinic,aw88395: add the AW88461 variant Qianhui Xu
2026-11-30 15:28 ` [PATCH 2/2] ASoC: codecs: aw88461: add the Awinic AW88461 speaker amplifier driver Qianhui Xu
2026-11-30 15:52 ` sashiko-bot [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=sashiko-outbox-241519@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=linux-sound@vger.kernel.org \
--cc=robh@kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
--cc=xiaqinghuan@mail.ustc.edu.cn \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.