[linux-next:master 13696/16300] sound/soc/sof/topology.c:2647 snd_sof_load_topology() warn: 'fw' from request_firmware() not released on lines: 2647.

kernel test robot <[email protected]>
Newsgroups dev.linux.lists.oe-kbuild
Message-ID <[email protected]>
BCC: [email protected]
CC: [email protected]
TO: Takashi Iwai <[email protected]>
CC: Mark Brown <[email protected]>

Hi Takashi,

FYI, the error/warning was bisected to this commit, please ignore it if it's irrelevant.

tree:   https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git master
head:   6a746cd265aed59107ebdaa9ce039bb832922969
commit: 6d0a9e4df17979ef8acbf8d7d6145fb1375e45cd [13696/16300] ASoC: SOF: Use auto-cleanup for firmware loading
:::::: branch date: 9 hours ago
:::::: commit date: 9 days ago
config: x86_64-randconfig-161-20260820 (https://download.01.org/0day-ci/archive/20260820/[email protected]/config)
compiler: gcc-14 (Debian 14.2.0-19) 14.2.0
smatch: v0.5.0-9187-g5189e3fb

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Fixes: 6d0a9e4df179 ("ASoC: SOF: Use auto-cleanup for firmware loading")
| Reported-by: kernel test robot <[email protected]>
| Reported-by: Dan Carpenter <[email protected]>
| Closes: https://lore.kernel.org/r/[email protected]/

New smatch warnings:
sound/soc/sof/topology.c:2647 snd_sof_load_topology() warn: 'fw' from request_firmware() not released on lines: 2647.
sound/soc/sof/topology.c:2647 snd_sof_load_topology() warn: 'fw' from request_firmware() not released on lines: 2647.

Old smatch warnings:
sound/soc/sof/topology.c:2133 sof_route_load() warn: missing error code 'ret'

vim +/fw +2647 sound/soc/sof/topology.c

28d40e7adfd410 Peter Ujfalusi     2023-04-04  2503  
ee1e79b72e3cf5 Ranjani Sridharan  2019-12-04  2504  int snd_sof_load_topology(struct snd_soc_component *scomp, const char *file)
311ce4fe7637d9 Liam Girdwood      2019-04-12  2505  {
9b014266ef8ad0 Jaroslav Kysela    2022-03-29  2506  	struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(scomp);
6d5997c412cc4b Bard Liao          2025-04-14  2507  	struct snd_sof_pdata *sof_pdata = sdev->pdata;
6d5997c412cc4b Bard Liao          2025-04-14  2508  	const char *tplg_filename_prefix = sof_pdata->tplg_filename_prefix;
6d5997c412cc4b Bard Liao          2025-04-14  2509  	int tplg_cnt = 0;
311ce4fe7637d9 Liam Girdwood      2019-04-12  2510  	int ret;
6d5997c412cc4b Bard Liao          2025-04-14  2511  	int i;
311ce4fe7637d9 Liam Girdwood      2019-04-12  2512  
6d0a9e4df17979 Takashi Iwai       2026-08-06  2513  	const char **tplg_files __free(kfree) =
6d0a9e4df17979 Takashi Iwai       2026-08-06  2514  		kcalloc(scomp->card->num_links, sizeof(char *), GFP_KERNEL);
6d5997c412cc4b Bard Liao          2025-04-14  2515  	if (!tplg_files)
6d5997c412cc4b Bard Liao          2025-04-14  2516  		return -ENOMEM;
6d5997c412cc4b Bard Liao          2025-04-14  2517  
c8f3c9fa75ff38 Peter Ujfalusi     2025-12-15  2518  	/* Try to use function topologies if possible */
7b400c9ab879a8 Bard Liao          2025-05-06  2519  	if (!sof_pdata->disable_function_topology && !disable_function_topology &&
7b400c9ab879a8 Bard Liao          2025-05-06  2520  	    sof_pdata->machine && sof_pdata->machine->get_function_tplg_files) {
c8f3c9fa75ff38 Peter Ujfalusi     2025-12-15  2521  		/*
c8f3c9fa75ff38 Peter Ujfalusi     2025-12-15  2522  		 * When the topology name contains 'dummy' word, it means that
c8f3c9fa75ff38 Peter Ujfalusi     2025-12-15  2523  		 * there is no fallback option to monolithic topology in case
c8f3c9fa75ff38 Peter Ujfalusi     2025-12-15  2524  		 * any of the function topologies might be missing.
c8f3c9fa75ff38 Peter Ujfalusi     2025-12-15  2525  		 * In this case we should use best effort to form the card,
c8f3c9fa75ff38 Peter Ujfalusi     2025-12-15  2526  		 * ignoring functionalities that we are missing a fragment for.
c8f3c9fa75ff38 Peter Ujfalusi     2025-12-15  2527  		 *
c8f3c9fa75ff38 Peter Ujfalusi     2025-12-15  2528  		 * Note: monolithic topologies also ignore these possibly
c8f3c9fa75ff38 Peter Ujfalusi     2025-12-15  2529  		 * missing functions, so the functionality of the card would be
c8f3c9fa75ff38 Peter Ujfalusi     2025-12-15  2530  		 * identical to the case if there would be a fallback monolithic
c8f3c9fa75ff38 Peter Ujfalusi     2025-12-15  2531  		 * topology created for the configuration.
c8f3c9fa75ff38 Peter Ujfalusi     2025-12-15  2532  		 */
c8f3c9fa75ff38 Peter Ujfalusi     2025-12-15  2533  		bool no_fallback = strstr(file, "dummy");
c8f3c9fa75ff38 Peter Ujfalusi     2025-12-15  2534  
6d5997c412cc4b Bard Liao          2025-04-14  2535  		tplg_cnt = sof_pdata->machine->get_function_tplg_files(scomp->card,
6d5997c412cc4b Bard Liao          2025-04-14  2536  								       sof_pdata->machine,
6d5997c412cc4b Bard Liao          2025-04-14  2537  								       tplg_filename_prefix,
c8f3c9fa75ff38 Peter Ujfalusi     2025-12-15  2538  								       &tplg_files,
c8f3c9fa75ff38 Peter Ujfalusi     2025-12-15  2539  								       no_fallback);
6d0a9e4df17979 Takashi Iwai       2026-08-06  2540  		if (tplg_cnt < 0)
6d5997c412cc4b Bard Liao          2025-04-14  2541  			return tplg_cnt;
6d5997c412cc4b Bard Liao          2025-04-14  2542  	}
6d5997c412cc4b Bard Liao          2025-04-14  2543  
6d5997c412cc4b Bard Liao          2025-04-14  2544  	/*
6d5997c412cc4b Bard Liao          2025-04-14  2545  	 * The monolithic topology will be used if there is no get_function_tplg_files
6d5997c412cc4b Bard Liao          2025-04-14  2546  	 * callback or the callback returns 0.
6d5997c412cc4b Bard Liao          2025-04-14  2547  	 */
6d5997c412cc4b Bard Liao          2025-04-14  2548  	if (!tplg_cnt) {
99c159279c6dfa Bard Liao          2025-10-09  2549  		if (strstr(file, "dummy")) {
99c159279c6dfa Bard Liao          2025-10-09  2550  			dev_err(scomp->dev,
99c159279c6dfa Bard Liao          2025-10-09  2551  				"Function topology is required, please upgrade sof-firmware\n");
99c159279c6dfa Bard Liao          2025-10-09  2552  			return -EINVAL;
99c159279c6dfa Bard Liao          2025-10-09  2553  		}
6d5997c412cc4b Bard Liao          2025-04-14  2554  		tplg_files[0] = file;
6d5997c412cc4b Bard Liao          2025-04-14  2555  		tplg_cnt = 1;
2b92b98cc4765f Bard Liao          2025-10-09  2556  		dev_info(scomp->dev, "loading topology: %s\n", file);
6d5997c412cc4b Bard Liao          2025-04-14  2557  	} else {
6d5997c412cc4b Bard Liao          2025-04-14  2558  		dev_info(scomp->dev, "Using function topologies instead %s\n", file);
6d5997c412cc4b Bard Liao          2025-04-14  2559  	}
6d5997c412cc4b Bard Liao          2025-04-14  2560  
6d5997c412cc4b Bard Liao          2025-04-14  2561  	for (i = 0; i < tplg_cnt; i++) {
6d5997c412cc4b Bard Liao          2025-04-14  2562  		/* Only print the file names if the function topologies are used */
6d5997c412cc4b Bard Liao          2025-04-14  2563  		if (tplg_files[0] != file)
6d5997c412cc4b Bard Liao          2025-04-14  2564  			dev_info(scomp->dev, "loading topology %d: %s\n", i, tplg_files[i]);
311ce4fe7637d9 Liam Girdwood      2019-04-12  2565  
6d0a9e4df17979 Takashi Iwai       2026-08-06  2566  		const struct firmware *fw __free(firmware) = NULL;
6d5997c412cc4b Bard Liao          2025-04-14  2567  		ret = request_firmware(&fw, tplg_files[i], scomp->dev);
311ce4fe7637d9 Liam Girdwood      2019-04-12  2568  		if (ret < 0) {
6d5997c412cc4b Bard Liao          2025-04-14  2569  			/*
6d5997c412cc4b Bard Liao          2025-04-14  2570  			 * snd_soc_tplg_component_remove(scomp) will be called
6d5997c412cc4b Bard Liao          2025-04-14  2571  			 * if snd_soc_tplg_component_load(scomp) failed and all
6d5997c412cc4b Bard Liao          2025-04-14  2572  			 * objects in the scomp will be removed. No need to call
6d5997c412cc4b Bard Liao          2025-04-14  2573  			 * snd_soc_tplg_component_remove(scomp) here.
6d5997c412cc4b Bard Liao          2025-04-14  2574  			 */
6d5997c412cc4b Bard Liao          2025-04-14  2575  			dev_err(scomp->dev, "tplg request firmware %s failed err: %d\n",
6d5997c412cc4b Bard Liao          2025-04-14  2576  				tplg_files[i], ret);
6d5997c412cc4b Bard Liao          2025-04-14  2577  			goto out;
311ce4fe7637d9 Liam Girdwood      2019-04-12  2578  		}
311ce4fe7637d9 Liam Girdwood      2019-04-12  2579  
28d40e7adfd410 Peter Ujfalusi     2023-04-04  2580  		if (sdev->dspless_mode_selected)
28d40e7adfd410 Peter Ujfalusi     2023-04-04  2581  			ret = snd_soc_tplg_component_load(scomp, &sof_dspless_tplg_ops, fw);
28d40e7adfd410 Peter Ujfalusi     2023-04-04  2582  		else
a5b8f71c5477f4 Amadeusz Sławiński 2020-10-30  2583  			ret = snd_soc_tplg_component_load(scomp, &sof_tplg_ops, fw);
28d40e7adfd410 Peter Ujfalusi     2023-04-04  2584  
6d5997c412cc4b Bard Liao          2025-04-14  2585  		if (ret < 0) {
6d5997c412cc4b Bard Liao          2025-04-14  2586  			dev_err(scomp->dev, "tplg %s component load failed %d\n",
6d5997c412cc4b Bard Liao          2025-04-14  2587  				tplg_files[i], ret);
6d5997c412cc4b Bard Liao          2025-04-14  2588  			goto out;
6d5997c412cc4b Bard Liao          2025-04-14  2589  		}
6d5997c412cc4b Bard Liao          2025-04-14  2590  	}
6d5997c412cc4b Bard Liao          2025-04-14  2591  
d82bf6af621301 Bard Liao          2026-04-21  2592  	/* Loading user defined topologies */
d82bf6af621301 Bard Liao          2026-04-21  2593  	for (i = 0; i < feature_tplg_cnt; i++) {
d82bf6af621301 Bard Liao          2026-04-21  2594  		const char *feature_topology = devm_kasprintf(scomp->dev, GFP_KERNEL, "%s/%s",
d82bf6af621301 Bard Liao          2026-04-21  2595  							   tplg_filename_prefix,
d82bf6af621301 Bard Liao          2026-04-21  2596  							   feature_topologies[i]);
d82bf6af621301 Bard Liao          2026-04-21  2597  
d82bf6af621301 Bard Liao          2026-04-21  2598  		if (!feature_topology) {
d82bf6af621301 Bard Liao          2026-04-21  2599  			ret = -ENOMEM;
d82bf6af621301 Bard Liao          2026-04-21  2600  			goto out;
d82bf6af621301 Bard Liao          2026-04-21  2601  		}
d82bf6af621301 Bard Liao          2026-04-21  2602  		dev_info(scomp->dev, "loading feature topology %d: %s\n", i, feature_topology);
6d0a9e4df17979 Takashi Iwai       2026-08-06  2603  
6d0a9e4df17979 Takashi Iwai       2026-08-06  2604  		const struct firmware *fw __free(firmware) = NULL;
d82bf6af621301 Bard Liao          2026-04-21  2605  		ret = request_firmware(&fw, feature_topology, scomp->dev);
d82bf6af621301 Bard Liao          2026-04-21  2606  		if (ret < 0) {
d82bf6af621301 Bard Liao          2026-04-21  2607  			/*
d82bf6af621301 Bard Liao          2026-04-21  2608  			 * snd_soc_tplg_component_remove(scomp) will be called
d82bf6af621301 Bard Liao          2026-04-21  2609  			 * if snd_soc_tplg_component_load(scomp) failed and all
d82bf6af621301 Bard Liao          2026-04-21  2610  			 * objects in the scomp will be removed. No need to call
d82bf6af621301 Bard Liao          2026-04-21  2611  			 * snd_soc_tplg_component_remove(scomp) here.
d82bf6af621301 Bard Liao          2026-04-21  2612  			 */
d82bf6af621301 Bard Liao          2026-04-21  2613  			dev_warn(scomp->dev, "feature tplg request firmware %s failed err: %d\n",
d82bf6af621301 Bard Liao          2026-04-21  2614  				 feature_topologies[i], ret);
d82bf6af621301 Bard Liao          2026-04-21  2615  			/*
d82bf6af621301 Bard Liao          2026-04-21  2616  			 * We don't return error here because we can still have the basic
d82bf6af621301 Bard Liao          2026-04-21  2617  			 * audio feature when the function topology load complete. No need
d82bf6af621301 Bard Liao          2026-04-21  2618  			 * to convert the error code because we will get new 'ret' out of the
d82bf6af621301 Bard Liao          2026-04-21  2619  			 * loop.
d82bf6af621301 Bard Liao          2026-04-21  2620  			 */
d82bf6af621301 Bard Liao          2026-04-21  2621  			continue;
d82bf6af621301 Bard Liao          2026-04-21  2622  		}
d82bf6af621301 Bard Liao          2026-04-21  2623  
d82bf6af621301 Bard Liao          2026-04-21  2624  		if (sdev->dspless_mode_selected)
d82bf6af621301 Bard Liao          2026-04-21  2625  			ret = snd_soc_tplg_component_load(scomp, &sof_dspless_tplg_ops, fw);
d82bf6af621301 Bard Liao          2026-04-21  2626  		else
d82bf6af621301 Bard Liao          2026-04-21  2627  			ret = snd_soc_tplg_component_load(scomp, &sof_tplg_ops, fw);
d82bf6af621301 Bard Liao          2026-04-21  2628  
d82bf6af621301 Bard Liao          2026-04-21  2629  		if (ret < 0) {
d82bf6af621301 Bard Liao          2026-04-21  2630  			dev_err(scomp->dev, "feature tplg %s component load failed %d\n",
d82bf6af621301 Bard Liao          2026-04-21  2631  				feature_topologies[i], ret);
d82bf6af621301 Bard Liao          2026-04-21  2632  			/*
d82bf6af621301 Bard Liao          2026-04-21  2633  			 * We need to return error here because it may lead to kernel NULL pointer
d82bf6af621301 Bard Liao          2026-04-21  2634  			 * dereference if we continue the remaining tasks.
d82bf6af621301 Bard Liao          2026-04-21  2635  			 */
d82bf6af621301 Bard Liao          2026-04-21  2636  			goto out;
d82bf6af621301 Bard Liao          2026-04-21  2637  		}
d82bf6af621301 Bard Liao          2026-04-21  2638  	}
d82bf6af621301 Bard Liao          2026-04-21  2639  
6d5997c412cc4b Bard Liao          2025-04-14  2640  	/* call sof_complete when topologies are loaded successfully */
6d5997c412cc4b Bard Liao          2025-04-14  2641  	ret = sof_complete(scomp);
6d5997c412cc4b Bard Liao          2025-04-14  2642  
6d5997c412cc4b Bard Liao          2025-04-14  2643  out:
9b014266ef8ad0 Jaroslav Kysela    2022-03-29  2644  	if (ret >= 0 && sdev->led_present)
9b014266ef8ad0 Jaroslav Kysela    2022-03-29  2645  		ret = snd_ctl_led_request();
9b014266ef8ad0 Jaroslav Kysela    2022-03-29  2646  
311ce4fe7637d9 Liam Girdwood      2019-04-12 @2647  	return ret;

:::::: The code at line 2647 was first introduced by commit
:::::: 311ce4fe7637d96608b6e57bf9ebbd8aabcf429e ASoC: SOF: Add support for loading topologies

:::::: TO: Liam Girdwood <[email protected]>
:::::: CC: Mark Brown <[email protected]>

--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.