Skip to content

Commit 0ad5470

Browse files
rfvirgilgregkh
authored andcommitted
ALSA: hda: cs35l56: Fix uninitialized value in cs35l56_hda_read_acpi()
[ Upstream commit 90df495 ] 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> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent dd110cc commit 0ad5470

2 files changed

Lines changed: 8 additions & 5 deletions

File tree

sound/pci/hda/cs35l56_hda.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -888,6 +888,7 @@ static int cs35l56_hda_system_resume(struct device *dev)
888888
static int cs35l56_hda_fixup_yoga9(struct cs35l56_hda *cs35l56, int *bus_addr)
889889
{
890890
/* The cirrus,dev-index property has the wrong values */
891+
cs35l56->num_amps = 2;
891892
switch (*bus_addr) {
892893
case 0x30:
893894
cs35l56->index = 1;
@@ -937,7 +938,6 @@ static int cs35l56_hda_read_acpi(struct cs35l56_hda *cs35l56, int hid, int id)
937938
char hid_string[8];
938939
struct acpi_device *adev;
939940
const char *property, *sub;
940-
size_t nval;
941941
int i, ret;
942942

943943
/*
@@ -973,13 +973,14 @@ static int cs35l56_hda_read_acpi(struct cs35l56_hda *cs35l56, int hid, int id)
973973
ret = -EINVAL;
974974
goto err;
975975
}
976-
nval = ret;
976+
cs35l56->num_amps = ret;
977977

978-
ret = device_property_read_u32_array(cs35l56->base.dev, property, values, nval);
978+
ret = device_property_read_u32_array(cs35l56->base.dev, property, values,
979+
cs35l56->num_amps);
979980
if (ret)
980981
goto err;
981982

982-
for (i = 0; i < nval; i++) {
983+
for (i = 0; i < cs35l56->num_amps; i++) {
983984
if (values[i] == id) {
984985
cs35l56->index = i;
985986
break;
@@ -1002,7 +1003,8 @@ static int cs35l56_hda_read_acpi(struct cs35l56_hda *cs35l56, int hid, int id)
10021003
"Read ACPI _SUB failed(%ld): fallback to generic firmware\n",
10031004
PTR_ERR(sub));
10041005
} else {
1005-
ret = cirrus_scodec_get_speaker_id(cs35l56->base.dev, cs35l56->index, nval, -1);
1006+
ret = cirrus_scodec_get_speaker_id(cs35l56->base.dev, cs35l56->index,
1007+
cs35l56->num_amps, -1);
10061008
if (ret == -ENOENT) {
10071009
cs35l56->system_name = sub;
10081010
} else if (ret >= 0) {

sound/pci/hda/cs35l56_hda.h

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

2727
int index;
28+
int num_amps;
2829
const char *system_name;
2930
const char *amp_name;
3031

0 commit comments

Comments
 (0)