[PATCH 09/10] ASoC: wm_adsp: Use a struct to pass around firmware struct and filename

From: Richard Fitzgerald

Date: Tue Mar 10 2026 - 10:51:03 EST


Bundle the pointers to struct firmware and its filename into a new
struct wm_adsp_fw_files. This simplifies passing these pointers around.

Changes are also needed to the test cases in wm_adsp_fw_find_test.c that
use this API.

Signed-off-by: Richard Fitzgerald <rf@xxxxxxxxxxxxxxxxxxxxx>
---
sound/soc/codecs/wm_adsp.c | 123 ++++++++++--------------
sound/soc/codecs/wm_adsp.h | 21 ++--
sound/soc/codecs/wm_adsp_fw_find_test.c | 47 +++------
3 files changed, 77 insertions(+), 114 deletions(-)

diff --git a/sound/soc/codecs/wm_adsp.c b/sound/soc/codecs/wm_adsp.c
index 034766760c86..1c480d59bd55 100644
--- a/sound/soc/codecs/wm_adsp.c
+++ b/sound/soc/codecs/wm_adsp.c
@@ -717,20 +717,15 @@ int wm_adsp_read_ctl(struct wm_adsp *dsp, const char *name, int type,
}
EXPORT_SYMBOL_GPL(wm_adsp_read_ctl);

-VISIBLE_IF_KUNIT void wm_adsp_release_firmware_files(const struct firmware *wmfw_firmware,
- char *wmfw_filename,
- const struct firmware *coeff_firmware,
- char *coeff_filename)
+VISIBLE_IF_KUNIT void wm_adsp_release_firmware_files(struct wm_adsp_fw_files *fw)
{
- KUNIT_STATIC_STUB_REDIRECT(wm_adsp_release_firmware_files,
- wmfw_firmware, wmfw_filename,
- coeff_firmware, coeff_filename);
+ KUNIT_STATIC_STUB_REDIRECT(wm_adsp_release_firmware_files, fw);

- release_firmware(wmfw_firmware);
- kfree(wmfw_filename);
+ release_firmware(fw->wmfw.firmware);
+ kfree(fw->wmfw.filename);

- release_firmware(coeff_firmware);
- kfree(coeff_filename);
+ release_firmware(fw->coeff.firmware);
+ kfree(fw->coeff.filename);
}
EXPORT_SYMBOL_IF_KUNIT(wm_adsp_release_firmware_files);

