From: sashiko-bot@kernel.org
To: "Shenghao Ding" <shenghao-ding@ti.com>
Cc: linux-sound@vger.kernel.org
Subject: Re: [PATCH v1] ASoC: tas2781: add realtime speaker protection data control for TAS2573
Date: Thu, 19 Nov 2026 01:23:10 +0000 [thread overview]
Message-ID: <sashiko-outbox-222281@kernel.org> (raw)
In-Reply-To: <20261119011102.1790-1-shenghao-ding@ti.com>
Thank you for your contribution! Sashiko AI review found 3 potential
issues to consider:
- [Medium] ASoC: tas2781: buffer offset shift on error in
tas2573_status_get_common()
- [Low] ASoC: tas2781: duplicate report logic in
tas2573_calib_status_get()
- [Low] ASoC: tas2781: use devm_kzalloc_obj() in
create_tas2573_rt_spk_data_ktrl()
--
commit ab506d198e775a76f5fde0b4b1d45d99fc376412
Author: Shenghao Ding <shenghao-ding@ti.com>
ASoC: tas2781: add realtime speaker protection data control for TAS2573
This commit introduces a common register-map report helper for TAS2573 and
extends the "Real-time Speaker Impedance" control into "Real-time Speaker
Protection Data" covering seven protection registers.
> diff --git a/sound/soc/codecs/tas2781-i2c.c b/sound/soc/codecs/tas2781-i2c.c
> index 984cb67476a53..e44a1d460c703 100644
> --- a/sound/soc/codecs/tas2781-i2c.c
> +++ b/sound/soc/codecs/tas2781-i2c.c
> @@ -1544,37 +1544,62 @@ static int create_tas2781_cali_start_ktrl(struct tasdevice_priv
> return 0;
> }
>
> -static int tas2573_re_get(struct snd_kcontrol *kcontrol,
> - struct snd_ctl_elem_value *ucontrol)
> +/*
> + * Common helper: shared by all controls that read a group of registers and
> + * pack the results into a report.
> + */
> +static int tas2573_status_get_common(struct snd_kcontrol *kcontrol,
> + struct snd_ctl_elem_value *ucontrol, const struct tasdev_reg_map *map)
> {
> struct snd_soc_component *comp = snd_kcontrol_chip(kcontrol);
> struct tasdevice_priv *priv = snd_soc_component_get_drvdata(comp);
> unsigned char *dst = ucontrol->value.bytes.data;
> struct soc_bytes_ext *bytes_ext =
> - (struct soc_bytes_ext *) kcontrol->private_value;
> + (struct soc_bytes_ext *)kcontrol->private_value;
> + unsigned int j, k, val;
> unsigned int i = 0;
> - unsigned int j;
> int rc;
>
> - guard(mutex)(&priv->codec_lock);
> + /* Report header: max size and 'r' marker */
> dst[i++] = bytes_ext->max;
> dst[i++] = 'r';
>
> - dst[i++] = TASDEVICE_BOOK_ID(TAS2573_RE_OUT);
> - dst[i++] = TASDEVICE_PAGE_ID(TAS2573_RE_OUT);
> - dst[i++] = TASDEVICE_PAGE_REG(TAS2573_RE_OUT);
> -
> + /* Emit book/page/reg triplets for every register in the map */
> + for (j = 0; j < map->nregs; j++) {
> + dst[i++] = TASDEVICE_BOOK_ID(map->regs[j]);
> + dst[i++] = TASDEVICE_PAGE_ID(map->regs[j]);
> + dst[i++] = TASDEVICE_PAGE_REG(map->regs[j]);
> + }
> dst[i++] = 'D';
>
> + guard(mutex)(&priv->codec_lock);
> +
> + /*
> + * Read each channel: first register via single read, the rest
> + * via bulk read (4 bytes each).
> + */
> for (j = 0; j < priv->ndev; j++) {
> dst[i++] = j;
> + dst[i++] = 0;
> + dst[i++] = 0;
> + dst[i++] = 0;
>
> - rc = tasdevice_dev_bulk_read(priv, j, TAS2573_RE_OUT,
> - &dst[i], 4);
> + rc = tasdevice_dev_read(priv, j, map->regs[0], &val);
> if (rc < 0)
> - dev_err(priv->dev, "chn %d bulk_rd err = %d\n", j, rc);
> + dev_err(priv->dev,
> + "chn %d %s[0] rd err = %d\n",
> + j, map->tag, rc);
> + else
> + dst[i++] = val;
>
> - i += 4;
> + for (k = 1; k < map->nregs; k++, i += 4) {
> + rc = tasdevice_dev_bulk_read(priv, j, map->regs[k],
> + &dst[i], 4);
> + if (rc < 0)
> + dev_err(priv->dev,
> + "chn %d %s[%u] bulk_rd err = %d\n",
> + j, map->tag, k, rc);
> + }
> }
>
> return 0;
[Severity: Medium]
Does an error from tasdevice_dev_read() leave i misaligned by one byte in
dst[]?
Unlike the pre-patch tas2573_re_get() and the bulk-read loop below it, the
rc < 0 branch skips incrementing i for the fourth byte of map->regs[0], so
the remaining registers for channel j and all subsequent channels are
written shifted left by one byte in the fixed-layout report buffer.
[Severity: Low]
This isn't a bug, but tas2573_calib_status_get() right below
tas2573_status_get_common() still open-codes an identical copy of this
report-packing and register-reading loop over fct_status_regs[] instead of
using tas2573_status_get_common().
> @@ -1682,37 +1707,48 @@ static int create_tas2573_cali_status_ktrl(struct tasdevice_priv
> return 0;
> }
>
> -static int create_tas2573_cali_re_ktrl(struct tasdevice_priv
> +/* Realtime sp data control */
> +static int tas2573_rt_get(struct snd_kcontrol *kcontrol,
> + struct snd_ctl_elem_value *ucontrol)
> +{
> + return tas2573_status_get_common(kcontrol, ucontrol,
> + &tas2573_rt_data_map);
> +}
> +
> +static int create_tas2573_rt_spk_data_ktrl(struct tasdevice_priv
> *priv, struct snd_kcontrol_new *cali_ctrl)
> {
> struct soc_bytes_ext *ext_cali_start;
> char *cali_start_name;
>
> - ext_cali_start = devm_kzalloc_obj(priv->dev, *ext_cali_start);
> + ext_cali_start = devm_kzalloc(priv->dev,
> + sizeof(*ext_cali_start), GFP_KERNEL);
[Severity: Low]
This reverts the devm_kzalloc_obj() conversion from 4dd10fbbeb9c
("treewide: Convert devm_kmalloc() family to the devm_kmalloc_obj()
family"), diverging from the neighboring kcontrol helpers in this file.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261119011102.1790-1-shenghao-ding@ti.com?part=1
next prev parent reply other threads:[~2026-11-19 1:23 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-19 1:11 [PATCH v1] ASoC: tas2781: add realtime speaker protection data control for TAS2573 Shenghao Ding
2026-11-19 1:23 ` sashiko-bot [this message]
2026-11-19 22:30 ` Mark Brown
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-222281@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=linux-sound@vger.kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
--cc=shenghao-ding@ti.com \
/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.