sound/soc/soc-dapm.c:2893 snd_soc_dapm_free_widget() warn: variable dereferenced before check 'w->dapm' (see line 2891)
kernel test robot
build botUnfiltered warning: this smatch report is sent as-is and has not been reviewed for false positives, so please treat it with due skepticism.
BCC: [email protected]
CC: [email protected]
TO: "Amadeusz Sławiński" <[email protected]>
CC: Mark Brown <[email protected]>
tree: https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git for-7.4 head: ba982c33278c1fc739c8c220f410d6539de9d9b9 commit: 568406bc832e7e9e333e2ab05aafd0b83ffb9610 [37/72] ASoC: soc-dapm: Remove widget from cache on removal
:::::: branch date: 2 days ago
:::::: commit date: 2 days ago
config: nios2-randconfig-r2202-20261017 (https://download.01.org/0day-ci/archive/20261018/[email protected]/config)
compiler: nios2-linux-gcc (GCC) 11.5.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
| Reported-by: kernel test robot <[email protected]> | Reported-by: Dan Carpenter <[email protected]> | Closes: https://lore.kernel.org/r/[email protected]/
smatch warnings:sound/soc/soc-dapm.c:2893 snd_soc_dapm_free_widget() warn: variable dereferenced before check 'w->dapm' (see line 2891)
vim +2893 sound/soc/soc-dapm.c
8872293fc38c49 Lars-Peter Clausen 2013-06-14 2863
da0398099a8348 Cezary Rojewski 2022-03-11 2864 /**
da0398099a8348 Cezary Rojewski 2022-03-11 2865 * snd_soc_dapm_free_widget - Free specified widget
da0398099a8348 Cezary Rojewski 2022-03-11 2866 * @w: widget to free
da0398099a8348 Cezary Rojewski 2022-03-11 2867 *
da0398099a8348 Cezary Rojewski 2022-03-11 2868 * Removes widget from all paths and frees memory occupied by it.
da0398099a8348 Cezary Rojewski 2022-03-11 2869 */
b97e26980f6c13 Lars-Peter Clausen 2015-07-21 2870 void snd_soc_dapm_free_widget(struct snd_soc_dapm_widget *w)
2b97eabc09f42d Richard Purdie 2006-10-06 2871 {
568406bc832e7e Amadeusz Sławiński 2026-10-14 2872 struct snd_soc_dapm_context *d;
2b97eabc09f42d Richard Purdie 2006-10-06 2873 struct snd_soc_dapm_path *p, *next_p;
a3423b02cf745c Lars-Peter Clausen 2015-08-11 2874 enum snd_soc_dapm_direction dir;
2b97eabc09f42d Richard Purdie 2006-10-06 2875
1c9096f32ad23f Kuninori Morimoto 2022-10-17 2876 if (!w)
1c9096f32ad23f Kuninori Morimoto 2022-10-17 2877 return;
1c9096f32ad23f Kuninori Morimoto 2022-10-17 2878
2b97eabc09f42d Richard Purdie 2006-10-06 2879 list_del(&w->list);
5c6679b5cb120f Thomas Hebb 2020-12-12 2880 list_del(&w->dirty);
8ddab3f5107c39 Jarkko Nikula 2010-12-14 2881 /*
8ddab3f5107c39 Jarkko Nikula 2010-12-14 2882 * remove source and sink paths associated to this widget.
8ddab3f5107c39 Jarkko Nikula 2010-12-14 2883 * While removing the path, remove reference to it from both
8ddab3f5107c39 Jarkko Nikula 2010-12-14 2884 * source and sink widgets so that path is removed only once.
8ddab3f5107c39 Jarkko Nikula 2010-12-14 2885 */
af6d53db28e644 Kuninori Morimoto 2026-01-20 2886 dapm_for_each_direction(dir) {
a3423b02cf745c Lars-Peter Clausen 2015-08-11 2887 snd_soc_dapm_widget_for_each_path_safe(w, dir, p, next_p)
8872293fc38c49 Lars-Peter Clausen 2013-06-14 2888 dapm_free_path(p);
a3423b02cf745c Lars-Peter Clausen 2015-08-11 2889 }
8872293fc38c49 Lars-Peter Clausen 2013-06-14 2890
8ad13cdc92f663 Trevor Wu 2023-05-26 @2891 dapm_debugfs_free_widget(w);
8ad13cdc92f663 Trevor Wu 2023-05-26 2892
568406bc832e7e Amadeusz Sławiński 2026-10-14 @2893 if (w->dapm) {
568406bc832e7e Amadeusz Sławiński 2026-10-14 2894 if (w->dapm->card) {
568406bc832e7e Amadeusz Sławiński 2026-10-14 2895 for_each_card_dapms(w->dapm->card, d) {
568406bc832e7e Amadeusz Sławiński 2026-10-14 2896 if (d->wcache_sink == w)
568406bc832e7e Amadeusz Sławiński 2026-10-14 2897 d->wcache_sink = NULL;
568406bc832e7e Amadeusz Sławiński 2026-10-14 2898 if (d->wcache_source == w)
568406bc832e7e Amadeusz Sławiński 2026-10-14 2899 d->wcache_source = NULL;
568406bc832e7e Amadeusz Sławiński 2026-10-14 2900 }
568406bc832e7e Amadeusz Sławiński 2026-10-14 2901 } else {
568406bc832e7e Amadeusz Sławiński 2026-10-14 2902 if (w->dapm->wcache_sink == w)
568406bc832e7e Amadeusz Sławiński 2026-10-14 2903 w->dapm->wcache_sink = NULL;
568406bc832e7e Amadeusz Sławiński 2026-10-14 2904 if (w->dapm->wcache_source == w)
568406bc832e7e Amadeusz Sławiński 2026-10-14 2905 w->dapm->wcache_source = NULL;
568406bc832e7e Amadeusz Sławiński 2026-10-14 2906 }
568406bc832e7e Amadeusz Sławiński 2026-10-14 2907 }
568406bc832e7e Amadeusz Sławiński 2026-10-14 2908
fad598887dc0d8 Stephen Warren 2011-04-28 2909 kfree(w->kcontrols);
48068961751038 Lars-Peter Clausen 2015-07-21 2910 kfree_const(w->name);
199ed3e81c49a6 Pierre-Louis Bossart 2019-02-01 2911 kfree_const(w->sname);
8ddab3f5107c39 Jarkko Nikula 2010-12-14 2912 kfree(w);
8ddab3f5107c39 Jarkko Nikula 2010-12-14 2913 }
da0398099a8348 Cezary Rojewski 2022-03-11 2914 EXPORT_SYMBOL_GPL(snd_soc_dapm_free_widget);
b97e26980f6c13 Lars-Peter Clausen 2015-07-21 2915 --
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki