]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
ASoC: wm_adsp: Add KUnit redirection stubs for firmware file search
authorRichard Fitzgerald <rf@opensource.cirrus.com>
Tue, 10 Mar 2026 14:18:09 +0000 (14:18 +0000)
committerMark Brown <broonie@kernel.org>
Tue, 10 Mar 2026 14:52:49 +0000 (14:52 +0000)
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>
sound/soc/codecs/wm_adsp.c
sound/soc/codecs/wm_adsp.h

index b3cead2cd7582fdf782287f5b48cdb4a7d5cebf7..e32da6949d1f68156e647047da3a24ed13c0e6f3 100644 (file)
@@ -7,6 +7,8 @@
  * Author: Mark Brown <broonie@opensource.wolfsonmicro.com>
  */
 
+#include <kunit/static_stub.h>
+#include <kunit/visibility.h>
 #include <linux/array_size.h>
 #include <linux/cleanup.h>
 #include <linux/ctype.h>
@@ -704,17 +706,32 @@ int wm_adsp_read_ctl(struct wm_adsp *dsp, const char *name, int type,
 }
 EXPORT_SYMBOL_GPL(wm_adsp_read_ctl);
 
-static 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(const struct firmware *wmfw_firmware,
+                                                    char *wmfw_filename,
+                                                    const struct firmware *coeff_firmware,
+                                                    char *coeff_filename)
 {
+       KUNIT_STATIC_STUB_REDIRECT(wm_adsp_release_firmware_files,
+                                  wmfw_firmware, wmfw_filename,
+                                  coeff_firmware, coeff_filename);
+
        release_firmware(wmfw_firmware);
        kfree(wmfw_filename);
 
        release_firmware(coeff_firmware);
        kfree(coeff_filename);
 }
+EXPORT_SYMBOL_IF_KUNIT(wm_adsp_release_firmware_files);
+
+VISIBLE_IF_KUNIT int wm_adsp_firmware_request(const struct firmware **firmware,
+                                             const char *filename,
+                                             struct device *dev)
+{
+       KUNIT_STATIC_STUB_REDIRECT(wm_adsp_firmware_request, firmware, filename, dev);
+
+       return firmware_request_nowarn(firmware, filename, dev);
+}
+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,
@@ -762,7 +779,7 @@ static int wm_adsp_request_firmware_file(struct wm_adsp *dsp,
                s++;
        }
 
-       ret = firmware_request_nowarn(firmware, *filename, cs_dsp->dev);
+       ret = wm_adsp_firmware_request(firmware, *filename, cs_dsp->dev);
        if (ret != 0) {
                adsp_dbg(dsp, "Failed to request '%s'\n", *filename);
                kfree(*filename);
@@ -775,11 +792,11 @@ static int wm_adsp_request_firmware_file(struct wm_adsp *dsp,
 }
 
 static const char * const cirrus_dir = "cirrus/";
-static 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)
+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)
 {
        const char *system_name = dsp->system_name;
        const char *suffix = dsp->component->name_prefix;
@@ -856,6 +873,7 @@ static int wm_adsp_request_firmware_files(struct wm_adsp *dsp,
 
        return -ENOENT;
 }
+EXPORT_SYMBOL_IF_KUNIT(wm_adsp_request_firmware_files);
 
 static int wm_adsp_common_init(struct wm_adsp *dsp)
 {
index 8035fda71f8db45bc9df7cb552c161b26b1b3d75..7c667123758b51a728b1fa6f5b882a40a32fd8c3 100644 (file)
@@ -142,4 +142,19 @@ int wm_adsp_write_ctl(struct wm_adsp *dsp, const char *name,  int type,
 int wm_adsp_read_ctl(struct wm_adsp *dsp, const char *name,  int type,
                      unsigned int alg, void *buf, size_t len);
 
+#if IS_ENABLED(CONFIG_KUNIT)
+void wm_adsp_release_firmware_files(const struct firmware *wmfw_firmware,
+                                   char *wmfw_filename,
+                                   const struct firmware *coeff_firmware,
+                                   char *coeff_filename);
+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);
+#endif
+
 #endif