Skip to contentSkip to conversation

ALSA: emu10k1: properly assert DSP init constraints

PATCH In review Oswald Buddenhagen 2 participants 4 messages Apr 21, 2023 Sound

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ALSA: emu10k1: properly assert DSP init constraints

If these are hit, we've already trashed kernel space. There is no recovery from that.

---
 sound/pci/emu10k1/emufx.c | 21 +++++----------------
 1 file changed, 5 insertions(+), 16 deletions(-)
sound/pci/emu10k1/emufx.c +5 -16
index 6cf7c8b1de47..f6f05219f7fc 100644
@@ -1773,22 +1773,19 @@ A_OP(icode, &ptr, iMAC0, A_GPR(var), A_GPR(var), A_GPR(vol), A_EXTIN(input))
 	 * ok, set up done..
 	 */
 
-	if (gpr > tmp) {
-		snd_BUG();
-		err = -EIO;
-		goto __err;
-	}
+	BUG_ON(gpr > tmp);
+	BUG_ON(nctl > SND_EMU10K1_GPR_CONTROLS);
+
 	/* clear remaining instruction memory */
 	while (ptr < 0x400)
 		A_OP(icode, &ptr, 0x0f, 0xc0, 0xc0, 0xcf, 0xc0);
 
 	icode->gpr_add_control_count = nctl;
 	icode->gpr_add_controls = controls;
 	emu->support_tlv = 1; /* support TLV */
 	err = snd_emu10k1_icode_poke(emu, icode, true);
 	emu->support_tlv = 0; /* clear again */
 
-__err:
 	kfree(controls);
 __err_ctrls:
 	kfree(icode->gpr_map);
@@ -2391,16 +2388,8 @@ static int _snd_emu10k1_init_efx(struct snd_emu10k1 *emu)
 	}
 	    
 
-	if (gpr > tmp) {
-		snd_BUG();
-		err = -EIO;
-		goto __err;
-	}
-	if (i > SND_EMU10K1_GPR_CONTROLS) {
-		snd_BUG();
-		err = -EIO;
-		goto __err;
-	}
+	BUG_ON(gpr > tmp);
+	BUG_ON(i > SND_EMU10K1_GPR_CONTROLS);
 	
 	/* clear remaining instruction memory */
 	while (ptr < 0x200)
Signature · 1 line
2.40.0.152.g15d061e6df
#1 lore raw
Quoted 5 lines · Oswald Buddenhagen

If these are hit, we've already trashed kernel space. There is no recovery from that.

Sorry, it's a big NO-NO. BUG_ON() shouldn't be used here at all.

BUG_ON() is used for the case you inevitably must stop everything immediately at this point.

thanks,

Takashi

#2 lore raw
Quoted 6 lines · Takashi Iwai
Quoted 4 lines · Oswald Buddenhagen

If these are hit, we've already trashed kernel space. There is no recovery from that.

Quoted 7 lines
Quoted 1 line

Sorry, it's a big NO-NO. BUG_ON() shouldn't be used here at all.

BUG_ON() is used for the case you inevitably must stop everything immediately at this point.

yes, this is exactly what is intended, and i hoped that the commit message makes it clear enough why.

regards

#3 lore raw
Quoted 10 lines · Oswald Buddenhagen
Quoted 8 lines · Takashi Iwai
Quoted 5 lines · Oswald Buddenhagen

If these are hit, we've already trashed kernel space. There is no recovery from that.

Quoted 7 lines
Quoted 5 lines

Sorry, it's a big NO-NO. BUG_ON() shouldn't be used here at all.

BUG_ON() is used for the case you inevitably must stop everything immediately at this point.

yes, this is exactly what is intended, and i hoped that the commit message makes it clear enough why.

Not clear at all. Please explain in more details if we really *HAVE TO* use BUG_ON() there.

thanks,

Takashi