Skip to content

Commit f8f0c68

Browse files
rfvirgilbroonie
authored andcommitted
ASoC: wm_adsp: Use consistent error checks in wm_adsp_request_firmware_files()
Use a consistent pattern of error checking in wm_adsp_request_firmware_files(). - The integer return value of wm_adsp_request_firmware_file() reports unrecoverable errors, for example -ENOMEM. - A NULL struct firmware pointer is a valid result. This not an error, not all DSPs require both files, some may not require any files. Previously wm_adsp_request_firmware_files() was using a mix of checking the return value and checking the struct firmware pointer to determine whether a file was found. It wasn't checking for unrecoverable errors. Signed-off-by: Richard Fitzgerald <rf@opensource.cirrus.com> Link: https://patch.msgid.link/20260310141817.1871794-7-rf@opensource.cirrus.com Signed-off-by: Mark Brown <broonie@kernel.org>
1 parent 2c7c270 commit f8f0c68

1 file changed

Lines changed: 65 additions & 27 deletions

File tree

sound/soc/codecs/wm_adsp.c

Lines changed: 65 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -753,7 +753,7 @@ static int wm_adsp_request_firmware_file(struct wm_adsp *dsp,
753753
struct cs_dsp *cs_dsp = &dsp->cs_dsp;
754754
const char *fwf;
755755
char *s, c;
756-
int ret = 0;
756+
int ret;
757757

758758
if (dsp->fwf_name)
759759
fwf = dsp->fwf_name;
@@ -791,15 +791,17 @@ static int wm_adsp_request_firmware_file(struct wm_adsp *dsp,
791791
}
792792

793793
ret = wm_adsp_firmware_request(firmware, *filename, cs_dsp->dev);
794-
if (ret != 0) {
795-
adsp_dbg(dsp, "Failed to request '%s'\n", *filename);
794+
if (ret < 0) {
795+
adsp_dbg(dsp, "Failed to request '%s': %d\n", *filename, ret);
796796
kfree(*filename);
797797
*filename = NULL;
798+
if (ret != -ENOENT)
799+
return ret;
798800
} else {
799801
adsp_dbg(dsp, "Found '%s'\n", *filename);
800802
}
801803

802-
return ret;
804+
return 0;
803805
}
804806

805807
static const char * const cirrus_dir = "cirrus/";
@@ -817,12 +819,19 @@ VISIBLE_IF_KUNIT int wm_adsp_request_firmware_files(struct wm_adsp *dsp,
817819
suffix = dsp->fwf_suffix;
818820

819821
if (system_name && suffix) {
820-
if (!wm_adsp_request_firmware_file(dsp, wmfw_firmware, wmfw_filename,
821-
cirrus_dir, system_name,
822-
suffix, "wmfw")) {
823-
wm_adsp_request_firmware_file(dsp, coeff_firmware, coeff_filename,
824-
cirrus_dir, system_name,
825-
suffix, "bin");
822+
ret = wm_adsp_request_firmware_file(dsp, wmfw_firmware, wmfw_filename,
823+
cirrus_dir, system_name,
824+
suffix, "wmfw");
825+
if (ret < 0)
826+
goto err;
827+
828+
if (*wmfw_firmware) {
829+
ret = wm_adsp_request_firmware_file(dsp, coeff_firmware, coeff_filename,
830+
cirrus_dir, system_name,
831+
suffix, "bin");
832+
if (ret < 0)
833+
goto err;
834+
826835
return 0;
827836
}
828837
}
@@ -831,36 +840,60 @@ VISIBLE_IF_KUNIT int wm_adsp_request_firmware_files(struct wm_adsp *dsp,
831840
ret = wm_adsp_request_firmware_file(dsp, wmfw_firmware, wmfw_filename,
832841
cirrus_dir, system_name,
833842
NULL, "wmfw");
834-
if (!ret || dsp->wmfw_optional) {
835-
if (suffix)
836-
wm_adsp_request_firmware_file(dsp, coeff_firmware, coeff_filename,
837-
cirrus_dir, system_name,
838-
suffix, "bin");
843+
if (ret < 0)
844+
goto err;
845+
846+
if (*wmfw_firmware || dsp->wmfw_optional) {
847+
if (suffix) {
848+
ret = wm_adsp_request_firmware_file(dsp,
849+
coeff_firmware, coeff_filename,
850+
cirrus_dir, system_name,
851+
suffix, "bin");
852+
if (ret < 0)
853+
goto err;
854+
}
839855

840-
if (!*coeff_firmware)
841-
wm_adsp_request_firmware_file(dsp, coeff_firmware, coeff_filename,
842-
cirrus_dir, system_name,
843-
NULL, "bin");
856+
if (!*coeff_firmware) {
857+
ret = wm_adsp_request_firmware_file(dsp,
858+
coeff_firmware, coeff_filename,
859+
cirrus_dir, system_name,
860+
NULL, "bin");
861+
if (ret < 0)
862+
goto err;
863+
}
844864

845865
if (*wmfw_firmware || (dsp->wmfw_optional && *coeff_firmware))
846866
return 0;
847867
}
848868
}
849869

850870
/* Check legacy location */
851-
if (!wm_adsp_request_firmware_file(dsp, wmfw_firmware, wmfw_filename,
852-
"", NULL, NULL, "wmfw")) {
853-
wm_adsp_request_firmware_file(dsp, coeff_firmware, coeff_filename,
854-
"", NULL, NULL, "bin");
871+
ret = wm_adsp_request_firmware_file(dsp, wmfw_firmware, wmfw_filename,
872+
"", NULL, NULL, "wmfw");
873+
if (ret < 0)
874+
goto err;
875+
876+
if (*wmfw_firmware) {
877+
ret = wm_adsp_request_firmware_file(dsp, coeff_firmware, coeff_filename,
878+
"", NULL, NULL, "bin");
879+
if (ret < 0)
880+
goto err;
881+
855882
return 0;
856883
}
857884

858885
/* Fall back to generic wmfw and optional matching bin */
859886
ret = wm_adsp_request_firmware_file(dsp, wmfw_firmware, wmfw_filename,
860887
cirrus_dir, NULL, NULL, "wmfw");
861-
if (!ret || dsp->wmfw_optional) {
862-
wm_adsp_request_firmware_file(dsp, coeff_firmware, coeff_filename,
863-
cirrus_dir, NULL, NULL, "bin");
888+
if (ret < 0)
889+
goto err;
890+
891+
if (*wmfw_firmware || dsp->wmfw_optional) {
892+
ret = wm_adsp_request_firmware_file(dsp, coeff_firmware, coeff_filename,
893+
cirrus_dir, NULL, NULL, "bin");
894+
if (ret < 0)
895+
goto err;
896+
864897
return 0;
865898
}
866899

@@ -869,7 +902,12 @@ VISIBLE_IF_KUNIT int wm_adsp_request_firmware_files(struct wm_adsp *dsp,
869902
dsp->fwf_name ? dsp->fwf_name : dsp->cs_dsp.name,
870903
wm_adsp_fw[dsp->fw].file, system_name, suffix);
871904

872-
return -ENOENT;
905+
ret = -ENOENT;
906+
err:
907+
wm_adsp_release_firmware_files(*wmfw_firmware, *wmfw_filename,
908+
*coeff_firmware, *coeff_filename);
909+
910+
return ret;
873911
}
874912
EXPORT_SYMBOL_IF_KUNIT(wm_adsp_request_firmware_files);
875913

0 commit comments

Comments
 (0)