ALSA: ctxfi: Clean up DAIO resource allocation
v2 cover ALSA: ctxfi: Clean up DAIO resource allocation
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(-)
Signature · 1 line
2.53.0
PATCH v2 1/3 ALSA: ctxfi: Rename SPDIFI1 to SPDIFI_BAY
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).
--- 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(-)
sound/pci/ctxfi/ctatc.c +2 -2
@@ -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 );
sound/pci/ctxfi/ctdaio.c +3 -3
@@ -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 ;
sound/pci/ctxfi/ctdaio.h +1 -1
@@ -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 };
Signature · 1 line
2.53.0
PATCH v2 2/3 ALSA: ctxfi: Use correct DAIO type for da_desc
In reply to Harin LeeSkip 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().
--- sound/pci/ctxfi/ctatc.c | 21 ++++++++++++--------- sound/pci/ctxfi/ctdaio.c | 1 - 2 files changed, 12 insertions(+), 10 deletions(-)
sound/pci/ctxfi/ctatc.c +12 -9
@@ -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 ]);
sound/pci/ctxfi/ctdaio.c +0 -1
@@ -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 ;
Signature · 1 line
2.53.0
PATCH v2 3/3 ALSA: ctxfi: Precompute SRC allocation loop bound
In reply to Harin LeeReplace 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.
--- sound/pci/ctxfi/ctatc.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-)
sound/pci/ctxfi/ctatc.c +4 -6
@@ -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)
Signature · 1 line
2.53.0
Takashi Iwai
AppliedQuoted 18 lines · 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-EINVALfor 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:
- Addatc_spdif_in_type()helper to avoid ternary operators in multiple places
- Rewrite the SPDIFI type skip condition as explicit model checks
Quoted 4 lines
Harin Lee (3):
ALSA: ctxfi: Rename SPDIFI1 toSPDIFI_BAY
ALSA: ctxfi: Use correct DAIO type forda_desc
ALSA: ctxfi: Precompute SRC allocation loop bound
Applied to for-next branch now. Thanks.
Takashi