Skip to content

Commit 277c696

Browse files
committed
ALSA: ctxfi: Check the error for index mapping
The ctxfi driver blindly assumed a proper value returned from daio_device_index(), but it's not always true. Add a proper error check to deal with the error from the function. Cc: <stable@vger.kernel.org> Link: https://lore.kernel.org/87cy149n6k.wl-tiwai@suse.de Link: https://patch.msgid.link/20260329091240.420194-2-tiwai@suse.de Signed-off-by: Takashi Iwai <tiwai@suse.de>
1 parent b045ab3 commit 277c696

1 file changed

Lines changed: 52 additions & 33 deletions

File tree

sound/pci/ctxfi/ctdaio.c

Lines changed: 52 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ static const struct rsc_ops daio_in_rsc_ops_20k2 = {
9999
.output_slot = daio_index,
100100
};
101101

102-
static unsigned int daio_device_index(enum DAIOTYP type, struct hw *hw)
102+
static int daio_device_index(enum DAIOTYP type, struct hw *hw)
103103
{
104104
switch (hw->chip_type) {
105105
case ATC20K1:
@@ -112,7 +112,9 @@ static unsigned int daio_device_index(enum DAIOTYP type, struct hw *hw)
112112
case LINEO3: return 5;
113113
case LINEO4: return 6;
114114
case LINEIM: return 7;
115-
default: return -EINVAL;
115+
default:
116+
pr_err("ctxfi: Invalid type %d for hw20k1\n", type);
117+
return -EINVAL;
116118
}
117119
case ATC20K2:
118120
switch (type) {
@@ -126,9 +128,12 @@ static unsigned int daio_device_index(enum DAIOTYP type, struct hw *hw)
126128
case LINEIM: return 4;
127129
case MIC: return 5;
128130
case RCA: return 3;
129-
default: return -EINVAL;
131+
default:
132+
pr_err("ctxfi: Invalid type %d for hw20k2\n", type);
133+
return -EINVAL;
130134
}
131135
default:
136+
pr_err("ctxfi: Invalid chip type %d\n", hw->chip_type);
132137
return -EINVAL;
133138
}
134139
}
@@ -149,8 +154,11 @@ static int dao_spdif_set_spos(struct dao *dao, unsigned int spos)
149154

150155
static int dao_commit_write(struct dao *dao)
151156
{
152-
dao->hw->dao_commit_write(dao->hw,
153-
daio_device_index(dao->daio.type, dao->hw), dao->ctrl_blk);
157+
int idx = daio_device_index(dao->daio.type, dao->hw);
158+
159+
if (idx < 0)
160+
return idx;
161+
dao->hw->dao_commit_write(dao->hw, idx, dao->ctrl_blk);
154162
return 0;
155163
}
156164

@@ -288,8 +296,11 @@ static int dai_set_enb_srt(struct dai *dai, unsigned int enb)
288296

289297
static int dai_commit_write(struct dai *dai)
290298
{
291-
dai->hw->dai_commit_write(dai->hw,
292-
daio_device_index(dai->daio.type, dai->hw), dai->ctrl_blk);
299+
int idx = daio_device_index(dai->daio.type, dai->hw);
300+
301+
if (idx < 0)
302+
return idx;
303+
dai->hw->dai_commit_write(dai->hw, idx, dai->ctrl_blk);
293304
return 0;
294305
}
295306

