Skip to content

Commit 70057cf

Browse files
rfvirgilbroonie
authored andcommitted
ASoC: wm_adsp: Add KUnit redirection stubs for firmware file search
Make some of the firmware file search functions redirectable for KUnit testing. - The call to firmware_request_nowarn() is factored out into a wrapper function so that it can be redirected. - wm_adsp_request_firmware_files() and wm_adsp_release_firmware_files() are made visible and exported if KUNIT is enabled. Signed-off-by: Richard Fitzgerald <rf@opensource.cirrus.com> Link: https://patch.msgid.link/20260310141817.1871794-3-rf@opensource.cirrus.com Signed-off-by: Mark Brown <broonie@kernel.org>
1 parent 1eadb77 commit 70057cf

2 files changed

Lines changed: 43 additions & 10 deletions

File tree

sound/soc/codecs/wm_adsp.c

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
* Author: Mark Brown <broonie@opensource.wolfsonmicro.com>
88
*/
99

10+
#include <kunit/static_stub.h>
11+
#include <kunit/visibility.h>
1012
#include <linux/array_size.h>
1113
#include <linux/cleanup.h>
1214
#include <linux/ctype.h>
@@ -704,17 +706,32 @@ int wm_adsp_read_ctl(struct wm_adsp *dsp, const char *name, int type,
704706
}
705707
EXPORT_SYMBOL_GPL(wm_adsp_read_ctl);
706708

707-
static void wm_adsp_release_firmware_files(const struct firmware *wmfw_firmware,
708-
char *wmfw_filename,
709-
const struct firmware *coeff_firmware,
710-
char *coeff_filename)
709+
VISIBLE_IF_KUNIT void wm_adsp_release_firmware_files(const struct firmware *wmfw_firmware,
710+
char *wmfw_filename,
711+
const struct firmware *coeff_firmware,
712+
char *coeff_filename)
711713
{
714+
KUNIT_STATIC_STUB_REDIRECT(wm_adsp_release_firmware_files,
715+
wmfw_firmware, wmfw_filename,
716+
coeff_firmware, coeff_filename);
717+
712718
release_firmware(wmfw_firmware);
713719
kfree(wmfw_filename);
714720

715721
release_firmware(coeff_firmware);
716722
kfree(coeff_filename);
717723
}
724+
EXPORT_SYMBOL_IF_KUNIT(wm_adsp_release_firmware_files);
725+
726+
VISIBLE_IF_KUNIT int wm_adsp_firmware_request(const struct firmware **firmware,
727+
const char *filename,
728+
struct device *dev)
729+
{
730+
KUNIT_STATIC_STUB_REDIRECT(wm_adsp_firmware_request, firmware, filename, dev);
731+
732+
return firmware_request_nowarn(firmware, filename, dev);
733+
}
734+
EXPORT_SYMBOL_IF_KUNIT(wm_adsp_firmware_request);
718735

719736
static int wm_adsp_request_firmware_file(struct wm_adsp *dsp,
720737
const struct firmware **firmware, char **filename,
@@ -762,7 +779,7 @@ static int wm_adsp_request_firmware_file(struct wm_adsp *dsp,
762779
s++;
763780
}
764781

765-
ret = firmware_request_nowarn(firmware, *filename, cs_dsp->dev);
782+
ret = wm_adsp_firmware_request(firmware, *filename, cs_dsp->dev);
766783
if (ret != 0) {
767784
adsp_dbg(dsp, "Failed to request '%s'\n", *filename);
768785
kfree(*filename);
@@ -775,11 +792,11 @@ static int wm_adsp_request_firmware_file(struct wm_adsp *dsp,
775792
}
776793

777794
static const char * const cirrus_dir = "cirrus/";
778-
static int wm_adsp_request_firmware_files(struct wm_adsp *dsp,
779-
const struct firmware **wmfw_firmware,
780-
char **wmfw_filename,
781-
const struct firmware **coeff_firmware,
782-
char **coeff_filename)
795+
VISIBLE_IF_KUNIT int wm_adsp_request_firmware_files(struct wm_adsp *dsp,
796+
const struct firmware **wmfw_firmware,
797+
char **wmfw_filename,
798+
const struct firmware **coeff_firmware,
799+
char **coeff_filename)
783800
{
784801
const char *system_name = dsp->system_name;
785802
const char *suffix = dsp->component->name_prefix;
@@ -856,6 +873,7 @@ static int wm_adsp_request_firmware_files(struct wm_adsp *dsp,
856873

857874
return -ENOENT;
858875
}
876+
EXPORT_SYMBOL_IF_KUNIT(wm_adsp_request_firmware_files);
859877

860878
static int wm_adsp_common_init(struct wm_adsp *dsp)
861879
{

sound/soc/codecs/wm_adsp.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,4 +142,19 @@ int wm_adsp_write_ctl(struct wm_adsp *dsp, const char *name, int type,
142142
int wm_adsp_read_ctl(struct wm_adsp *dsp, const char *name, int type,
143143
unsigned int alg, void *buf, size_t len);
144144

145+
#if IS_ENABLED(CONFIG_KUNIT)
146+
void wm_adsp_release_firmware_files(const struct firmware *wmfw_firmware,
147+
char *wmfw_filename,
148+
const struct firmware *coeff_firmware,
149+
char *coeff_filename);
150+
int wm_adsp_firmware_request(const struct firmware **firmware,
151+
const char *filename,
152+
struct device *dev);
153+
int wm_adsp_request_firmware_files(struct wm_adsp *dsp,
154+
const struct firmware **wmfw_firmware,
155+
char **wmfw_filename,
156+
const struct firmware **coeff_firmware,
157+
char **coeff_filename);
158+
#endif
159+
145160
#endif

0 commit comments

Comments
 (0)