* [PATCH v2 0/3] ALSA: ctxfi: Clean up DAIO resource allocation
@ 2026-04-01 9:01 Harin Lee
2026-04-01 9:01 ` [PATCH v2 1/3] ALSA: ctxfi: Rename SPDIFI1 to SPDIFI_BAY Harin Lee
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: Harin Lee @ 2026-04-01 9:01 UTC (permalink / raw)
To: Jaroslav Kysela, Takashi Iwai; +Cc: linux-sound, linux-kernel, Harin Lee
Clean up the resource allocation in atc_get_resources() and related
functions, on top of the recent SPDIFI1 fixes.
The earlier refactoring introduced a kernel crash on hw20k2, where
daio_device_index() returned -EINVAL for the SPDIFI1 type and the
value was used as an unsigned array offset. On my development system
(64G memory), this did not manifest as a crash, making the bug
difficult to catch during testing.
Tested on the real hw20k2 hardware with mem=8G to verify the original
crash and confirm these patches.
Changes in v2:
- Add atc_spdif_in_type() helper to avoid ternary operators in
multiple places
- Rewrite the SPDIFI type skip condition as explicit model checks
Harin Lee (3):
ALSA: ctxfi: Rename SPDIFI1 to SPDIFI_BAY
ALSA: ctxfi: Use correct DAIO type for da_desc
ALSA: ctxfi: Precompute SRC allocation loop bound
sound/pci/ctxfi/ctatc.c | 31 ++++++++++++++++---------------
sound/pci/ctxfi/ctdaio.c | 5 ++---
sound/pci/ctxfi/ctdaio.h | 2 +-
3 files changed, 19 insertions(+), 19 deletions(-)
--
2.53.0
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH v2 1/3] ALSA: ctxfi: Rename SPDIFI1 to SPDIFI_BAY
2026-04-01 9:01 [PATCH v2 0/3] ALSA: ctxfi: Clean up DAIO resource allocation Harin Lee
@ 2026-04-01 9:01 ` Harin Lee
2026-04-01 9:01 ` [PATCH v2 2/3] ALSA: ctxfi: Use correct DAIO type for da_desc Harin Lee
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: Harin Lee @ 2026-04-01 9:01 UTC (permalink / raw)
To: Jaroslav Kysela, Takashi Iwai; +Cc: linux-sound, linux-kernel, Harin Lee
Rename the SPDIFI1 enum value to SPDIFI_BAY to better reflect its
purpose as the S/PDIF input on the internal drive bay, as opposed to
the S/PDIF input via Flexijack or optical (SPDIFIO; not SPDIFI-zero).
Signed-off-by: Harin Lee <me@harin.net>
---
sound/pci/ctxfi/ctatc.c | 4 ++--
sound/pci/ctxfi/ctdaio.c | 6 +++---
sound/pci/ctxfi/ctdaio.h | 2 +-
3 files changed, 6 insertions(+), 6 deletions(-)
diff --git a/sound/pci/ctxfi/ctatc.c b/sound/pci/ctxfi/ctatc.c
index da2667cb2489..9e0532fb33ff 100644
--- a/sound/pci/ctxfi/ctatc.c
+++ b/sound/pci/ctxfi/ctatc.c
@@ -1429,10 +1429,10 @@ static int atc_get_resources(struct ct_atc *atc)
for (i = 0; i < NUM_DAIOTYP; i++) {
if (((i == MIC) && !cap.dedicated_mic) ||
((i == RCA) && !cap.dedicated_rca) ||
- i == SPDIFI1)
+ i == SPDIFI_BAY)
continue;
if (atc->model == CTSB073X && i == SPDIFIO)
- da_desc.type = SPDIFI1;
+ da_desc.type = SPDIFI_BAY;
else
da_desc.type = i;
da_desc.output = (i < LINEIM) || (i == RCA);
diff --git a/sound/pci/ctxfi/ctdaio.c b/sound/pci/ctxfi/ctdaio.c
index 4dbb1dd7af32..128cf2f69ac1 100644
--- a/sound/pci/ctxfi/ctdaio.c
+++ b/sound/pci/ctxfi/ctdaio.c
@@ -35,7 +35,7 @@ static const struct daio_rsc_idx idx_20k1[NUM_DAIOTYP] = {
[LINEIM] = {.left = 0x1b5, .right = 0x1bd},
[SPDIFOO] = {.left = 0x20, .right = 0x21},
[SPDIFIO] = {.left = 0x15, .right = 0x1d},
- [SPDIFI1] = {.left = 0x95, .right = 0x9d},
+ [SPDIFI_BAY] = {.left = 0x95, .right = 0x9d},
};
static const struct daio_rsc_idx idx_20k2[NUM_DAIOTYP] = {
@@ -106,7 +106,7 @@ static int daio_device_index(enum DAIOTYP type, struct hw *hw)
switch (type) {
case SPDIFOO: return 0;
case SPDIFIO: return 0;
- case SPDIFI1: return 1;
+ case SPDIFI_BAY: return 1;
case LINEO1: return 4;
case LINEO2: return 7;
case LINEO3: return 5;
@@ -120,7 +120,7 @@ static int daio_device_index(enum DAIOTYP type, struct hw *hw)
switch (type) {
case SPDIFOO: return 0;
case SPDIFIO: return 0;
- case SPDIFI1: return 1;
+ case SPDIFI_BAY: return 1;
case LINEO1: return 4;
case LINEO2: return 7;
case LINEO3: return 5;
diff --git a/sound/pci/ctxfi/ctdaio.h b/sound/pci/ctxfi/ctdaio.h
index ff77d55539a5..c9f6207fe92f 100644
--- a/sound/pci/ctxfi/ctdaio.h
+++ b/sound/pci/ctxfi/ctdaio.h
@@ -32,7 +32,7 @@ enum DAIOTYP {
SPDIFIO, /* S/PDIF In (Flexijack/Optical) on the card */
MIC, /* Dedicated mic on Titanium HD */
RCA, /* Dedicated RCA on SE-300PCIE */
- SPDIFI1, /* S/PDIF In on internal Drive Bay */
+ SPDIFI_BAY, /* S/PDIF In on internal drive bay */
NUM_DAIOTYP
};
--
2.53.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH v2 2/3] ALSA: ctxfi: Use correct DAIO type for da_desc
2026-04-01 9:01 [PATCH v2 0/3] ALSA: ctxfi: Clean up DAIO resource allocation Harin Lee
2026-04-01 9:01 ` [PATCH v2 1/3] ALSA: ctxfi: Rename SPDIFI1 to SPDIFI_BAY Harin Lee
@ 2026-04-01 9:01 ` Harin Lee
2026-04-01 9:01 ` [PATCH v2 3/3] ALSA: ctxfi: Precompute SRC allocation loop bound Harin Lee
2026-04-01 12:44 ` [PATCH v2 0/3] ALSA: ctxfi: Clean up DAIO resource allocation Takashi Iwai
3 siblings, 0 replies; 5+ messages in thread
From: Harin Lee @ 2026-04-01 9:01 UTC (permalink / raw)
To: Jaroslav Kysela, Takashi Iwai; +Cc: linux-sound, linux-kernel, Harin Lee
Skip the unused DAIO type per model (SPDIFIO on CTSB073X, SPDIFI_BAY
on all others) and use the correct DAIO type directly as da_desc
type. This removes the mismatch and misleading between the actual
DAIO resource and the da_desc type like SPDIFI_BAY (formerly SPDIFI1).
Update related functions accordingly, and drop the unreachable
SPDIFI_BAY case from the hw20k2 daio_device_index().
Signed-off-by: Harin Lee <me@harin.net>
---
sound/pci/ctxfi/ctatc.c | 21 ++++++++++++---------
sound/pci/ctxfi/ctdaio.c | 1 -
2 files changed, 12 insertions(+), 10 deletions(-)
diff --git a/sound/pci/ctxfi/ctatc.c b/sound/pci/ctxfi/ctatc.c
index 9e0532fb33ff..7c2f896d531d 100644
--- a/sound/pci/ctxfi/ctatc.c
+++ b/sound/pci/ctxfi/ctatc.c
@@ -983,6 +983,11 @@ static int atc_select_mic_in(struct ct_atc *atc)
return 0;
}
+static inline enum DAIOTYP atc_spdif_in_type(struct ct_atc *atc)
+{
+ return (atc->model == CTSB073X) ? SPDIFI_BAY : SPDIFIO;
+}
+
static struct capabilities atc_capabilities(struct ct_atc *atc)
{
struct hw *hw = atc->hw;
@@ -1121,7 +1126,7 @@ static int atc_spdif_out_unmute(struct ct_atc *atc, unsigned char state)
static int atc_spdif_in_unmute(struct ct_atc *atc, unsigned char state)
{
- return atc_daio_unmute(atc, state, SPDIFIO);
+ return atc_daio_unmute(atc, state, atc_spdif_in_type(atc));
}
static int atc_spdif_out_get_status(struct ct_atc *atc, unsigned int *status)
@@ -1427,14 +1432,12 @@ static int atc_get_resources(struct ct_atc *atc)
daio_mgr = (struct daio_mgr *)atc->rsc_mgrs[DAIO];
da_desc.msr = atc->msr;
for (i = 0; i < NUM_DAIOTYP; i++) {
- if (((i == MIC) && !cap.dedicated_mic) ||
- ((i == RCA) && !cap.dedicated_rca) ||
- i == SPDIFI_BAY)
+ if (((i == SPDIFIO) && (atc->model == CTSB073X)) ||
+ ((i == SPDIFI_BAY) && (atc->model != CTSB073X)) ||
+ ((i == MIC) && !cap.dedicated_mic) ||
+ ((i == RCA) && !cap.dedicated_rca))
continue;
- if (atc->model == CTSB073X && i == SPDIFIO)
- da_desc.type = SPDIFI_BAY;
- else
- da_desc.type = i;
+ da_desc.type = i;
da_desc.output = (i < LINEIM) || (i == RCA);
err = daio_mgr->get_daio(daio_mgr, &da_desc,
(struct daio **)&atc->daios[i]);
@@ -1569,7 +1572,7 @@ static void atc_connect_resources(struct ct_atc *atc)
mixer->set_input_right(mixer, MIX_MIC_IN, &src->rsc);
}
- dai = container_of(atc->daios[SPDIFIO], struct dai, daio);
+ dai = container_of(atc->daios[atc_spdif_in_type(atc)], struct dai, daio);
atc_connect_dai(atc->rsc_mgrs[SRC], dai,
(struct src **)&atc->srcs[0],
(struct srcimp **)&atc->srcimps[0]);
diff --git a/sound/pci/ctxfi/ctdaio.c b/sound/pci/ctxfi/ctdaio.c
index 128cf2f69ac1..69aacd06716c 100644
--- a/sound/pci/ctxfi/ctdaio.c
+++ b/sound/pci/ctxfi/ctdaio.c
@@ -120,7 +120,6 @@ static int daio_device_index(enum DAIOTYP type, struct hw *hw)
switch (type) {
case SPDIFOO: return 0;
case SPDIFIO: return 0;
- case SPDIFI_BAY: return 1;
case LINEO1: return 4;
case LINEO2: return 7;
case LINEO3: return 5;
--
2.53.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH v2 3/3] ALSA: ctxfi: Precompute SRC allocation loop bound
2026-04-01 9:01 [PATCH v2 0/3] ALSA: ctxfi: Clean up DAIO resource allocation Harin Lee
2026-04-01 9:01 ` [PATCH v2 1/3] ALSA: ctxfi: Rename SPDIFI1 to SPDIFI_BAY Harin Lee
2026-04-01 9:01 ` [PATCH v2 2/3] ALSA: ctxfi: Use correct DAIO type for da_desc Harin Lee
@ 2026-04-01 9:01 ` Harin Lee
2026-04-01 12:44 ` [PATCH v2 0/3] ALSA: ctxfi: Clean up DAIO resource allocation Takashi Iwai
3 siblings, 0 replies; 5+ messages in thread
From: Harin Lee @ 2026-04-01 9:01 UTC (permalink / raw)
To: Jaroslav Kysela, Takashi Iwai; +Cc: linux-sound, linux-kernel, Harin Lee
Replace the capability checks in the SRC and SRCIMP allocation loops
with a precomputed loop bound. Cards with a dedicated mic input
(SB1270, OK0010) allocate all NUM_ATC_SRCS entries, otherwise stop
at 4.
Signed-off-by: Harin Lee <me@harin.net>
---
sound/pci/ctxfi/ctatc.c | 10 ++++------
1 file changed, 4 insertions(+), 6 deletions(-)
diff --git a/sound/pci/ctxfi/ctatc.c b/sound/pci/ctxfi/ctatc.c
index 7c2f896d531d..516c0a12ed9f 100644
--- a/sound/pci/ctxfi/ctatc.c
+++ b/sound/pci/ctxfi/ctatc.c
@@ -1409,9 +1409,11 @@ static int atc_get_resources(struct ct_atc *atc)
struct sum_desc sum_dsc = {0};
struct sum_mgr *sum_mgr;
struct capabilities cap;
+ int atc_srcs_limit;
int err, i;
cap = atc->capabilities(atc);
+ atc_srcs_limit = cap.dedicated_mic ? NUM_ATC_SRCS : 4;
atc->daios = kcalloc(NUM_DAIOTYP, sizeof(void *), GFP_KERNEL);
if (!atc->daios)
@@ -1453,9 +1455,7 @@ static int atc_get_resources(struct ct_atc *atc)
src_dsc.multi = 1;
src_dsc.msr = atc->msr;
src_dsc.mode = ARCRW;
- for (i = 0; i < NUM_ATC_SRCS; i++) {
- if (((i > 3) && !cap.dedicated_mic))
- continue;
+ for (i = 0; i < atc_srcs_limit; i++) {
err = src_mgr->get_src(src_mgr, &src_dsc,
(struct src **)&atc->srcs[i]);
if (err)
@@ -1464,9 +1464,7 @@ static int atc_get_resources(struct ct_atc *atc)
srcimp_mgr = atc->rsc_mgrs[SRCIMP];
srcimp_dsc.msr = 8;
- for (i = 0; i < NUM_ATC_SRCS; i++) {
- if (((i > 3) && !cap.dedicated_mic))
- continue;
+ for (i = 0; i < atc_srcs_limit; i++) {
err = srcimp_mgr->get_srcimp(srcimp_mgr, &srcimp_dsc,
(struct srcimp **)&atc->srcimps[i]);
if (err)
--
2.53.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH v2 0/3] ALSA: ctxfi: Clean up DAIO resource allocation
2026-04-01 9:01 [PATCH v2 0/3] ALSA: ctxfi: Clean up DAIO resource allocation Harin Lee
` (2 preceding siblings ...)
2026-04-01 9:01 ` [PATCH v2 3/3] ALSA: ctxfi: Precompute SRC allocation loop bound Harin Lee
@ 2026-04-01 12:44 ` Takashi Iwai
3 siblings, 0 replies; 5+ messages in thread
From: Takashi Iwai @ 2026-04-01 12:44 UTC (permalink / raw)
To: Harin Lee; +Cc: Jaroslav Kysela, Takashi Iwai, linux-sound, linux-kernel
On Wed, 01 Apr 2026 11:01:56 +0200,
Harin Lee wrote:
>
> Clean up the resource allocation in atc_get_resources() and related
> functions, on top of the recent SPDIFI1 fixes.
>
> The earlier refactoring introduced a kernel crash on hw20k2, where
> daio_device_index() returned -EINVAL for the SPDIFI1 type and the
> value was used as an unsigned array offset. On my development system
> (64G memory), this did not manifest as a crash, making the bug
> difficult to catch during testing.
>
> Tested on the real hw20k2 hardware with mem=8G to verify the original
> crash and confirm these patches.
>
> Changes in v2:
> - Add atc_spdif_in_type() helper to avoid ternary operators in
> multiple places
> - Rewrite the SPDIFI type skip condition as explicit model checks
>
> Harin Lee (3):
> ALSA: ctxfi: Rename SPDIFI1 to SPDIFI_BAY
> ALSA: ctxfi: Use correct DAIO type for da_desc
> ALSA: ctxfi: Precompute SRC allocation loop bound
Applied to for-next branch now. Thanks.
Takashi
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2026-04-01 12:44 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-04-01 9:01 [PATCH v2 0/3] ALSA: ctxfi: Clean up DAIO resource allocation Harin Lee
2026-04-01 9:01 ` [PATCH v2 1/3] ALSA: ctxfi: Rename SPDIFI1 to SPDIFI_BAY Harin Lee
2026-04-01 9:01 ` [PATCH v2 2/3] ALSA: ctxfi: Use correct DAIO type for da_desc Harin Lee
2026-04-01 9:01 ` [PATCH v2 3/3] ALSA: ctxfi: Precompute SRC allocation loop bound Harin Lee
2026-04-01 12:44 ` [PATCH v2 0/3] ALSA: ctxfi: Clean up DAIO resource allocation Takashi Iwai
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox