* [PATCH 0/3] ALSA: hda: Separate codec read status from response
@ 2026-12-03 17:04 Sreeraj S Kurup
2026-12-03 17:05 ` [PATCH 1/3] ALSA: hda: core: Fix command creation error handling Sreeraj S Kurup
` (3 more replies)
0 siblings, 4 replies; 10+ messages in thread
From: Sreeraj S Kurup @ 2026-12-03 17:04 UTC (permalink / raw)
To: perex, tiwai, lgirdwood, broonie
Cc: linux-sound, linux-kernel, Sreeraj S Kurup
Hi,
This series improves error handling in the HDA codec command and read
APIs.
Currently, snd_hdac_make_cmd() returns an unsigned int and uses -1 to
indicate an invalid command. Since -1 is converted to 0xffffffff,
which can also represent a valid encoded HDA command, callers cannot
reliably distinguish an error from a valid command.
This series changes snd_hdac_make_cmd() to return an integer status
and provide the encoded command through an output parameter. It also
updates snd_hdac_codec_read() to return an integer status and provide
the codec response through an output parameter.
The affected callers in the HDA core and ASoC HDMI codec driver are
updated to use the new API and handle errors appropriately.
Patch overview:
1. ALSA: hda: core: Fix command creation error handling
2. ALSA: hda: hdmi_chmap: Update HDMI channel map codec read callers
3. ASoC: codecs: hdac_hdmi: Update codec read API callers
Patches 2 and 3 depend on the API changes introduced in patch 1.
Please let me know if any changes are needed.
Thanks,
Sreeraj
Sreeraj S Kurup (3):
ALSA: hda: core: Fix command creation error handling
ALSA: hda: hdmi_chmap: Update HDMI channel map codec read callers
ASoC: codecs: hdac_hdmi: Update codec read API callers
include/sound/hdaudio.h | 2 +-
sound/hda/core/device.c | 69 ++++++++++++++++++++++++----------
sound/hda/core/hdmi_chmap.c | 30 ++++++++++++---
sound/soc/codecs/hdac_hdmi.c | 72 +++++++++++++++++++++++-------------
4 files changed, 123 insertions(+), 50 deletions(-)
--
2.55.0
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH 1/3] ALSA: hda: core: Fix command creation error handling
2026-12-03 17:04 [PATCH 0/3] ALSA: hda: Separate codec read status from response Sreeraj S Kurup
@ 2026-12-03 17:05 ` Sreeraj S Kurup
2026-12-03 18:12 ` sashiko-bot
2026-12-03 17:05 ` [PATCH 2/3] ALSA: hda: hdmi_chmap: Update HDMI channel map codec read callers Sreeraj S Kurup
` (2 subsequent siblings)
3 siblings, 1 reply; 10+ messages in thread
From: Sreeraj S Kurup @ 2026-12-03 17:05 UTC (permalink / raw)
To: perex, tiwai, lgirdwood, broonie
Cc: linux-sound, linux-kernel, Sreeraj S Kurup
snd_hdac_make_cmd() returns -1 when one of the command fields is
out of range. However, its return type is unsigned int, so -1 is
converted to 0xffffffff.
Since 0xffffffff can also be a valid encoded HDA command, callers
cannot reliably distinguish an invalid command from a valid one.
Change snd_hdac_make_cmd() to return an integer status and store
the encoded command through an output parameter. Return -EINVAL
when a command field is out of range and 0 on success.
Update snd_hdac_read(), codec_read() and codec_write() to check
the command creation status before executing the command.
Also change codec_read() and snd_hdac_codec_read() to return an
integer status and provide the codec response through an output
parameter. This separates the response value from the error
status and makes error handling clearer.
Update snd_hdac_sync_power_state() to check the return status
before using the codec response.
This ensures that invalid commands are not passed to
snd_hdac_exec_verb() and that codec responses are handled
separately from errors.
Signed-off-by: Sreeraj S Kurup <sreekuttan2156239@gmail.com>
---
include/sound/hdaudio.h | 2 +-
sound/hda/core/device.c | 69 +++++++++++++++++++++++++++++------------
2 files changed, 51 insertions(+), 20 deletions(-)
diff --git a/include/sound/hdaudio.h b/include/sound/hdaudio.h
index 04fd4794bcee..7d9c034efc1b 100644
--- a/include/sound/hdaudio.h
+++ b/include/sound/hdaudio.h
@@ -155,7 +155,7 @@ bool snd_hdac_is_supported_format(struct hdac_device *codec, hda_nid_t nid,
unsigned int format);
int snd_hdac_codec_read(struct hdac_device *hdac, hda_nid_t nid,
- int flags, unsigned int verb, unsigned int parm);
+ int flags, unsigned int verb, unsigned int parm, unsigned int *res);
int snd_hdac_codec_write(struct hdac_device *hdac, hda_nid_t nid,
int flags, unsigned int verb, unsigned int parm);
bool snd_hdac_check_power_state(struct hdac_device *hdac,
diff --git a/sound/hda/core/device.c b/sound/hda/core/device.c
index 6187ffaedbfa..d43c949af77c 100644
--- a/sound/hda/core/device.c
+++ b/sound/hda/core/device.c
@@ -219,27 +219,34 @@ EXPORT_SYMBOL_GPL(snd_hdac_codec_modalias);
* @nid: NID to encode
* @verb: verb to encode
* @parm: parameter to encode
+ * @cmd: pointer to store the encoded command.
*
- * Return an encoded command verb or -1 for error.
+ * Return 0 on success, or a negative error code.
+ * The encoded command is stored in @cmd.
*/
-static unsigned int snd_hdac_make_cmd(struct hdac_device *codec, hda_nid_t nid,
- unsigned int verb, unsigned int parm)
+static int snd_hdac_make_cmd(struct hdac_device *codec, hda_nid_t nid,
+ unsigned int verb, unsigned int parm,
+ unsigned int *cmd)
{
u32 val, addr;
+ if (!cmd)
+ return -EINVAL;
+
addr = codec->addr;
if ((addr & ~0xf) || (nid & ~0x7f) ||
(verb & ~0xfff) || (parm & ~0xffff)) {
dev_err(&codec->dev, "out of range cmd %x:%x:%x:%x\n",
addr, nid, verb, parm);
- return -1;
+ return -EINVAL;
}
val = addr << 28;
val |= (u32)nid << 20;
val |= verb << 8;
val |= parm;
- return val;
+ *cmd = val;
+ return 0;
}
/**
@@ -276,7 +283,12 @@ int snd_hdac_exec_verb(struct hdac_device *codec, unsigned int cmd,
int snd_hdac_read(struct hdac_device *codec, hda_nid_t nid,
unsigned int verb, unsigned int parm, unsigned int *res)
{
- unsigned int cmd = snd_hdac_make_cmd(codec, nid, verb, parm);
+ unsigned int cmd;
+ int err;
+
+ err = snd_hdac_make_cmd(codec, nid, verb, parm, &cmd);
+ if (err)
+ return err;
return snd_hdac_exec_verb(codec, cmd, 0, res);
}
@@ -1048,22 +1060,30 @@ bool snd_hdac_is_supported_format(struct hdac_device *codec, hda_nid_t nid,
}
EXPORT_SYMBOL_GPL(snd_hdac_is_supported_format);
-static unsigned int codec_read(struct hdac_device *hdac, hda_nid_t nid,
- int flags, unsigned int verb, unsigned int parm)
+static int codec_read(struct hdac_device *hdac, hda_nid_t nid,
+ int flags, unsigned int verb, unsigned int parm,
+ unsigned int *res)
{
- unsigned int cmd = snd_hdac_make_cmd(hdac, nid, verb, parm);
- unsigned int res;
+ unsigned int cmd;
+ int err;
- if (snd_hdac_exec_verb(hdac, cmd, flags, &res))
- return -1;
+ err = snd_hdac_make_cmd(hdac, nid, verb, parm, &cmd);
+ if (err)
+ return err;
+
+ return snd_hdac_exec_verb(hdac, cmd, flags, res);
- return res;
}
static int codec_write(struct hdac_device *hdac, hda_nid_t nid,
int flags, unsigned int verb, unsigned int parm)
{
- unsigned int cmd = snd_hdac_make_cmd(hdac, nid, verb, parm);
+ int err;
+ unsigned int cmd;
+
+ err = snd_hdac_make_cmd(hdac, nid, verb, parm, &cmd);
+ if (err)
+ return err;
return snd_hdac_exec_verb(hdac, cmd, flags, NULL);
}
@@ -1075,15 +1095,23 @@ static int codec_write(struct hdac_device *hdac, hda_nid_t nid,
* @flags: optional bit flags
* @verb: the verb to send
* @parm: the parameter for the verb
+ * @res: pointer to store the codec response
*
* Send a single command and read the corresponding response.
*
- * Returns the obtained response value, or -1 for an error.
+ * Returns 0 on success, or a negative error code.
*/
int snd_hdac_codec_read(struct hdac_device *hdac, hda_nid_t nid,
- int flags, unsigned int verb, unsigned int parm)
+ int flags, unsigned int verb, unsigned int parm,
+ unsigned int *res)
{
- return codec_read(hdac, nid, flags, verb, parm);
+ int err;
+
+ err = codec_read(hdac, nid, flags, verb, parm, res);
+ if (err < 0)
+ return err;
+
+ return 0;
}
EXPORT_SYMBOL_GPL(snd_hdac_codec_read);
@@ -1145,8 +1173,11 @@ unsigned int snd_hdac_sync_power_state(struct hdac_device *codec,
unsigned int state, actual_state, count;
for (count = 0; count < 500; count++) {
- state = snd_hdac_codec_read(codec, nid, 0,
- AC_VERB_GET_POWER_STATE, 0);
+ if (snd_hdac_codec_read(codec, nid, 0,
+ AC_VERB_GET_POWER_STATE, 0, &state)) {
+ msleep(20);
+ break;
+ }
if (state & AC_PWRST_ERROR) {
msleep(20);
break;
--
2.55.0
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH 2/3] ALSA: hda: hdmi_chmap: Update HDMI channel map codec read callers
2026-12-03 17:04 [PATCH 0/3] ALSA: hda: Separate codec read status from response Sreeraj S Kurup
2026-12-03 17:05 ` [PATCH 1/3] ALSA: hda: core: Fix command creation error handling Sreeraj S Kurup
@ 2026-12-03 17:05 ` Sreeraj S Kurup
2026-12-03 18:22 ` sashiko-bot
2026-12-03 17:05 ` [PATCH 3/3] ASoC: codecs: hdac_hdmi: Update codec read API callers Sreeraj S Kurup
2026-12-03 17:33 ` [PATCH 0/3] ALSA: hda: Separate codec read status from response Takashi Iwai
3 siblings, 1 reply; 10+ messages in thread
From: Sreeraj S Kurup @ 2026-12-03 17:05 UTC (permalink / raw)
To: perex, tiwai, lgirdwood, broonie
Cc: linux-sound, linux-kernel, Sreeraj S Kurup
Update callers of snd_hdac_codec_read() in hdmi_chmap.c to use
the new status and output parameter interface.
Check the return status before using the codec response, and
propagate read errors from the channel mapping helper functions.
Also avoid updating the converter channel count when reading the
current channel count fails.
Signed-off-by: Sreeraj S Kurup <sreekuttan2156239@gmail.com>
---
sound/hda/core/hdmi_chmap.c | 30 +++++++++++++++++++++++++-----
1 file changed, 25 insertions(+), 5 deletions(-)
diff --git a/sound/hda/core/hdmi_chmap.c b/sound/hda/core/hdmi_chmap.c
index c897fc443467..e9e599154ef1 100644
--- a/sound/hda/core/hdmi_chmap.c
+++ b/sound/hda/core/hdmi_chmap.c
@@ -190,21 +190,41 @@ static int hdmi_pin_set_slot_channel(struct hdac_device *codec,
static int hdmi_pin_get_slot_channel(struct hdac_device *codec,
hda_nid_t pin_nid, int asp_slot)
{
- return (snd_hdac_codec_read(codec, pin_nid, 0,
+ unsigned int res;
+ int err;
+
+ err = snd_hdac_codec_read(codec, pin_nid, 0,
AC_VERB_GET_HDMI_CHAN_SLOT,
- asp_slot) & 0xf0) >> 4;
+ asp_slot, &res);
+ if (err < 0)
+ return err;
+
+ return (res & 0xf0) >> 4;
}
static int hdmi_get_channel_count(struct hdac_device *codec, hda_nid_t cvt_nid)
{
- return 1 + snd_hdac_codec_read(codec, cvt_nid, 0,
- AC_VERB_GET_CVT_CHAN_COUNT, 0);
+ unsigned int res;
+ int err;
+
+ err = snd_hdac_codec_read(codec, cvt_nid, 0,
+ AC_VERB_GET_CVT_CHAN_COUNT, 0, &res);
+ if (err < 0)
+ return err;
+
+ return 1 + res;
}
static void hdmi_set_channel_count(struct hdac_device *codec,
hda_nid_t cvt_nid, int chs)
{
- if (chs != hdmi_get_channel_count(codec, cvt_nid))
+ int current;
+
+ current = hdmi_get_channel_count(codec, cvt_nid);
+ if (current < 0)
+ return;
+
+ if (chs != current)
snd_hdac_codec_write(codec, cvt_nid, 0,
AC_VERB_SET_CVT_CHAN_COUNT, chs - 1);
}
--
2.55.0
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH 3/3] ASoC: codecs: hdac_hdmi: Update codec read API callers
2026-12-03 17:04 [PATCH 0/3] ALSA: hda: Separate codec read status from response Sreeraj S Kurup
2026-12-03 17:05 ` [PATCH 1/3] ALSA: hda: core: Fix command creation error handling Sreeraj S Kurup
2026-12-03 17:05 ` [PATCH 2/3] ALSA: hda: hdmi_chmap: Update HDMI channel map codec read callers Sreeraj S Kurup
@ 2026-12-03 17:05 ` Sreeraj S Kurup
2026-12-03 18:46 ` sashiko-bot
2026-12-03 17:33 ` [PATCH 0/3] ALSA: hda: Separate codec read status from response Takashi Iwai
3 siblings, 1 reply; 10+ messages in thread
From: Sreeraj S Kurup @ 2026-12-03 17:05 UTC (permalink / raw)
To: perex, tiwai, lgirdwood, broonie
Cc: linux-sound, linux-kernel, Sreeraj S Kurup
Update callers of snd_hdac_codec_read() in hdac_hdmi.c to use
the new status and output parameter interface.
Check the return status before using codec responses and handle
command failures appropriately in port selection, power
management and vendor-specific verb operations.
This ensures that codec read errors are handled separately
from response values.
Signed-off-by: Sreeraj S Kurup <sreekuttan2156239@gmail.com>
---
sound/soc/codecs/hdac_hdmi.c | 72 +++++++++++++++++++++++-------------
1 file changed, 47 insertions(+), 25 deletions(-)
diff --git a/sound/soc/codecs/hdac_hdmi.c b/sound/soc/codecs/hdac_hdmi.c
index f7922ffaad97..8dad9f1644f8 100644
--- a/sound/soc/codecs/hdac_hdmi.c
+++ b/sound/soc/codecs/hdac_hdmi.c
@@ -241,8 +241,15 @@ static int hdac_hdmi_get_port_len(struct hdac_device *hdev, hda_nid_t nid)
static int hdac_hdmi_port_select_get(struct hdac_device *hdev,
struct hdac_hdmi_port *port)
{
- return snd_hdac_codec_read(hdev, port->pin->nid,
- 0, AC_VERB_GET_DEVICE_SEL, 0);
+ unsigned int res;
+ int err;
+
+ err = snd_hdac_codec_read(hdev, port->pin->nid,
+ 0, AC_VERB_GET_DEVICE_SEL, 0, &res);
+ if (err < 0)
+ return err;
+
+ return res;
}
/*
@@ -253,6 +260,7 @@ static int hdac_hdmi_port_select_set(struct hdac_device *hdev,
struct hdac_hdmi_port *port)
{
int num_ports;
+ int selected;
if (!port->pin->mst_capable)
return 0;
@@ -271,7 +279,11 @@ static int hdac_hdmi_port_select_set(struct hdac_device *hdev,
snd_hdac_codec_write(hdev, port->pin->nid, 0,
AC_VERB_SET_DEVICE_SEL, port->id);
- if (port->id != hdac_hdmi_port_select_get(hdev, port))
+ selected = hdac_hdmi_port_select_get(hdev, port);
+ if (selected < 0)
+ return selected;
+
+ if (port->id != selected)
return -EIO;
dev_dbg(&hdev->dev, "Selected the port=%d\n", port->id);
@@ -740,15 +752,18 @@ static struct hdac_hdmi_pcm *hdac_hdmi_get_pcm(struct hdac_device *hdev,
static void hdac_hdmi_set_power_state(struct hdac_device *hdev,
hda_nid_t nid, unsigned int pwr_state)
{
- int count;
- unsigned int state;
+ int count, err;
+ unsigned int state, res;
if (snd_hdac_get_wcaps(hdev, nid) & AC_WCAP_POWER) {
if (!snd_hdac_check_power_state(hdev, nid, pwr_state)) {
for (count = 0; count < 10; count++) {
- snd_hdac_codec_read(hdev, nid, 0,
+ err = snd_hdac_codec_read(hdev, nid, 0,
AC_VERB_SET_POWER_STATE,
- pwr_state);
+ pwr_state, &res);
+ if (err < 0)
+ break;
+
state = snd_hdac_sync_power_state(hdev,
nid, pwr_state);
if (!(state & AC_PWRST_ERROR))
@@ -1401,38 +1416,40 @@ static int hdac_hdmi_add_pin(struct hdac_device *hdev, hda_nid_t nid)
static void hdac_hdmi_skl_enable_all_pins(struct hdac_device *hdev)
{
- unsigned int vendor_param;
+ unsigned int vendor_param, res;
struct hdac_hdmi_priv *hdmi = hdev_to_hdmi_priv(hdev);
unsigned int vendor_nid = hdmi->drv_data->vendor_nid;
+ int err;
- vendor_param = snd_hdac_codec_read(hdev, vendor_nid, 0,
- INTEL_GET_VENDOR_VERB, 0);
- if (vendor_param == -1 || vendor_param & INTEL_EN_ALL_PIN_CVTS)
+ err = snd_hdac_codec_read(hdev, vendor_nid, 0,
+ INTEL_GET_VENDOR_VERB, 0, &vendor_param);
+ if (err < 0 || (vendor_param & INTEL_EN_ALL_PIN_CVTS))
return;
vendor_param |= INTEL_EN_ALL_PIN_CVTS;
- vendor_param = snd_hdac_codec_read(hdev, vendor_nid, 0,
- INTEL_SET_VENDOR_VERB, vendor_param);
- if (vendor_param == -1)
+ err = snd_hdac_codec_read(hdev, vendor_nid, 0,
+ INTEL_SET_VENDOR_VERB, vendor_param, &res);
+ if (err < 0)
return;
}
static void hdac_hdmi_skl_enable_dp12(struct hdac_device *hdev)
{
- unsigned int vendor_param;
+ unsigned int vendor_param, res;
struct hdac_hdmi_priv *hdmi = hdev_to_hdmi_priv(hdev);
unsigned int vendor_nid = hdmi->drv_data->vendor_nid;
+ int err;
- vendor_param = snd_hdac_codec_read(hdev, vendor_nid, 0,
- INTEL_GET_VENDOR_VERB, 0);
- if (vendor_param == -1 || vendor_param & INTEL_EN_DP12)
+ err = snd_hdac_codec_read(hdev, vendor_nid, 0,
+ INTEL_GET_VENDOR_VERB, 0, &vendor_param);
+ if (err < 0 || (vendor_param & INTEL_EN_DP12))
return;
/* enable DP1.2 mode */
vendor_param |= INTEL_EN_DP12;
- vendor_param = snd_hdac_codec_read(hdev, vendor_nid, 0,
- INTEL_SET_VENDOR_VERB, vendor_param);
- if (vendor_param == -1)
+ err = snd_hdac_codec_read(hdev, vendor_nid, 0,
+ INTEL_SET_VENDOR_VERB, vendor_param, &res);
+ if (err < 0)
return;
}
@@ -1942,6 +1959,8 @@ static int hdac_hdmi_runtime_suspend(struct device *dev)
struct hdac_device *hdev = dev_to_hdac_dev(dev);
struct hdac_bus *bus = hdev->bus;
struct hdac_ext_link *hlink;
+ int ret;
+ unsigned int res;
dev_dbg(dev, "Enter: %s\n", __func__);
@@ -1956,8 +1975,10 @@ static int hdac_hdmi_runtime_suspend(struct device *dev)
* is received. So setting power state is ensured without using loop
* to read the state.
*/
- snd_hdac_codec_read(hdev, hdev->afg, 0, AC_VERB_SET_POWER_STATE,
- AC_PWRST_D3);
+ ret = snd_hdac_codec_read(hdev, hdev->afg, 0, AC_VERB_SET_POWER_STATE,
+ AC_PWRST_D3, &res);
+ if (ret < 0)
+ return ret;
hlink = snd_hdac_ext_bus_get_hlink_by_name(bus, dev_name(dev));
if (!hlink) {
@@ -1978,6 +1999,7 @@ static int hdac_hdmi_runtime_resume(struct device *dev)
struct hdac_device *hdev = dev_to_hdac_dev(dev);
struct hdac_bus *bus = hdev->bus;
struct hdac_ext_link *hlink;
+ unsigned int res;
dev_dbg(dev, "Enter: %s\n", __func__);
@@ -2000,8 +2022,8 @@ static int hdac_hdmi_runtime_resume(struct device *dev)
hdac_hdmi_skl_enable_dp12(hdev);
/* Power up afg */
- snd_hdac_codec_read(hdev, hdev->afg, 0, AC_VERB_SET_POWER_STATE,
- AC_PWRST_D0);
+ snd_hdac_codec_read(hdev, hdev->afg, 0, AC_VERB_SET_POWER_STATE,
+ AC_PWRST_D0, &res);
return 0;
}
--
2.55.0
^ permalink raw reply related [flat|nested] 10+ messages in thread
* Re: [PATCH 0/3] ALSA: hda: Separate codec read status from response
2026-12-03 17:04 [PATCH 0/3] ALSA: hda: Separate codec read status from response Sreeraj S Kurup
` (2 preceding siblings ...)
2026-12-03 17:05 ` [PATCH 3/3] ASoC: codecs: hdac_hdmi: Update codec read API callers Sreeraj S Kurup
@ 2026-12-03 17:33 ` Takashi Iwai
2026-12-03 18:10 ` Sreeraj S Kurup
2026-12-03 18:31 ` Sreeraj S Kurup
3 siblings, 2 replies; 10+ messages in thread
From: Takashi Iwai @ 2026-12-03 17:33 UTC (permalink / raw)
To: Sreeraj S Kurup
Cc: perex, tiwai, lgirdwood, broonie, linux-sound, linux-kernel
On Thu, 03 Dec 2026 18:04:59 +0100,
Sreeraj S Kurup wrote:
>
> Hi,
>
> This series improves error handling in the HDA codec command and read
> APIs.
>
> Currently, snd_hdac_make_cmd() returns an unsigned int and uses -1 to
> indicate an invalid command. Since -1 is converted to 0xffffffff,
> which can also represent a valid encoded HDA command, callers cannot
> reliably distinguish an error from a valid command.
>
> This series changes snd_hdac_make_cmd() to return an integer status
> and provide the encoded command through an output parameter. It also
> updates snd_hdac_codec_read() to return an integer status and provide
> the codec response through an output parameter.
>
> The affected callers in the HDA core and ASoC HDMI codec driver are
> updated to use the new API and handle errors appropriately.
>
> Patch overview:
>
> 1. ALSA: hda: core: Fix command creation error handling
> 2. ALSA: hda: hdmi_chmap: Update HDMI channel map codec read callers
> 3. ASoC: codecs: hdac_hdmi: Update codec read API callers
>
> Patches 2 and 3 depend on the API changes introduced in patch 1.
You can't do it in that way. Each patch (commit) must not break
builds.
Takashi
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH 0/3] ALSA: hda: Separate codec read status from response
2026-12-03 17:33 ` [PATCH 0/3] ALSA: hda: Separate codec read status from response Takashi Iwai
@ 2026-12-03 18:10 ` Sreeraj S Kurup
2026-12-03 18:31 ` Sreeraj S Kurup
1 sibling, 0 replies; 10+ messages in thread
From: Sreeraj S Kurup @ 2026-12-03 18:10 UTC (permalink / raw)
To: tiwai
Cc: broonie, lgirdwood, linux-kernel, linux-sound, perex,
sreekuttan2156239
Hi Takashi,
Thanks for the feedback.
Would it be okay if I combine all three patches into a single patch so that the API change and all affected
caller updates are included together, ensuring that the commit builds independently?
Please let me know if you have any concerns with this approach.
Thanks,
Sreeraj
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH 1/3] ALSA: hda: core: Fix command creation error handling
2026-12-03 17:05 ` [PATCH 1/3] ALSA: hda: core: Fix command creation error handling Sreeraj S Kurup
@ 2026-12-03 18:12 ` sashiko-bot
0 siblings, 0 replies; 10+ messages in thread
From: sashiko-bot @ 2026-12-03 18:12 UTC (permalink / raw)
To: Sreeraj S Kurup; +Cc: linux-sound
Thank you for your contribution! Sashiko AI review found 4 potential
issues to consider:
- [High] ALSA: hda: unupdated codec_read() call in
snd_hdac_check_power_state()
- [High] ALSA: hda: unupdated callers after snd_hdac_codec_read()
signature change
- [Medium] ALSA: hda: uninitialized or stale state in
snd_hdac_sync_power_state()
- [Low] ALSA: hda: false 0xffffffff rationale and redundant API redesign
--
commit fe0465b0edab0acacf0e239416a267a90e9cf600
Author: Sreeraj S Kurup <sreekuttan2156239@gmail.com>
ALSA: hda: core: Fix command creation error handling
This commit changes snd_hdac_make_cmd(), codec_read(), and
snd_hdac_codec_read() to return an integer error status and pass the
encoded command or codec response via an output pointer. It also updates
snd_hdac_read(), codec_write(), and snd_hdac_sync_power_state() to check
the returned error status.
> Since 0xffffffff can also be a valid encoded HDA command, callers
> cannot reliably distinguish an invalid command from a valid one.
[Severity: Low]
Is the 0xffffffff premise accurate? Because snd_hdac_make_cmd() limits
nid to 7 bits (nid & ~0x7f) shifted left by 20, bit 27 is always 0 and
0xffffffff can never be encoded; snd_hdac_bus_exec_verb_unlocked() and
codec_exec_verb() already reject cmd == ~0.
Checking snd_hdac_make_cmd() does not require changing the exported
snd_hdac_codec_read() signature, as codec_read() could still return -1
on error, and snd_hdac_read() already provides a status-returning read
helper with an output pointer.
Forwarding caller-supplied res directly to snd_hdac_exec_verb() without
checking for NULL also drops the previous synchronous RIRB wait when a
caller passes NULL and !bus->sync_write.
> diff --git a/include/sound/hdaudio.h b/include/sound/hdaudio.h
> index 682e10a0f6dba..749f70d518344 100644
> --- a/include/sound/hdaudio.h
> +++ b/include/sound/hdaudio.h
> @@ -155,7 +155,7 @@ bool snd_hdac_is_supported_format(struct hdac_device *codec, hda_nid_t nid,
> unsigned int format);
>
> int snd_hdac_codec_read(struct hdac_device *hdac, hda_nid_t nid,
> - int flags, unsigned int verb, unsigned int parm);
> + int flags, unsigned int verb, unsigned int parm, unsigned int *res);
[Severity: High]
Does changing the exported snd_hdac_codec_read() signature here break
compilation for unupdated callers?
snd_hda_codec_read() and snd_hda_codec_write_sync() in
include/sound/hda_codec.h still pass 5 arguments and are never updated
in this series, breaking all legacy HDA codec builds.
When updating snd_hda_codec_write_sync(), it needs a non-NULL dummy res
pointer so snd_hdac_bus_exec_verb_unlocked() does not execute
asynchronously when !bus->sync_write.
The callers in sound/hda/core/hdmi_chmap.c and
sound/soc/codecs/hdac_hdmi.c also fail to compile on this commit,
breaking bisectability until updated in commit "ALSA: hda: hdmi_chmap:
Update HDMI channel map codec read callers" and commit "ASoC: codecs:
hdac_hdmi: Update codec read API callers".
> diff --git a/sound/hda/core/device.c b/sound/hda/core/device.c
> index 6187ffaedbfa3..d43c949af77c2 100644
> --- a/sound/hda/core/device.c
> +++ b/sound/hda/core/device.c
[ ... ]
> @@ -1048,22 +1060,30 @@ bool snd_hdac_is_supported_format(struct hdac_device *codec, hda_nid_t nid,
> }
> EXPORT_SYMBOL_GPL(snd_hdac_is_supported_format);
>
> -static unsigned int codec_read(struct hdac_device *hdac, hda_nid_t nid,
> - int flags, unsigned int verb, unsigned int parm)
> +static int codec_read(struct hdac_device *hdac, hda_nid_t nid,
> + int flags, unsigned int verb, unsigned int parm,
> + unsigned int *res)
[Severity: High]
Was the codec_read() call in snd_hdac_check_power_state() missed here?
snd_hdac_check_power_state() in this same file still invokes
codec_read() with 5 arguments, breaking builds with CONFIG_SND_HDA_CORE
enabled across the series.
When updating it to pass &state, it also needs to check for a negative
return and return true (preserving the prior behavior where -1 had
AC_PWRST_ERROR set) instead of reading an uninitialized state.
[ ... ]
> @@ -1145,8 +1173,11 @@ unsigned int snd_hdac_sync_power_state(struct hdac_device *codec,
> unsigned int state, actual_state, count;
>
> for (count = 0; count < 500; count++) {
> - state = snd_hdac_codec_read(codec, nid, 0,
> - AC_VERB_GET_POWER_STATE, 0);
> + if (snd_hdac_codec_read(codec, nid, 0,
> + AC_VERB_GET_POWER_STATE, 0, &state)) {
> + msleep(20);
> + break;
> + }
> if (state & AC_PWRST_ERROR) {
> msleep(20);
> break;
[Severity: Medium]
Can this return an uninitialized or stale state when
snd_hdac_codec_read() fails?
state is declared uninitialized, and error paths such as call_exec_verb()
failing runtime PM return a negative error without writing *res. A
failure on the first iteration returns an uninitialized stack value,
while a failure on a later iteration returns the previous non-error
state.
Callers like hda_set_power_state() and hdac_hdmi_set_power_state() check
AC_PWRST_ERROR in the returned state to retry failed transitions, and
hda_codec_runtime_suspend() tests state & AC_PWRST_CLK_STOP_OK. Setting
state = AC_PWRST_ERROR (or -1) before breaking preserves the previous
error contract.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261203170741.3873-1-sreekuttan2156239@gmail.com?part=1
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH 2/3] ALSA: hda: hdmi_chmap: Update HDMI channel map codec read callers
2026-12-03 17:05 ` [PATCH 2/3] ALSA: hda: hdmi_chmap: Update HDMI channel map codec read callers Sreeraj S Kurup
@ 2026-12-03 18:22 ` sashiko-bot
0 siblings, 0 replies; 10+ messages in thread
From: sashiko-bot @ 2026-12-03 18:22 UTC (permalink / raw)
To: Sreeraj S Kurup; +Cc: linux-sound
Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [High] ALSA: hda: local variable current in hdmi_set_channel_count()
breaks build
- [High] ALSA: hda: split snd_hdac_codec_read() migration breaks build
and bisect
--
commit d54e70f2805e77d43db50fbde0556d0b48b00dcf
Author: Sreeraj S Kurup <sreekuttan2156239@gmail.com>
ALSA: hda: hdmi_chmap: Update HDMI channel map codec read callers
This commit updates the snd_hdac_codec_read() callers in hdmi_chmap.c to use
the new status and output parameter interface, propagating read errors and
skipping the channel count update when reading the current count fails.
> diff --git a/sound/hda/core/hdmi_chmap.c b/sound/hda/core/hdmi_chmap.c
> index c897fc443467c..e9e599154ef12 100644
> --- a/sound/hda/core/hdmi_chmap.c
> +++ b/sound/hda/core/hdmi_chmap.c
> @@ -190,21 +190,41 @@ static int hdmi_pin_set_slot_channel(struct hdac_device *codec,
> static int hdmi_pin_get_slot_channel(struct hdac_device *codec,
> hda_nid_t pin_nid, int asp_slot)
> {
> - return (snd_hdac_codec_read(codec, pin_nid, 0,
> + unsigned int res;
> + int err;
> +
> + err = snd_hdac_codec_read(codec, pin_nid, 0,
> AC_VERB_GET_HDMI_CHAN_SLOT,
> - asp_slot) & 0xf0) >> 4;
> + asp_slot, &res);
> + if (err < 0)
> + return err;
> +
> + return (res & 0xf0) >> 4;
> }
[Severity: High]
Does splitting the snd_hdac_codec_read() signature change across commits
break builds and git bisect?
Commit "ALSA: hda: core: Fix command creation error handling" changed
snd_hdac_codec_read() to six arguments, leaving callers in
include/sound/hda_codec.h (snd_hda_codec_read() and
snd_hda_codec_write_sync()) and sound/soc/codecs/hdac_hdmi.c broken.
Commit "ASoC: codecs: hdac_hdmi: Update codec read API callers" updates
hdac_hdmi.c later, but include/sound/hda_codec.h remains un-updated at the
end of the series. All callers need to be updated in the same commit as
the signature change, or migrated via a transitional helper first.
[ ... ]
> static void hdmi_set_channel_count(struct hdac_device *codec,
> hda_nid_t cvt_nid, int chs)
> {
> - if (chs != hdmi_get_channel_count(codec, cvt_nid))
> + int current;
> +
> + current = hdmi_get_channel_count(codec, cvt_nid);
> + if (current < 0)
> + return;
> +
> + if (chs != current)
> snd_hdac_codec_write(codec, cvt_nid, 0,
> AC_VERB_SET_CVT_CHAN_COUNT, chs - 1);
> }
[Severity: High]
Does naming this local variable current break the build?
current is a global macro expanding to get_current() via asm/current.h
(included through sound/control.h and linux/wait.h), so this fails to
compile whenever CONFIG_SND_HDA_CORE is enabled. Renaming it to something
like cur_chs would avoid the collision.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261203170741.3873-1-sreekuttan2156239@gmail.com?part=2
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH 0/3] ALSA: hda: Separate codec read status from response
2026-12-03 17:33 ` [PATCH 0/3] ALSA: hda: Separate codec read status from response Takashi Iwai
2026-12-03 18:10 ` Sreeraj S Kurup
@ 2026-12-03 18:31 ` Sreeraj S Kurup
1 sibling, 0 replies; 10+ messages in thread
From: Sreeraj S Kurup @ 2026-12-03 18:31 UTC (permalink / raw)
To: tiwai
Cc: broonie, lgirdwood, linux-kernel, linux-sound, perex,
sreekuttan2156239
Hi Takashi,
I reviewed your comments and the issues found by Sashiko AI. The review pointed
out that "0xffffffff" cannot be a valid command with the current command encoding.
It also found some missed callers and error-handling issues in my changes.
After reviewing these points, I think the proposed API change is not needed.
I'll drop this patchset instead of sending a new version.
Sorry for the noise, and thanks for your time.
Best regards,
Sreeraj
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH 3/3] ASoC: codecs: hdac_hdmi: Update codec read API callers
2026-12-03 17:05 ` [PATCH 3/3] ASoC: codecs: hdac_hdmi: Update codec read API callers Sreeraj S Kurup
@ 2026-12-03 18:46 ` sashiko-bot
0 siblings, 0 replies; 10+ messages in thread
From: sashiko-bot @ 2026-12-03 18:46 UTC (permalink / raw)
To: Sreeraj S Kurup; +Cc: linux-sound
Thank you for your contribution! Sashiko AI review found 7 potential
issues to consider:
- [High] ALSA: hda: snd_hdac_check_power_state() still calls
codec_read() with 5 args
- [High] ALSA: hda: hda_codec.h wrappers still call
snd_hdac_codec_read() with 5 args
- [High] ALSA: hda: hdmi_set_channel_count() local current collides with
kernel macro
- [Medium] ALSA: hda: snd_hdac_sync_power_state() returns uninitialized
or stale state
- [Medium] ALSA: hda: non-atomic snd_hdac_codec_read() change breaks
bisect and dup API
- [Medium] ASoC: hdac_hdmi: early break defeats retry loop in
hdac_hdmi_set_power_state()
- [Medium] ASoC: hdac_hdmi: aborting hdac_hdmi_runtime_suspend() on D3
read error
--
commit c39e00c18989bfbf7ab831cd560cf2b65326aa27
Author: Sreeraj S Kurup <sreekuttan2156239@gmail.com>
ASoC: codecs: hdac_hdmi: Update codec read API callers
This commit updates the snd_hdac_codec_read() callers in hdac_hdmi.c to
pass an output pointer for the codec response and check the returned error
status.
> diff --git a/sound/soc/codecs/hdac_hdmi.c b/sound/soc/codecs/hdac_hdmi.c
> index f7922ffaad973..8dad9f1644f89 100644
> --- a/sound/soc/codecs/hdac_hdmi.c
> +++ b/sound/soc/codecs/hdac_hdmi.c
> @@ -241,8 +241,15 @@ static int hdac_hdmi_get_port_len(struct hdac_device *hdev, hda_nid_t nid)
> static int hdac_hdmi_port_select_get(struct hdac_device *hdev,
> struct hdac_hdmi_port *port)
> {
> - return snd_hdac_codec_read(hdev, port->pin->nid,
> - 0, AC_VERB_GET_DEVICE_SEL, 0);
> + unsigned int res;
> + int err;
> +
> + err = snd_hdac_codec_read(hdev, port->pin->nid,
> + 0, AC_VERB_GET_DEVICE_SEL, 0, &res);
> + if (err < 0)
> + return err;
> +
> + return res;
> }
[Severity: Medium]
Does splitting the snd_hdac_codec_read() signature change across commits
break git bisect? Commit "ALSA: hda: core: Fix command creation error
handling" changed the exported prototype without updating callers in
sound/hda/core/hdmi_chmap.c and sound/soc/codecs/hdac_hdmi.c in the same
commit, so the intermediate commits fail to build.
Also, every updated call site passes 0 for flags, which the existing
snd_hdac_read() already provides with the same status-return and output
parameter interface. Switching these callers to snd_hdac_read() would
avoid changing snd_hdac_codec_read() at all.
[Severity: High]
Were the inline wrappers in include/sound/hda_codec.h missed when updating
snd_hdac_codec_read()? Both snd_hda_codec_read() and
snd_hda_codec_write_sync() still call snd_hdac_codec_read() with five
arguments, breaking the build for every translation unit that includes
include/sound/hda_codec.h.
Note that snd_hda_codec_read() callers expect the 32-bit response (or -1
on error) as the return value rather than the 0/negative status.
[Severity: High]
Does the local variable named current in hdmi_set_channel_count() break
compilation of sound/hda/core/hdmi_chmap.c? Commit "ALSA: hda:
hdmi_chmap: Update HDMI channel map codec read callers" added:
sound/hda/core/hdmi_chmap.c:hdmi_set_channel_count() {
int current;
current = hdmi_get_channel_count(codec, cvt_nid);
...
}
Because the included headers pull in asm/current.h, the global current
macro expands over the declaration and assignment, causing a syntax error
whenever CONFIG_SND_HDA_CORE is enabled.
[ ... ]
> @@ -740,15 +752,18 @@ static struct hdac_hdmi_pcm *hdac_hdmi_get_pcm(struct hdac_device *hdev,
> static void hdac_hdmi_set_power_state(struct hdac_device *hdev,
> hda_nid_t nid, unsigned int pwr_state)
> {
> - int count;
> - unsigned int state;
> + int count, err;
> + unsigned int state, res;
>
> if (snd_hdac_get_wcaps(hdev, nid) & AC_WCAP_POWER) {
> if (!snd_hdac_check_power_state(hdev, nid, pwr_state)) {
[Severity: High]
Does snd_hdac_check_power_state() still call codec_read() with five
arguments? After commit "ALSA: hda: core: Fix command creation error
handling" added the output parameter to codec_read(),
sound/hda/core/device.c fails to compile:
sound/hda/core/device.c:snd_hdac_check_power_state() {
unsigned int state = codec_read(hdac, nid, 0,
AC_VERB_GET_POWER_STATE, 0);
...
}
It also needs to pass &state and treat a negative error return the same
way AC_PWRST_ERROR was handled previously.
> for (count = 0; count < 10; count++) {
> - snd_hdac_codec_read(hdev, nid, 0,
> + err = snd_hdac_codec_read(hdev, nid, 0,
> AC_VERB_SET_POWER_STATE,
> - pwr_state);
> + pwr_state, &res);
> + if (err < 0)
> + break;
[Severity: Medium]
Does breaking out of the loop on err < 0 defeat the 10-attempt retry logic
here? Previously, a transient HDA verb or RIRB error continued into
snd_hdac_sync_power_state() and retried; now the first error aborts
immediately without logging or reporting failure.
Because hdac_hdmi_set_power_state() returns void, callers such as
hdac_hdmi_pin_output_widget_event() proceed to configure a pin or
converter widget that may still be in D3, leaving audio silent.
>
> state = snd_hdac_sync_power_state(hdev,
> nid, pwr_state);
> if (!(state & AC_PWRST_ERROR))
> break;
[Severity: Medium]
Can snd_hdac_sync_power_state() return an uninitialized or stale state
when snd_hdac_codec_read() fails? In sound/hda/core/device.c, state is
uninitialized on entry and is not set to AC_PWRST_ERROR before breaking
out on error:
sound/hda/core/device.c:snd_hdac_sync_power_state() {
unsigned int state, actual_state, count;
for (count = 0; count < 500; count++) {
if (snd_hdac_codec_read(codec, nid, 0,
AC_VERB_GET_POWER_STATE, 0, &state)) {
msleep(20);
break;
}
...
}
If codec_read() fails early (for example, snd_hdac_make_cmd() returning
-EINVAL or a runtime PM error in call_exec_verb()) without writing *res,
state holds stack garbage or a previous poll value without AC_PWRST_ERROR
set, causing callers to abort retries early. Assigning
state = AC_PWRST_ERROR before breaking restores the previous contract.
[ ... ]
> @@ -1942,6 +1959,8 @@ static int hdac_hdmi_runtime_suspend(struct device *dev)
[ ... ]
> * is received. So setting power state is ensured without using loop
> * to read the state.
> */
> - snd_hdac_codec_read(hdev, hdev->afg, 0, AC_VERB_SET_POWER_STATE,
> - AC_PWRST_D3);
> + ret = snd_hdac_codec_read(hdev, hdev->afg, 0, AC_VERB_SET_POWER_STATE,
> + AC_PWRST_D3, &res);
> + if (ret < 0)
> + return ret;
[Severity: Medium]
Can returning early on a D3 verb error wedge runtime PM and abort system
suspend? If snd_hdac_codec_read() returns -EIO (such as on an RIRB
timeout), rpm_suspend() sets dev->power.runtime_error = -EIO because it is
neither -EAGAIN nor -EBUSY, and nothing in this driver clears it.
Once runtime_error is set, later HDMI PCM opens fail with -EINVAL in
snd_soc_pcm_component_pm_runtime_get(), the skipped link and display power
teardown keeps the controller and display power well awake (and leaks
hlink->ref_count on unbind), and pm_runtime_force_suspend() aborts system
sleep. Logging the error and continuing with the teardown before
returning 0 would preserve the previous behavior.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261203170741.3873-1-sreekuttan2156239@gmail.com?part=3
^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2026-12-03 18:46 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-03 17:04 [PATCH 0/3] ALSA: hda: Separate codec read status from response Sreeraj S Kurup
2026-12-03 17:05 ` [PATCH 1/3] ALSA: hda: core: Fix command creation error handling Sreeraj S Kurup
2026-12-03 18:12 ` sashiko-bot
2026-12-03 17:05 ` [PATCH 2/3] ALSA: hda: hdmi_chmap: Update HDMI channel map codec read callers Sreeraj S Kurup
2026-12-03 18:22 ` sashiko-bot
2026-12-03 17:05 ` [PATCH 3/3] ASoC: codecs: hdac_hdmi: Update codec read API callers Sreeraj S Kurup
2026-12-03 18:46 ` sashiko-bot
2026-12-03 17:33 ` [PATCH 0/3] ALSA: hda: Separate codec read status from response Takashi Iwai
2026-12-03 18:10 ` Sreeraj S Kurup
2026-12-03 18:31 ` Sreeraj S Kurup
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox