Skip to content

Commit ab97833

Browse files
Amadeusz Sławińskiintel-lab-lkp
Amadeusz Sławiński
authored andcommitted
ASoC: Intel: avs: Use lookup table to create modules
As reported by Nathan, when building avs driver using clang with: CONFIG_COMPILE_TEST=y CONFIG_FORTIFY_SOURCE=y CONFIG_KASAN=y CONFIG_PCI=y CONFIG_SOUND=y CONFIG_SND=y CONFIG_SND_SOC=y CONFIG_SND_SOC_INTEL_AVS=y there are reports of too big stack use, like: sound/soc/intel/avs/path.c:815:18: error: stack frame size (2176) exceeds limit (2048) in 'avs_path_create' [-Werror,-Wframe-larger-than] struct avs_path *avs_path_create(struct avs_dev *adev, u32 dma_id, ^ 1 error generated. This is apparently caused by inlining many calls to guid_equal which inlines fortified memcpy, using 2 size_t variables. Instead of hardcoding many calls to guid_equal, use lookup table with one call, this improves stack usage. Link: https://lore.kernel.org/alsa-devel/[email protected]/T/ Link: ClangBuiltLinux#1642 Signed-off-by: Amadeusz Sławiński <[email protected]> Reported-by: Nathan Chancellor <[email protected]> Build-tested-by: Nathan Chancellor <[email protected]>
1 parent 9f26bd6 commit ab97833

File tree

1 file changed

+29
-25
lines changed

1 file changed

+29
-25
lines changed

sound/soc/intel/avs/path.c

Lines changed: 29 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -449,35 +449,39 @@ static int avs_modext_create(struct avs_dev *adev, struct avs_path_module *mod)
449449
return ret;
450450
}
451451

452+
static int avs_probe_create(struct avs_dev *adev, struct avs_path_module *mod)
453+
{
454+
dev_err(adev->dev, "Probe module can't be instantiated by topology");
455+
return -EINVAL;
456+
}
457+
458+
struct avs_module_create {
459+
guid_t *guid;
460+
int (*create)(struct avs_dev *adev, struct avs_path_module *mod);
461+
};
462+
463+
static struct avs_module_create avs_module_create[] = {
464+
{ &AVS_MIXIN_MOD_UUID, avs_modbase_create },
465+
{ &AVS_MIXOUT_MOD_UUID, avs_modbase_create },
466+
{ &AVS_KPBUFF_MOD_UUID, avs_modbase_create },
467+
{ &AVS_COPIER_MOD_UUID, avs_copier_create },
468+
{ &AVS_MICSEL_MOD_UUID, avs_micsel_create },
469+
{ &AVS_MUX_MOD_UUID, avs_mux_create },
470+
{ &AVS_UPDWMIX_MOD_UUID, avs_updown_mix_create },
471+
{ &AVS_SRCINTC_MOD_UUID, avs_src_create },
472+
{ &AVS_AEC_MOD_UUID, avs_aec_create },
473+
{ &AVS_ASRC_MOD_UUID, avs_asrc_create },
474+
{ &AVS_INTELWOV_MOD_UUID, avs_wov_create },
475+
{ &AVS_PROBE_MOD_UUID, avs_probe_create },
476+
};
477+
452478
static int avs_path_module_type_create(struct avs_dev *adev, struct avs_path_module *mod)
453479
{
454480
const guid_t *type = &mod->template->cfg_ext->type;
455481

456-
if (guid_equal(type, &AVS_MIXIN_MOD_UUID) ||
457-
guid_equal(type, &AVS_MIXOUT_MOD_UUID) ||
458-
guid_equal(type, &AVS_KPBUFF_MOD_UUID))
459-
return avs_modbase_create(adev, mod);
460-
if (guid_equal(type, &AVS_COPIER_MOD_UUID))
461-
return avs_copier_create(adev, mod);
462-
if (guid_equal(type, &AVS_MICSEL_MOD_UUID))
463-
return avs_micsel_create(adev, mod);
464-
if (guid_equal(type, &AVS_MUX_MOD_UUID))
465-
return avs_mux_create(adev, mod);
466-
if (guid_equal(type, &AVS_UPDWMIX_MOD_UUID))
467-
return avs_updown_mix_create(adev, mod);
468-
if (guid_equal(type, &AVS_SRCINTC_MOD_UUID))
469-
return avs_src_create(adev, mod);
470-
if (guid_equal(type, &AVS_AEC_MOD_UUID))
471-
return avs_aec_create(adev, mod);
472-
if (guid_equal(type, &AVS_ASRC_MOD_UUID))
473-
return avs_asrc_create(adev, mod);
474-
if (guid_equal(type, &AVS_INTELWOV_MOD_UUID))
475-
return avs_wov_create(adev, mod);
476-
477-
if (guid_equal(type, &AVS_PROBE_MOD_UUID)) {
478-
dev_err(adev->dev, "Probe module can't be instantiated by topology");
479-
return -EINVAL;
480-
}
482+
for (int i = 0; i < ARRAY_SIZE(avs_module_create); i++)
483+
if (guid_equal(type, avs_module_create[i].guid))
484+
return avs_module_create[i].create(adev, mod);
481485

482486
return avs_modext_create(adev, mod);
483487
}

0 commit comments

Comments
 (0)