Skip to content

Commit daf3f0f

Browse files
rfvirgilbroonie
authored andcommitted
ASoC: wm_adsp: Don't overwrite fwf_name with the default
There's no need to overwrite fwf_name with a kstrdup() of the cs_dsp part name. It is trivial to select either fwf_name or cs_dsp.part as the string to use when building the filename in wm_adsp_request_firmware_file(). This leaves fwf_name entirely owned by the codec driver. It also avoids problems with freeing the pointer. With the original code fwf_name was either a pointer owned by the codec driver, or a kstrdup() created by wm_adsp. This meant wm_adsp must free it if it set it, but not if the codec driver set it. The code was handling this by using devm_kstrdup(). But there is no absolute requirement that wm_adsp_common_init() must be called from probe(), so this was a pseudo-memory leak - each new call to wm_adsp_common_init() would allocate another block of memory but these would only be freed if the owning codec driver was removed. Signed-off-by: Richard Fitzgerald <[email protected]> Link: https://msgid.link/r/[email protected] Signed-off-by: Mark Brown <[email protected]>
1 parent 3657e4c commit daf3f0f

File tree

1 file changed

+12
-17
lines changed

1 file changed

+12
-17
lines changed

sound/soc/codecs/wm_adsp.c

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -739,19 +739,25 @@ static int wm_adsp_request_firmware_file(struct wm_adsp *dsp,
739739
const char *filetype)
740740
{
741741
struct cs_dsp *cs_dsp = &dsp->cs_dsp;
742+
const char *fwf;
742743
char *s, c;
743744
int ret = 0;
744745

746+
if (dsp->fwf_name)
747+
fwf = dsp->fwf_name;
748+
else
749+
fwf = dsp->cs_dsp.name;
750+
745751
if (system_name && asoc_component_prefix)
746752
*filename = kasprintf(GFP_KERNEL, "%s%s-%s-%s-%s-%s.%s", dir, dsp->part,
747-
dsp->fwf_name, wm_adsp_fw[dsp->fw].file, system_name,
753+
fwf, wm_adsp_fw[dsp->fw].file, system_name,
748754
asoc_component_prefix, filetype);
749755
else if (system_name)
750756
*filename = kasprintf(GFP_KERNEL, "%s%s-%s-%s-%s.%s", dir, dsp->part,
751-
dsp->fwf_name, wm_adsp_fw[dsp->fw].file, system_name,
757+
fwf, wm_adsp_fw[dsp->fw].file, system_name,
752758
filetype);
753759
else
754-
*filename = kasprintf(GFP_KERNEL, "%s%s-%s-%s.%s", dir, dsp->part, dsp->fwf_name,
760+
*filename = kasprintf(GFP_KERNEL, "%s%s-%s-%s.%s", dir, dsp->part, fwf,
755761
wm_adsp_fw[dsp->fw].file, filetype);
756762

757763
if (*filename == NULL)
@@ -857,29 +863,18 @@ static int wm_adsp_request_firmware_files(struct wm_adsp *dsp,
857863
}
858864

859865
adsp_err(dsp, "Failed to request firmware <%s>%s-%s-%s<-%s<%s>>.wmfw\n",
860-
cirrus_dir, dsp->part, dsp->fwf_name, wm_adsp_fw[dsp->fw].file,
861-
system_name, asoc_component_prefix);
866+
cirrus_dir, dsp->part,
867+
dsp->fwf_name ? dsp->fwf_name : dsp->cs_dsp.name,
868+
wm_adsp_fw[dsp->fw].file, system_name, asoc_component_prefix);
862869

863870
return -ENOENT;
864871
}
865872

866873
static int wm_adsp_common_init(struct wm_adsp *dsp)
867874
{
868-
char *p;
869-
870875
INIT_LIST_HEAD(&dsp->compr_list);
871876
INIT_LIST_HEAD(&dsp->buffer_list);
872877

873-
if (!dsp->fwf_name) {
874-
p = devm_kstrdup(dsp->cs_dsp.dev, dsp->cs_dsp.name, GFP_KERNEL);
875-
if (!p)
876-
return -ENOMEM;
877-
878-
dsp->fwf_name = p;
879-
for (; *p != 0; ++p)
880-
*p = tolower(*p);
881-
}
882-
883878
return 0;
884879
}
885880

0 commit comments

Comments
 (0)