From: Mark Brown <broonie@kernel.org>
To: Niranjan H Y <niranjan.hy@ti.com>
Cc: linux-sound@vger.kernel.org, linux-kernel@vger.kernel.org,
ckeepax@opensource.cirrus.com, lgirdwood@gmail.com,
perex@perex.cz, tiwai@suse.com, cezary.rojewski@intel.com,
peter.ujfalusi@linux.intel.com, yung-chuan.liao@linux.intel.com,
ranjani.sridharan@linux.intel.com, kai.vehmanen@linux.intel.com,
pierre-louis.bossart@linux.dev, baojun.xu@ti.com,
shenghao-ding@ti.com, sandeepk@ti.com, v-hampiholi@ti.com
Subject: Re: [PATCH v3 2/4] ASoC: tac5xx2-sdw: add soundwire based codec driver
Date: Tue, 31 Mar 2026 17:50:46 +0100 [thread overview]
Message-ID: <bf385693-40ca-44fe-bfda-7e9cf5a27328@sirena.org.uk> (raw)
In-Reply-To: <20260331151638.1281-2-niranjan.hy@ti.com>
[-- Attachment #1: Type: text/plain, Size: 3857 bytes --]
On Tue, Mar 31, 2026 at 08:46:36PM +0530, Niranjan H Y wrote:
> Add codec driver for tac5xx2 family of devices.
> +static int tac_cx11_get(struct snd_kcontrol *kcontrol,
> + struct snd_ctl_elem_value *ucontrol)
> +{
> + struct snd_soc_component *component;
> + struct tac5xx2_prv *tac_dev;
> +
> + ucontrol->value.enumerated.item[0] = 1; /* Default to DC:1 */
> +
> + if (!kcontrol || !kcontrol->private_data)
> + return 0;
> +
> + component = snd_kcontrol_chip(kcontrol);
> + if (!component)
> + return 0;
> +
> + tac_dev = snd_soc_component_get_drvdata(component);
> + if (!tac_dev)
> + return 0;
Shouldn't these be errors?
> +
> +static int tac_cx11_put(struct snd_kcontrol *kcontrol,
> + struct snd_ctl_elem_value *ucontrol)
> +{
> + ret = regmap_write(tac_dev->regmap,
> + SDW_SDCA_CTL(TAC_FUNCTION_ID_SM, TAC_SDCA_ENT_CX11,
> + TAC_SDCA_CTL_CX_CLK_SEL, 0),
> + val);
> + if (ret) {
> + dev_dbg(tac_dev->dev, "cx put failed");
> + return -EIO;
> + }
Probably nicer to return the error code you got here, and also include
it in the log message - that'll help people figure out what's going on
if things do go wrong.
> +/* Volume controls for mic, hp and mic cap */
> +static const struct snd_kcontrol_new tac5xx2_snd_controls[] = {
> + SOC_SINGLE_RANGE_TLV("Left Amp Volume", TAC_AMP_LVL_CFG0, 2, 0, 44, 1,
> + tac5xx2_amp_tlv),
> + SOC_SINGLE_RANGE_TLV("Right Amp Volume", TAC_AMP_LVL_CFG1, 2, 0, 44, 1,
> + tac5xx2_amp_tlv),
What's the logic behind two mono controls rather than stereo controls?
There's a bunch of these in the driver.
> +static int tac_sdw_hw_params(struct snd_pcm_substream *substream,
> + struct snd_pcm_hw_params *params,
> + struct snd_soc_dai *dai)
> +{
> + if (dai->id == TAC5XX2_DMIC) {
> + } else if (dai->id == TAC5XX2_UAJ) {
> + } else if (dai->id == TAC5XX2_SPK) {
> + } else {
> + }
This should be a switch statement for clarity and scalability.
> + switch (params_rate(params)) {
> + case 48000:
> + sample_rate_idx = 0x01;
> + break;
> + case 44100:
> + sample_rate_idx = 0x02;
> + break;
> + case 96000:
> + sample_rate_idx = 0x03;
> + break;
> + case 88200:
> + sample_rate_idx = 0x04;
> + break;
> + default:
> + dev_err(tac_dev->dev, "Unsupported sample rate: %d Hz",
> + params_rate(params));
> + return -EINVAL;
> + }
This allows userspace to spam the logs doesn't it?
> + if (function_id == TAC_FUNCTION_ID_SM) {
> + } else if (function_id == TAC_FUNCTION_ID_UAJ) {
Again, switch statement. There's a bunch of these in teh driver.
> +static s32 tac_fw_read_hdr(const u8 *data, struct tac_fw_hdr *hdr)
> +{
> + hdr->size = get_unaligned_le32(data);
> +
> + return TAC_FW_HDR_SIZE;
> +}
> +static s32 tac_download_fw_to_hw(struct tac5xx2_prv *tac_dev)
> +{
> + buf = tac_dev->fw_data;
> + img_sz = tac_dev->fw_size;
> +
> + dev_dbg(tac_dev->dev, "Downloading cached firmware to HW, size=%zu\n", img_sz);
> +
> + offset += tac_fw_read_hdr(buf, hdr);
> + if (hdr->size != img_sz) {
We don't validate that the file has enough data to read here, there's a
check after the request_firmware() that the file is non-zero but it
might just be a single byte.
> + while (offset < img_sz && num_files < TAC_MAX_FW_CHUNKS) {
> + if (offset + 20 > img_sz) {
> + dev_warn(tac_dev->dev, "Incomplete block header at offset %d\n",
> + offset);
> + break;
> + }
> + offset += tac_fw_get_next_file(&buf[offset], &files[num_files]);
> + num_files++;
> + }
I can't see anything that validates that we stay within the buffer here,
we're checking if the header is in the buffer but not the payload and if
we do overflow we just exit the loop and...
> +
> + if (num_files == 0) {
> + dev_err(tac_dev->dev, "firmware with no files\n");
> + ret = -EINVAL;
> + goto out;
> + }
...so long as we found at least one block we'll just carry on.
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
next prev parent reply other threads:[~2026-03-31 16:50 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-31 15:16 [PATCH v3 1/4] ASoC: SDCA: Export Q7.8 volume control helpers Niranjan H Y
2026-03-31 15:16 ` [PATCH v3 2/4] ASoC: tac5xx2-sdw: add soundwire based codec driver Niranjan H Y
2026-03-31 16:50 ` Mark Brown [this message]
2026-03-31 15:16 ` [PATCH v3 3/4] ASoC: sdw_utils: TI amp utility for tac5xx2 family Niranjan H Y
2026-03-31 15:16 ` [PATCH v3 4/4] ASoC: tac5xx2-sdw: ACPI match for intel mtl platform Niranjan H Y
2026-03-31 15:38 ` [PATCH v3 1/4] ASoC: SDCA: Export Q7.8 volume control helpers Charles Keepax
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=bf385693-40ca-44fe-bfda-7e9cf5a27328@sirena.org.uk \
--to=broonie@kernel.org \
--cc=baojun.xu@ti.com \
--cc=cezary.rojewski@intel.com \
--cc=ckeepax@opensource.cirrus.com \
--cc=kai.vehmanen@linux.intel.com \
--cc=lgirdwood@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-sound@vger.kernel.org \
--cc=niranjan.hy@ti.com \
--cc=perex@perex.cz \
--cc=peter.ujfalusi@linux.intel.com \
--cc=pierre-louis.bossart@linux.dev \
--cc=ranjani.sridharan@linux.intel.com \
--cc=sandeepk@ti.com \
--cc=shenghao-ding@ti.com \
--cc=tiwai@suse.com \
--cc=v-hampiholi@ti.com \
--cc=yung-chuan.liao@linux.intel.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®