Skip to content

Commit 843e94c

Browse files
committed
ASoC: Intel: Fix invalid quirk input mapping
Merge series from Takashi Iwai <tiwai@suse.de>: This is a revised patch set for potential OOB accesses when wild values are passed to quirk option for ASoC Intel drivers. Unlike the v1 previous patchset, invalid quirk values are checked and corrected at log_quirks() in each driver, instead. v1: https://lore.kernel.org/20250415083144.6588-1-tiwai@suse.de Takashi === Takashi Iwai (3): ASoC: Intel: bytcht_es8316: Fix invalid quirk input mapping ASoC: Intel: bytcr_rt5640: Fix invalid quirk input mapping ASoC: Intel: bytcr_rt5651: Fix invalid quirk input mapping sound/soc/intel/boards/bytcht_es8316.c | 20 +++++++++++++++++--- sound/soc/intel/boards/bytcr_rt5640.c | 7 +++++-- sound/soc/intel/boards/bytcr_rt5651.c | 26 +++++++++++++++++++++----- 3 files changed, 43 insertions(+), 10 deletions(-) -- 2.50.1
2 parents 1cf8786 + 4336efb commit 843e94c

3 files changed

Lines changed: 43 additions & 10 deletions

File tree

sound/soc/intel/boards/bytcht_es8316.c

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ enum {
4747
BYT_CHT_ES8316_INTMIC_IN2_MAP,
4848
};
4949

50-
#define BYT_CHT_ES8316_MAP(quirk) ((quirk) & GENMASK(3, 0))
50+
#define BYT_CHT_ES8316_MAP_MASK GENMASK(3, 0)
51+
#define BYT_CHT_ES8316_MAP(quirk) ((quirk) & BYT_CHT_ES8316_MAP_MASK)
5152
#define BYT_CHT_ES8316_SSP0 BIT(16)
5253
#define BYT_CHT_ES8316_MONO_SPEAKER BIT(17)
5354
#define BYT_CHT_ES8316_JD_INVERTED BIT(18)
@@ -60,10 +61,23 @@ MODULE_PARM_DESC(quirk, "Board-specific quirk override");
6061

6162
static void log_quirks(struct device *dev)
6263
{
63-
if (BYT_CHT_ES8316_MAP(quirk) == BYT_CHT_ES8316_INTMIC_IN1_MAP)
64+
int map;
65+
66+
map = BYT_CHT_ES8316_MAP(quirk);
67+
switch (map) {
68+
case BYT_CHT_ES8316_INTMIC_IN1_MAP:
6469
dev_info(dev, "quirk IN1_MAP enabled");
65-
if (BYT_CHT_ES8316_MAP(quirk) == BYT_CHT_ES8316_INTMIC_IN2_MAP)
70+
break;
71+
case BYT_CHT_ES8316_INTMIC_IN2_MAP:
6672
dev_info(dev, "quirk IN2_MAP enabled");
73+
break;
74+
default:
75+
dev_warn_once(dev, "quirk sets invalid input map: 0x%x, default to INTMIC_IN1_MAP\n", map);
76+
quirk &= ~BYT_CHT_ES8316_MAP_MASK;
77+
quirk |= BYT_CHT_ES8316_INTMIC_IN1_MAP;
78+
break;
79+
}
80+
6781
if (quirk & BYT_CHT_ES8316_SSP0)
6882
dev_info(dev, "quirk SSP0 enabled");
6983
if (quirk & BYT_CHT_ES8316_MONO_SPEAKER)

sound/soc/intel/boards/bytcr_rt5640.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,8 @@ enum {
6868
BYT_RT5640_OVCD_SF_1P5 = (RT5640_OVCD_SF_1P5 << 13),
6969
};
7070

71-
#define BYT_RT5640_MAP(quirk) ((quirk) & GENMASK(3, 0))
71+
#define BYT_RT5640_MAP_MASK GENMASK(3, 0)
72+
#define BYT_RT5640_MAP(quirk) ((quirk) & BYT_RT5640_MAP_MASK)
7273
#define BYT_RT5640_JDSRC(quirk) (((quirk) & GENMASK(7, 4)) >> 4)
7374
#define BYT_RT5640_OVCD_TH(quirk) (((quirk) & GENMASK(12, 8)) >> 8)
7475
#define BYT_RT5640_OVCD_SF(quirk) (((quirk) & GENMASK(14, 13)) >> 13)
@@ -140,7 +141,9 @@ static void log_quirks(struct device *dev)
140141
dev_info(dev, "quirk NO_INTERNAL_MIC_MAP enabled\n");
141142
break;
142143
default:
143-
dev_err(dev, "quirk map 0x%x is not supported, microphone input will not work\n", map);
144+
dev_warn_once(dev, "quirk sets invalid input map: 0x%x, default to DMIC1_MAP\n", map);
145+
byt_rt5640_quirk &= ~BYT_RT5640_MAP_MASK;
146+
byt_rt5640_quirk |= BYT_RT5640_DMIC1_MAP;
144147
break;
145148
}
146149
if (byt_rt5640_quirk & BYT_RT5640_HSMIC2_ON_IN1)