@@ -745,7 +740,7 @@ VISIBLE_IF_KUNIT int wm_adsp_firmware_request(const struct firmware **firmware,
EXPORT_SYMBOL_IF_KUNIT(wm_adsp_firmware_request);

static int wm_adsp_request_firmware_file(struct wm_adsp *dsp,
- const struct firmware **firmware, char **filename,
+ struct wm_adsp_fw_file *fw,
const char *dir, const char *system_name,
const char *asoc_component_prefix,
const char *filetype)
@@ -761,25 +756,25 @@ static int wm_adsp_request_firmware_file(struct wm_adsp *dsp,
fwf = dsp->cs_dsp.name;

if (system_name && asoc_component_prefix)
- *filename = kasprintf(GFP_KERNEL, "%s%s-%s-%s-%s-%s.%s", dir, dsp->part,
- fwf, wm_adsp_fw[dsp->fw].file, system_name,
- asoc_component_prefix, filetype);
+ fw->filename = kasprintf(GFP_KERNEL, "%s%s-%s-%s-%s-%s.%s", dir, dsp->part,
+ fwf, wm_adsp_fw[dsp->fw].file, system_name,
+ asoc_component_prefix, filetype);
else if (system_name)
- *filename = kasprintf(GFP_KERNEL, "%s%s-%s-%s-%s.%s", dir, dsp->part,
- fwf, wm_adsp_fw[dsp->fw].file, system_name,
- filetype);
+ fw->filename = kasprintf(GFP_KERNEL, "%s%s-%s-%s-%s.%s", dir, dsp->part,
+ fwf, wm_adsp_fw[dsp->fw].file, system_name,
+ filetype);
else
- *filename = kasprintf(GFP_KERNEL, "%s%s-%s-%s.%s", dir, dsp->part, fwf,
- wm_adsp_fw[dsp->fw].file, filetype);
+ fw->filename = kasprintf(GFP_KERNEL, "%s%s-%s-%s.%s", dir, dsp->part, fwf,
+ wm_adsp_fw[dsp->fw].file, filetype);

- if (*filename == NULL)
+ if (!fw->filename)
return -ENOMEM;

/*
* Make sure that filename after dir is lower-case and any non-alpha-numeric
* characters except full-stop are replaced with hyphens.
*/
- s = *filename + strlen(dir);
+ s = fw->filename + strlen(dir);
while (*s) {
c = *s;
if (isalnum(c))
@@ -789,15 +784,15 @@ static int wm_adsp_request_firmware_file(struct wm_adsp *dsp,
s++;
}

- ret = wm_adsp_firmware_request(firmware, *filename, cs_dsp->dev);
+ ret = wm_adsp_firmware_request(&fw->firmware, fw->filename, cs_dsp->dev);
if (ret < 0) {
- adsp_dbg(dsp, "Failed to request '%s': %d\n", *filename, ret);
- kfree(*filename);
- *filename = NULL;
+ adsp_dbg(dsp, "Failed to request '%s': %d\n", fw->filename, ret);
+ kfree(fw->filename);
+ fw->filename = NULL;
if (ret != -ENOENT)
return ret;
} else {
- adsp_dbg(dsp, "Found '%s'\n", *filename);
+ adsp_dbg(dsp, "Found '%s'\n", fw->filename);
}

return 0;
@@ -805,10 +800,7 @@ static int wm_adsp_request_firmware_file(struct wm_adsp *dsp,

static const char * const cirrus_dir = "cirrus/";
VISIBLE_IF_KUNIT int wm_adsp_request_firmware_files(struct wm_adsp *dsp,
- const struct firmware **wmfw_firmware,
- char **wmfw_filename,
- const struct firmware **coeff_firmware,
- char **coeff_filename)
+ struct wm_adsp_fw_files *fw)
{
const char *system_name = dsp->system_name;
const char *suffix = dsp->component->name_prefix;
@@ -818,14 +810,14 @@ VISIBLE_IF_KUNIT int wm_adsp_request_firmware_files(struct wm_adsp *dsp,
suffix = dsp->fwf_suffix;

if (system_name && suffix) {
- ret = wm_adsp_request_firmware_file(dsp, wmfw_firmware, wmfw_filename,
+ ret = wm_adsp_request_firmware_file(dsp, &fw->wmfw,
cirrus_dir, system_name,
suffix, "wmfw");
if (ret < 0)
goto err;

- if (*wmfw_firmware) {
- ret = wm_adsp_request_firmware_file(dsp, coeff_firmware, coeff_filename,
+ if (fw->wmfw.firmware) {
+ ret = wm_adsp_request_firmware_file(dsp, &fw->coeff,
cirrus_dir, system_name,
suffix, "bin");
if (ret < 0)
@@ -836,45 +828,43 @@ VISIBLE_IF_KUNIT int wm_adsp_request_firmware_files(struct wm_adsp *dsp,
}

if (system_name) {
- ret = wm_adsp_request_firmware_file(dsp, wmfw_firmware, wmfw_filename,
+ ret = wm_adsp_request_firmware_file(dsp, &fw->wmfw,
cirrus_dir, system_name,
NULL, "wmfw");
if (ret < 0)
goto err;

- if (*wmfw_firmware || dsp->wmfw_optional) {
+ if (fw->wmfw.firmware || dsp->wmfw_optional) {
if (suffix) {
ret = wm_adsp_request_firmware_file(dsp,
- coeff_firmware, coeff_filename,
+ &fw->coeff,
cirrus_dir, system_name,
suffix, "bin");
if (ret < 0)
goto err;
}

- if (!*coeff_firmware) {
+ if (!fw->coeff.firmware) {
ret = wm_adsp_request_firmware_file(dsp,
- coeff_firmware, coeff_filename,
+ &fw->coeff,
cirrus_dir, system_name,
NULL, "bin");
if (ret < 0)
goto err;
}

- if (*wmfw_firmware || (dsp->wmfw_optional && *coeff_firmware))
+ if (fw->wmfw.firmware || (dsp->wmfw_optional && fw->coeff.firmware))
return 0;
}
}

/* Check legacy location */
- ret = wm_adsp_request_firmware_file(dsp, wmfw_firmware, wmfw_filename,
- "", NULL, NULL, "wmfw");
+ ret = wm_adsp_request_firmware_file(dsp, &fw->wmfw, "", NULL, NULL, "wmfw");
if (ret < 0)
goto err;

- if (*wmfw_firmware) {
- ret = wm_adsp_request_firmware_file(dsp, coeff_firmware, coeff_filename,
- "", NULL, NULL, "bin");
+ if (fw->wmfw.firmware) {
+ ret = wm_adsp_request_firmware_file(dsp, &fw->coeff, "", NULL, NULL, "bin");
if (ret < 0)
goto err;

@@ -882,13 +872,13 @@ VISIBLE_IF_KUNIT int wm_adsp_request_firmware_files(struct wm_adsp *dsp,
}

/* Fall back to generic wmfw and optional matching bin */
- ret = wm_adsp_request_firmware_file(dsp, wmfw_firmware, wmfw_filename,
+ ret = wm_adsp_request_firmware_file(dsp, &fw->wmfw,
cirrus_dir, NULL, NULL, "wmfw");
if (ret < 0)
goto err;

- if (*wmfw_firmware || dsp->wmfw_optional) {
- ret = wm_adsp_request_firmware_file(dsp, coeff_firmware, coeff_filename,
+ if (fw->wmfw.firmware || dsp->wmfw_optional) {
+ ret = wm_adsp_request_firmware_file(dsp, &fw->coeff,
cirrus_dir, NULL, NULL, "bin");
if (ret < 0)
goto err;
@@ -903,8 +893,7 @@ VISIBLE_IF_KUNIT int wm_adsp_request_firmware_files(struct wm_adsp *dsp,

ret = -ENOENT;
err:
- wm_adsp_release_firmware_files(*wmfw_firmware, *wmfw_filename,
- *coeff_firmware, *coeff_filename);
+ wm_adsp_release_firmware_files(fw);

return ret;
}
@@ -939,29 +928,23 @@ int wm_adsp1_event(struct snd_soc_dapm_widget *w,
struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm);
struct wm_adsp *dsps = snd_soc_component_get_drvdata(component);
struct wm_adsp *dsp = &dsps[w->shift];
+ struct wm_adsp_fw_files fw = { 0 };
int ret = 0;
- char *wmfw_filename = NULL;
- const struct firmware *wmfw_firmware = NULL;
- char *coeff_filename = NULL;
- const struct firmware *coeff_firmware = NULL;

dsp->component = component;

switch (event) {
case SND_SOC_DAPM_POST_PMU:
- ret = wm_adsp_request_firmware_files(dsp,
- &wmfw_firmware, &wmfw_filename,
- &coeff_firmware, &coeff_filename);
+ ret = wm_adsp_request_firmware_files(dsp, &fw);
if (ret)
break;

ret = cs_dsp_adsp1_power_up(&dsp->cs_dsp,
- wmfw_firmware, wmfw_filename,
- coeff_firmware, coeff_filename,
+ fw.wmfw.firmware, fw.wmfw.filename,
+ fw.coeff.firmware, fw.coeff.filename,
wm_adsp_fw_text[dsp->fw]);

- wm_adsp_release_firmware_files(wmfw_firmware, wmfw_filename,
- coeff_firmware, coeff_filename);
+ wm_adsp_release_firmware_files(&fw);
break;
case SND_SOC_DAPM_PRE_PMD:
cs_dsp_adsp1_power_down(&dsp->cs_dsp);
@@ -1037,33 +1020,27 @@ EXPORT_SYMBOL_GPL(wm_adsp2_preloader_put);

int wm_adsp_power_up(struct wm_adsp *dsp, bool load_firmware)
{
+ struct wm_adsp_fw_files fw = { 0 };
int ret = 0;
- char *wmfw_filename = NULL;
- const struct firmware *wmfw_firmware = NULL;
- char *coeff_filename = NULL;
- const struct firmware *coeff_firmware = NULL;

if (load_firmware) {
- ret = wm_adsp_request_firmware_files(dsp,
- &wmfw_firmware, &wmfw_filename,
- &coeff_firmware, &coeff_filename);
+ ret = wm_adsp_request_firmware_files(dsp, &fw);
if (ret)
return ret;
}

- if (dsp->bin_mandatory && !coeff_firmware) {
+ if (dsp->bin_mandatory && !fw.coeff.firmware) {
ret = -ENOENT;
goto err;
}

ret = cs_dsp_power_up(&dsp->cs_dsp,
- wmfw_firmware, wmfw_filename,
- coeff_firmware, coeff_filename,
+ fw.wmfw.firmware, fw.wmfw.filename,
+ fw.coeff.firmware, fw.coeff.filename,
wm_adsp_fw_text[dsp->fw]);

err:
- wm_adsp_release_firmware_files(wmfw_firmware, wmfw_filename,
- coeff_firmware, coeff_filename);
+ wm_adsp_release_firmware_files(&fw);

return ret;
}
diff --git a/sound/soc/codecs/wm_adsp.h b/sound/soc/codecs/wm_adsp.h
index b4d5bd321c0b..8922732479c2 100644
--- a/sound/soc/codecs/wm_adsp.h
+++ b/sound/soc/codecs/wm_adsp.h
@@ -79,6 +79,16 @@ struct wm_adsp {
SOC_ENUM_EXT(dspname " Firmware", wm_adsp_fw_enum[num], \
wm_adsp_fw_get, wm_adsp_fw_put)

+struct wm_adsp_fw_file {
+ const struct firmware *firmware;
+ char *filename;
+};
+
+struct wm_adsp_fw_files {
+ struct wm_adsp_fw_file wmfw;
+ struct wm_adsp_fw_file coeff;
+};
+
extern const struct soc_enum wm_adsp_fw_enum[];

int wm_adsp1_init(struct wm_adsp *dsp);
@@ -145,18 +155,11 @@ int wm_adsp_read_ctl(struct wm_adsp *dsp, const char *name, int type,

#if IS_ENABLED(CONFIG_KUNIT)
const char *wm_adsp_get_fwf_name_by_index(int index);
-void wm_adsp_release_firmware_files(const struct firmware *wmfw_firmware,
- char *wmfw_filename,
- const struct firmware *coeff_firmware,
- char *coeff_filename);
+void wm_adsp_release_firmware_files(struct wm_adsp_fw_files *fw);
int wm_adsp_firmware_request(const struct firmware **firmware,
const char *filename,
struct device *dev);
-int wm_adsp_request_firmware_files(struct wm_adsp *dsp,
- const struct firmware **wmfw_firmware,
- char **wmfw_filename,
- const struct firmware **coeff_firmware,
- char **coeff_filename);
+int wm_adsp_request_firmware_files(struct wm_adsp *dsp, struct wm_adsp_fw_files *fw);
#endif

#endif
diff --git a/sound/soc/codecs/wm_adsp_fw_find_test.c b/sound/soc/codecs/wm_adsp_fw_find_test.c
index 11047851fd80..44c26e991b35 100644
--- a/sound/soc/codecs/wm_adsp_fw_find_test.c
+++ b/sound/soc/codecs/wm_adsp_fw_find_test.c
@@ -16,10 +16,7 @@ KUNIT_DEFINE_ACTION_WRAPPER(_put_device_wrapper, put_device, struct device *);
struct wm_adsp_fw_find_test {
struct wm_adsp dsp;

- const struct firmware *found_wmfw_firmware;
- const struct firmware *found_bin_firmware;
- char *found_wmfw_filename;
- char *found_bin_filename;
+ struct wm_adsp_fw_files found_fw;
char searched_fw_files[768];
};

@@ -101,28 +98,24 @@ static void wm_adsp_fw_find_test_pick_file(struct kunit *test)
wm_adsp_firmware_request,
wm_adsp_fw_find_test_firmware_request_simple_stub);

- ret = wm_adsp_request_firmware_files(dsp,
- &priv->found_wmfw_firmware,
- &priv->found_wmfw_filename,
- &priv->found_bin_firmware,
- &priv->found_bin_filename);
+ ret = wm_adsp_request_firmware_files(dsp, &priv->found_fw);
kunit_deactivate_static_stub(test, wm_adsp_firmware_request);
KUNIT_EXPECT_EQ_MSG(test, ret,
(params->expect_wmfw || params->expect_bin) ? 0 : -ENOENT,
"%s\n", priv->searched_fw_files);

- KUNIT_EXPECT_EQ_MSG(test, !!priv->found_wmfw_filename, !!params->expect_wmfw,
+ KUNIT_EXPECT_EQ_MSG(test, !!priv->found_fw.wmfw.filename, !!params->expect_wmfw,
"%s\n", priv->searched_fw_files);
- KUNIT_EXPECT_EQ_MSG(test, !!priv->found_bin_filename, !!params->expect_bin,
+ KUNIT_EXPECT_EQ_MSG(test, !!priv->found_fw.coeff.filename, !!params->expect_bin,
"%s\n", priv->searched_fw_files);

if (params->expect_wmfw) {
- KUNIT_EXPECT_STREQ_MSG(test, priv->found_wmfw_filename, params->expect_wmfw,
+ KUNIT_EXPECT_STREQ_MSG(test, priv->found_fw.wmfw.filename, params->expect_wmfw,
"%s\n", priv->searched_fw_files);
}

if (params->expect_bin) {
- KUNIT_EXPECT_STREQ_MSG(test, priv->found_bin_filename, params->expect_bin,
+ KUNIT_EXPECT_STREQ_MSG(test, priv->found_fw.coeff.filename, params->expect_bin,
"%s\n", priv->searched_fw_files);
}
}
@@ -181,27 +174,23 @@ static void wm_adsp_fw_find_test_search_order(struct kunit *test)
wm_adsp_firmware_request,
wm_adsp_fw_find_test_firmware_request_stub);

- wm_adsp_request_firmware_files(dsp,
- &priv->found_wmfw_firmware,
- &priv->found_wmfw_filename,
- &priv->found_bin_firmware,
- &priv->found_bin_filename);
+ wm_adsp_request_firmware_files(dsp, &priv->found_fw);

kunit_deactivate_static_stub(test, wm_adsp_firmware_request);

KUNIT_EXPECT_STREQ(test, priv->searched_fw_files, params->expected_searches);

- KUNIT_EXPECT_EQ(test, !!priv->found_wmfw_filename, !!params->expect_wmfw);
+ KUNIT_EXPECT_EQ(test, !!priv->found_fw.wmfw.filename, !!params->expect_wmfw);
if (params->expect_wmfw)
- KUNIT_EXPECT_STREQ(test, priv->found_wmfw_filename, params->expect_wmfw);
+ KUNIT_EXPECT_STREQ(test, priv->found_fw.wmfw.filename, params->expect_wmfw);

- KUNIT_EXPECT_EQ(test, !!priv->found_bin_filename, !!params->expect_bin);
+ KUNIT_EXPECT_EQ(test, !!priv->found_fw.coeff.filename, !!params->expect_bin);
if (params->expect_bin)
- KUNIT_EXPECT_STREQ(test, priv->found_bin_filename, params->expect_bin);
+ KUNIT_EXPECT_STREQ(test, priv->found_fw.coeff.filename, params->expect_bin);

/* Either we get a filename and firmware, or neither */
- KUNIT_EXPECT_EQ(test, !!priv->found_wmfw_filename, !!priv->found_wmfw_firmware);
- KUNIT_EXPECT_EQ(test, !!priv->found_bin_filename, !!priv->found_bin_firmware);
+ KUNIT_EXPECT_EQ(test, !!priv->found_fw.wmfw.filename, !!priv->found_fw.wmfw.firmware);
+ KUNIT_EXPECT_EQ(test, !!priv->found_fw.coeff.filename, !!priv->found_fw.coeff.firmware);
}

static void wm_adsp_fw_find_test_find_firmware_byindex(struct kunit *test)
@@ -221,12 +210,7 @@ static void wm_adsp_fw_find_test_find_firmware_byindex(struct kunit *test)
wm_adsp_firmware_request,
wm_adsp_fw_find_test_firmware_request_stub);

- wm_adsp_request_firmware_files(dsp,
- &priv->found_wmfw_firmware,
- &priv->found_wmfw_filename,
- &priv->found_bin_firmware,
- &priv->found_bin_filename);
-
+ wm_adsp_request_firmware_files(dsp, &priv->found_fw);
kunit_deactivate_static_stub(test, wm_adsp_firmware_request);

KUNIT_EXPECT_NOT_NULL_MSG(test,
@@ -278,8 +262,7 @@ static void wm_adsp_fw_find_test_case_exit(struct kunit *test)
* dummies not allocated by the real request_firmware() call they
* must not be passed to release_firmware().
*/
- wm_adsp_release_firmware_files(NULL, priv->found_wmfw_filename,
- NULL, priv->found_bin_filename);
+ wm_adsp_release_firmware_files(&priv->found_fw);
}

static void wm_adsp_fw_find_test_param_desc(const struct wm_adsp_fw_find_test_params *param,
--
2.47.3