Skip to contentSkip to conversation

ALSA: hda: Fix [codec] ID matching in patch files for IDs with bit 31 set

PATCH In review Andrew Davison 2 participants 2 messages Nov 6 – Nov 7

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ALSA: hda: Fix [codec] ID matching in patch files for IDs with bit 31 set

parse_codec_mode() reads the vendor and subsystem IDs of a patch file's [codec] line into an int, and skips the check when the value is zero or negative, as documented. An ID with bit 31 set, such as SigmaTel's 0x8384xxxx or Intel's 0x8086xxxx, comes out negative, so it is taken as a wildcard and the section is applied to every codec instead of the one it names.

This was seen on an OpenPeak OpenFrame 2 with an IDT 92HD75B2X5 (0x111d7608). A patch file written for the STAC9202 (0x83847632) in the related OpenFrame 1 was applied to it, swapping the headphone and speaker pin configurations, so auto-mute never muted the speaker.

Read the IDs as long long, so real IDs are compared exactly. Values written as negative numbers (e.g. -1) still act as wildcards, as documented; a hex value such as 0xffffffff is now compared as written.

Tested on 6.18.60 on an OpenFrame 2, with a rebuilt snd-hda-codec and the STAC9202 patch file: user_pin_configs stays empty for the IDT codec, and the headphone and line-out pins are assigned as the BIOS sets them. Not tested on a STAC9202 itself.

The bug was tracked down and this fix written with an AI coding assistant (Claude Code, Claude Opus 5.5), which also ran the tests above. I have reviewed the change and the tests.

Fixes ef940b0403d4 ("ALSA: hda - Allow patching with any vendor/subsystem ids")
---
 sound/hda/common/sysfs.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
sound/hda/common/sysfs.c +3 -2
index bf65223fde10d..b354cbbc3dc91 100644
@@ -512,11 +512,12 @@ static inline int strmatch(const char *a, const char *b)
 static void parse_codec_mode(char *buf, struct hda_bus *bus,
 			     struct hda_codec **codecp)
 {
-	int vendorid, subid, caddr;
+	long long vendorid, subid;
+	int caddr;
 	struct hda_codec *codec;
 
 	*codecp = NULL;
-	if (sscanf(buf, "%i %i %i", &vendorid, &subid, &caddr) == 3) {
+	if (sscanf(buf, "%lli %lli %i", &vendorid, &subid, &caddr) == 3) {
 		list_for_each_codec(codec, bus) {
 			if ((vendorid <= 0 || codec->core.vendor_id == vendorid) &&
 			    (subid <= 0 || codec->core.subsystem_id == subid) &&

base-commit: e0f6c0c60adc73582b40803a5c172077c5a4e84f

Signature · 1 line
2.39.5 (Apple Git-154)
#1 lore raw
Quoted 22 lines · Andrew Davison

parse_codec_mode() reads the vendor and subsystem IDs of a patch file's [codec] line into an int, and skips the check when the value is zero or negative, as documented. An ID with bit 31 set, such as SigmaTel's 0x8384xxxx or Intel's 0x8086xxxx, comes out negative, so it is taken as a wildcard and the section is applied to every codec instead of the one it names.

This was seen on an OpenPeak OpenFrame 2 with an IDT 92HD75B2X5 (0x111d7608). A patch file written for the STAC9202 (0x83847632) in the related OpenFrame 1 was applied to it, swapping the headphone and speaker pin configurations, so auto-mute never muted the speaker.

Read the IDs as long long, so real IDs are compared exactly. Values written as negative numbers (e.g. -1) still act as wildcards, as documented; a hex value such as 0xffffffff is now compared as written.

Tested on 6.18.60 on an OpenFrame 2, with a rebuilt snd-hda-codec and the STAC9202 patch file: user_pin_configs stays empty for the IDT codec, and the headphone and line-out pins are assigned as the BIOS sets them. Not tested on a STAC9202 itself.

Quoted 7 lines

The bug was tracked down and this fix written with an AI coding assistant (Claude Code, Claude Opus 5.5), which also ran the tests above. I have reviewed the change and the tests.

Fixes ef940b0403d4 ("ALSA: hda - Allow patching with any vendor/subsystem ids")

Applied now. Thanks.

Takashi