Skip to content

Commit 90df495

Browse files
rfvirgiltiwai
authored andcommitted
ALSA: hda: cs35l56: Fix uninitialized value in cs35l56_hda_read_acpi()
Eliminate the uninitialized 'nval' in cs35l56_hda_read_acpi() if a system-specific quirk overrides processing of the dev-index property. The value is now stored in a new 'num_amps' member of struct cs35l56_hda so that the quirk handler can set the value. The quirk for the Lenovo Yoga Book 9i GenX replaces the values from the dev-index property with hardcoded indexes. So cs35l56_hda_read_acpi() would then skip reading the property. But this left the 'nval' local variable uninitialized when it is later passed to cirrus_scodec_get_speaker_id(). Fixes: 40b1c2f ("ALSA: hda/cs35l56: Workaround bad dev-index on Lenovo Yoga Book 9i GenX") Reported-by: Dan Carpenter <error27@gmail.com> Closes: https://lore.kernel.org/linux-sound/aenFesLAStjrVNy8@stanley.mountain/T/#u Signed-off-by: Richard Fitzgerald <rf@opensource.cirrus.com> Link: https://patch.msgid.link/20260428130531.169600-1-rf@opensource.cirrus.com Signed-off-by: Takashi Iwai <tiwai@suse.de>
1 parent b0e2333 commit 90df495

2 files changed

Lines changed: 8 additions & 5 deletions

File tree

sound/hda/codecs/side-codecs/cs35l56_hda.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -976,6 +976,7 @@ static int cs35l56_hda_system_resume(struct device *dev)
976976
static int cs35l56_hda_fixup_yoga9(struct cs35l56_hda *cs35l56, int *bus_addr)
977977
{
978978
/* The cirrus,dev-index property has the wrong values */
979+
cs35l56->num_amps = 2;
979980
switch (*bus_addr) {
980981
case 0x30:
981982
cs35l56->index = 1;
@@ -1025,7 +1026,6 @@ static int cs35l56_hda_read_acpi(struct cs35l56_hda *cs35l56, int hid, int id)
10251026
char hid_string[8];
10261027
struct acpi_device *adev;
10271028
const char *property, *sub;
1028-
size_t nval;
10291029
int i, ret;
10301030

10311031
/*
@@ -1061,13 +1061,14 @@ static int cs35l56_hda_read_acpi(struct cs35l56_hda *cs35l56, int hid, int id)
10611061
ret = -EINVAL;
10621062
goto err;
10631063
}
1064-
nval = ret;
1064+
cs35l56->num_amps = ret;
10651065

1066-
ret = device_property_read_u32_array(cs35l56->base.dev, property, values, nval);
1066+
ret = device_property_read_u32_array(cs35l56->base.dev, property, values,
1067+
cs35l56->num_amps);
10671068
if (ret)
10681069
goto err;
10691070

1070-
for (i = 0; i < nval; i++) {
1071+
for (i = 0; i < cs35l56->num_amps; i++) {
10711072
if (values[i] == id) {
10721073
cs35l56->index = i;
10731074
break;
@@ -1090,7 +1091,8 @@ static int cs35l56_hda_read_acpi(struct cs35l56_hda *cs35l56, int hid, int id)
10901091
"Read ACPI _SUB failed(%ld): fallback to generic firmware\n",
10911092
PTR_ERR(sub));
10921093
} else {
1093-
ret = cirrus_scodec_get_speaker_id(cs35l56->base.dev, cs35l56->index, nval, -1);
1094+
ret = cirrus_scodec_get_speaker_id(cs35l56->base.dev, cs35l56->index,
1095+
cs35l56->num_amps, -1);
10941096
if (ret == -ENOENT) {
10951097
cs35l56->system_name = sub;
10961098
} else if (ret >= 0) {

sound/hda/codecs/side-codecs/cs35l56_hda.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ struct cs35l56_hda {
2626
struct work_struct dsp_work;
2727

2828
int index;
29+
int num_amps;
2930
const char *system_name;
3031
const char *amp_name;
3132

0 commit comments

Comments
 (0)