sound/soc/intel/boards/bytcr_rt5651.c

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@ enum {
5858
BYT_RT5651_OVCD_SF_1P5 = (RT5651_OVCD_SF_1P5 << 13),
5959
};
6060

61-
#define BYT_RT5651_MAP(quirk) ((quirk) & GENMASK(3, 0))
61+
#define BYT_RT5651_MAP_MASK GENMASK(3, 0)
62+
#define BYT_RT5651_MAP(quirk) ((quirk) & BYT_RT5651_MAP_MASK)
6263
#define BYT_RT5651_JDSRC(quirk) (((quirk) & GENMASK(7, 4)) >> 4)
6364
#define BYT_RT5651_OVCD_TH(quirk) (((quirk) & GENMASK(12, 8)) >> 8)
6465
#define BYT_RT5651_OVCD_SF(quirk) (((quirk) & GENMASK(14, 13)) >> 13)
@@ -100,14 +101,29 @@ MODULE_PARM_DESC(quirk, "Board-specific quirk override");
100101

101102
static void log_quirks(struct device *dev)
102103
{
103-
if (BYT_RT5651_MAP(byt_rt5651_quirk) == BYT_RT5651_DMIC_MAP)
104+
int map;
105+
106+
map = BYT_RT5651_MAP(byt_rt5651_quirk);
107+
switch (map) {
108+
case BYT_RT5651_DMIC_MAP:
104109
dev_info(dev, "quirk DMIC_MAP enabled");
105-
if (BYT_RT5651_MAP(byt_rt5651_quirk) == BYT_RT5651_IN1_MAP)
110+
break;
111+
case BYT_RT5651_IN1_MAP:
106112
dev_info(dev, "quirk IN1_MAP enabled");
107-
if (BYT_RT5651_MAP(byt_rt5651_quirk) == BYT_RT5651_IN2_MAP)
113+
break;
114+
case BYT_RT5651_IN2_MAP:
108115
dev_info(dev, "quirk IN2_MAP enabled");
109-
if (BYT_RT5651_MAP(byt_rt5651_quirk) == BYT_RT5651_IN1_IN2_MAP)
116+
break;
117+
case BYT_RT5651_IN1_IN2_MAP:
110118
dev_info(dev, "quirk IN1_IN2_MAP enabled");
119+
break;
120+
default:
121+
dev_warn_once(dev, "quirk sets invalid input map: 0x%x, default to DMIC_MAP\n", map);
122+
byt_rt5651_quirk &= ~BYT_RT5651_MAP_MASK;
123+
byt_rt5651_quirk |= BYT_RT5651_DMIC_MAP;
124+
break;
125+
}
126+
111127
if (BYT_RT5651_JDSRC(byt_rt5651_quirk)) {
112128
dev_info(dev, "quirk realtek,jack-detect-source %ld\n",
113129
BYT_RT5651_JDSRC(byt_rt5651_quirk));

0 commit comments

Comments
 (0)