@@ -368,7 +379,7 @@ static int dao_rsc_init(struct dao *dao,
368379
{
369380
struct hw *hw = mgr->mgr.hw;
370381
unsigned int conf;
371-
int err;
382+
int idx, err;
372383

373384
err = daio_rsc_init(&dao->daio, desc, mgr->mgr.hw);
374385
if (err)
@@ -387,15 +398,18 @@ static int dao_rsc_init(struct dao *dao,
387398
if (err)
388399
goto error2;
389400

390-
hw->daio_mgr_dsb_dao(mgr->mgr.ctrl_blk,
391-
daio_device_index(dao->daio.type, hw));
401+
idx = daio_device_index(dao->daio.type, hw);
402+
if (idx < 0) {
403+
err = idx;
404+
goto error2;
405+
}
406+
407+
hw->daio_mgr_dsb_dao(mgr->mgr.ctrl_blk, idx);
392408
hw->daio_mgr_commit_write(hw, mgr->mgr.ctrl_blk);
393409

394410
conf = (desc->msr & 0x7) | (desc->passthru << 3);
395-
hw->daio_mgr_dao_init(hw, mgr->mgr.ctrl_blk,
396-
daio_device_index(dao->daio.type, hw), conf);
397-
hw->daio_mgr_enb_dao(mgr->mgr.ctrl_blk,
398-
daio_device_index(dao->daio.type, hw));
411+
hw->daio_mgr_dao_init(hw, mgr->mgr.ctrl_blk, idx, conf);
412+
hw->daio_mgr_enb_dao(mgr->mgr.ctrl_blk, idx);
399413
hw->daio_mgr_commit_write(hw, mgr->mgr.ctrl_blk);
400414

401415
return 0;
@@ -444,7 +458,7 @@ static int dai_rsc_init(struct dai *dai,
444458
const struct daio_desc *desc,
445459
struct daio_mgr *mgr)
446460
{
447-
int err;
461+
int idx, err;
448462
struct hw *hw = mgr->mgr.hw;
449463
unsigned int rsr, msr;
450464

@@ -458,6 +472,12 @@ static int dai_rsc_init(struct dai *dai,
458472
if (err)
459473
goto error1;
460474

475+
idx = daio_device_index(dai->daio.type, dai->hw);
476+
if (idx < 0) {
477+
err = idx;
478+
goto error1;
479+
}
480+
461481
for (rsr = 0, msr = desc->msr; msr > 1; msr >>= 1)
462482
rsr++;
463483

@@ -466,8 +486,7 @@ static int dai_rsc_init(struct dai *dai,
466486
/* default to disabling control of a SRC */
467487
hw->dai_srt_set_ec(dai->ctrl_blk, 0);
468488
hw->dai_srt_set_et(dai->ctrl_blk, 0); /* default to disabling SRT */
469-
hw->dai_commit_write(hw,
470-
daio_device_index(dai->daio.type, dai->hw), dai->ctrl_blk);
489+
hw->dai_commit_write(hw, idx, dai->ctrl_blk);
471490

472491
return 0;
473492

@@ -582,28 +601,28 @@ static int put_daio_rsc(struct daio_mgr *mgr, struct daio *daio)
582601
static int daio_mgr_enb_daio(struct daio_mgr *mgr, struct daio *daio)
583602
{
584603
struct hw *hw = mgr->mgr.hw;
585-
586-
if (daio->output) {
587-
hw->daio_mgr_enb_dao(mgr->mgr.ctrl_blk,
588-
daio_device_index(daio->type, hw));
589-
} else {
590-
hw->daio_mgr_enb_dai(mgr->mgr.ctrl_blk,
591-
daio_device_index(daio->type, hw));
592-
}
604+
int idx = daio_device_index(daio->type, hw);
605+
606+
if (idx < 0)
607+
return idx;
608+
if (daio->output)
609+
hw->daio_mgr_enb_dao(mgr->mgr.ctrl_blk, idx);
610+
else
611+
hw->daio_mgr_enb_dai(mgr->mgr.ctrl_blk, idx);
593612
return 0;
594613
}
595614

596615
static int daio_mgr_dsb_daio(struct daio_mgr *mgr, struct daio *daio)
597616
{
598617
struct hw *hw = mgr->mgr.hw;
599-
600-
if (daio->output) {
601-
hw->daio_mgr_dsb_dao(mgr->mgr.ctrl_blk,
602-
daio_device_index(daio->type, hw));
603-
} else {
604-
hw->daio_mgr_dsb_dai(mgr->mgr.ctrl_blk,
605-
daio_device_index(daio->type, hw));
606-
}
618+
int idx = daio_device_index(daio->type, hw);
619+
620+
if (idx < 0)
621+
return idx;
622+
if (daio->output)
623+
hw->daio_mgr_dsb_dao(mgr->mgr.ctrl_blk, idx);
624+
else
625+
hw->daio_mgr_dsb_dai(mgr->mgr.ctrl_blk, idx);
607626
return 0;
608627
}
609628

0 commit comments

Comments
 (0)