From: Arnd Bergmann <arnd@xxxxxxxx>
clang warns about excessive stack usage in this driver when
UBSAN is enabled:
drivers/staging/greybus/audio_topology.c:977:12: error: stack frame size of 1836 bytes in function 'gbaudio_tplg_create_widget' [-Werror,-Wframe-larger-than=]
Rework this code to no longer use compound literals for
initializing the structure in each case, but instead keep
the common bits in a preallocated constant array and copy
them as needed.
Signed-off-by: Arnd Bergmann <arnd@xxxxxxxx>
---
drivers/staging/greybus/audio_topology.c | 106 ++++++++++-------------
1 file changed, 47 insertions(+), 59 deletions(-)
diff --git a/drivers/staging/greybus/audio_topology.c b/drivers/staging/greybus/audio_topology.c
index 96b8b29fe899..c03873915c20 100644
--- a/drivers/staging/greybus/audio_topology.c
+++ b/drivers/staging/greybus/audio_topology.c
@@ -974,6 +974,44 @@ static int gbaudio_widget_event(struct snd_soc_dapm_widget *w,
return ret;
}
+static const struct snd_soc_dapm_widget gbaudio_widgets[] = {
+ [snd_soc_dapm_spk] = SND_SOC_DAPM_SPK("spk", gbcodec_event_spk),
+ [snd_soc_dapm_hp] = SND_SOC_DAPM_HP("hp", gbcodec_event_hp),
+ [snd_soc_dapm_mic] = SND_SOC_DAPM_MIC("mic", gbcodec_event_int_mic),
@@ -1050,78 +1088,28 @@ static int gbaudio_tplg_create_widget(struct gbaudio_module_info *module,
strlcpy(temp_name, w->name, NAME_SIZE);
snprintf(w->name, NAME_SIZE, "GB %d %s", module->dev_id, temp_name);
+ if (w->type > ARRAY_SIZE(gbaudio_widgets)) {
+ ret = -EINVAL;
+ goto error;
+ }
+ *dw = gbaudio_widgets[w->type];
+ dw->name = w->name;
+
switch (w->type) {
case snd_soc_dapm_spk:
- *dw = (struct snd_soc_dapm_widget)
- SND_SOC_DAPM_SPK(w->name, gbcodec_event_spk);
module->op_devices |= GBAUDIO_DEVICE_OUT_SPEAKER;
break;
case snd_soc_dapm_hp:
- *dw = (struct snd_soc_dapm_widget)
- SND_SOC_DAPM_HP(w->name, gbcodec_event_hp);
module->op_devices |= (GBAUDIO_DEVICE_OUT_WIRED_HEADSET
- | GBAUDIO_DEVICE_OUT_WIRED_HEADPHONE);
+ | GBAUDIO_DEVICE_OUT_WIRED_HEADPHONE),
module->ip_devices |= GBAUDIO_DEVICE_IN_WIRED_HEADSET;
break;
case snd_soc_dapm_mic:
- *dw = (struct snd_soc_dapm_widget)
- SND_SOC_DAPM_MIC(w->name, gbcodec_event_int_mic);
module->ip_devices |= GBAUDIO_DEVICE_IN_BUILTIN_MIC;
break;