Skip to content

Commit

Permalink
ASoC: Intel: avs: Fix route override
Browse files Browse the repository at this point in the history
BugLink: https://bugs.launchpad.net/bugs/2078304

[ Upstream commit fd660b1 ]

Instead of overriding existing memory strings that may be too short,
just allocate needed memory and point the route at it.

Reported-by: Jason Montleon <jmontleo@redhat.com>
Link: thesofproject/avs-topology-xml#22 (comment)
Reviewed-by: Cezary Rojewski <cezary.rojewski@intel.com>
Signed-off-by: Amadeusz Sławiński <amadeuszx.slawinski@linux.intel.com>
Link: https://lore.kernel.org/r/20240603102818.36165-3-amadeuszx.slawinski@linux.intel.com
Signed-off-by: Mark Brown <broonie@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
Signed-off-by: Portia Stephens <portia.stephens@canonical.com>
Signed-off-by: Stefan Bader <stefan.bader@canonical.com>
  • Loading branch information
Amadeusz Sławiński authored and smb49 committed Sep 27, 2024
1 parent 1c2b8b3 commit 3368904
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions sound/soc/intel/avs/topology.c
Original file line number Diff line number Diff line change
Expand Up @@ -1421,8 +1421,8 @@ static int avs_route_load(struct snd_soc_component *comp, int index,
{
struct snd_soc_acpi_mach *mach = dev_get_platdata(comp->card->dev);
size_t len = SNDRV_CTL_ELEM_ID_NAME_MAXLEN;
char buf[SNDRV_CTL_ELEM_ID_NAME_MAXLEN];
int ssp_port, tdm_slot;
char *buf;

/* See parse_link_formatted_string() for dynamic naming when(s). */
if (!avs_mach_singular_ssp(mach))
Expand All @@ -1433,13 +1433,24 @@ static int avs_route_load(struct snd_soc_component *comp, int index,
return 0;
tdm_slot = avs_mach_ssp_tdm(mach, ssp_port);

buf = devm_kzalloc(comp->card->dev, len, GFP_KERNEL);
if (!buf)
return -ENOMEM;
avs_ssp_sprint(buf, len, route->source, ssp_port, tdm_slot);
strscpy((char *)route->source, buf, len);
route->source = buf;

buf = devm_kzalloc(comp->card->dev, len, GFP_KERNEL);
if (!buf)
return -ENOMEM;
avs_ssp_sprint(buf, len, route->sink, ssp_port, tdm_slot);
strscpy((char *)route->sink, buf, len);
route->sink = buf;

if (route->control) {
buf = devm_kzalloc(comp->card->dev, len, GFP_KERNEL);
if (!buf)
return -ENOMEM;
avs_ssp_sprint(buf, len, route->control, ssp_port, tdm_slot);
strscpy((char *)route->control, buf, len);
route->control = buf;
}

return 0;
Expand Down

0 comments on commit 3368904

Please sign in to comment.