linux/sound/soc
Douglas Anderson a93d2afd3f
ASoC: mediatek: mt8186: Fix use-after-free in driver remove path
When devm runs function in the "remove" path for a device it runs them
in the reverse order. That means that if you have parts of your driver
that aren't using devm or are using "roll your own" devm w/
devm_add_action_or_reset() you need to keep that in mind.

The mt8186 audio driver didn't quite get this right. Specifically, in
mt8186_init_clock() it called mt8186_audsys_clk_register() and then
went on to call a bunch of other devm function. The caller of
mt8186_init_clock() used devm_add_action_or_reset() to call
mt8186_deinit_clock() but, because of the intervening devm functions,
the order was wrong.

Specifically at probe time, the order was:
1. mt8186_audsys_clk_register()
2. afe_priv->clk = devm_kcalloc(...)
3. afe_priv->clk[i] = devm_clk_get(...)

At remove time, the order (which should have been 3, 2, 1) was:
1. mt8186_audsys_clk_unregister()
3. Free all of afe_priv->clk[i]
2. Free afe_priv->clk

The above seemed to be causing a use-after-free. Luckily, it's easy to
fix this by simply using devm more correctly. Let's move the
devm_add_action_or_reset() to the right place. In addition to fixing
the use-after-free, code inspection shows that this fixes a leak
(missing call to mt8186_audsys_clk_unregister()) that would have
happened if any of the syscon_regmap_lookup_by_phandle() calls in
mt8186_init_clock() had failed.

Fixes: 55b423d562 ("ASoC: mediatek: mt8186: support audio clock control in platform driver")
Signed-off-by: Douglas Anderson <dianders@chromium.org
Link: https://lore.kernel.org/r/20230511092437.1.I31cceffc8c45bb1af16eb613e197b3df92cdc19e@changeid
Signed-off-by: Mark Brown <broonie@kernel.org
2023-05-15 10:21:13 +09:00
..
adi ASoC: adi: axi-spdif: Convert to platform remove callback returning void 2023-03-20 13:07:10 +00:00
amd ASoC: amd: yc: Add DMI entry to support System76 Pangolin 12 2023-05-08 09:07:42 +09:00
apple ASoC: apple: mca: Convert to platform remove callback returning void 2023-03-20 13:07:18 +00:00
atmel ASoC: atmel: remove unnecessary dai_link->platform 2023-03-24 12:15:18 +00:00
au1x ASoC: au1x: psc-i2s: Convert to platform remove callback returning void 2023-03-20 13:07:31 +00:00
bcm ASoC: bcm: cygnus-ssp: Convert to platform remove callback returning void 2023-03-20 13:07:33 +00:00
cirrus ASoC: ep93xx: Add OF support 2023-04-12 12:54:23 +01:00
codecs ASoC: ssm2602: Add workaround for playback distortions 2023-05-12 10:26:47 +09:00
dwc ASoC: dwc: limit the number of overrun messages 2023-05-08 09:07:43 +09:00
fsl ASoC: fsl_micfil: Fix error handler with pm_runtime_enable 2023-05-08 22:35:10 +09:00
generic ASoC: audio-graph-card2: switch to use c2c_params instead of params 2023-04-05 12:16:37 +01:00
hisilicon
img ASoC: img: pistachio-internal-dac: Convert to platform remove callback returning void 2023-03-20 13:08:22 +00:00
intel ASoC: Intel: soc-acpi-cht: Add quirk for Nextbook Ares 8A tablet 2023-05-04 10:14:31 +09:00
jz4740 ASoC: jz4740-i2s: Make I2S divider calculations more robust 2023-05-11 10:17:58 +09:00
kirkwood ASoC: kirkwood: kirkwood-i2s: Convert to platform remove callback returning void 2023-03-20 13:08:35 +00:00
mediatek ASoC: mediatek: mt8186: Fix use-after-free in driver remove path 2023-05-15 10:21:13 +09:00
meson ASoC: meson: switch to use c2c_params instead of params 2023-04-05 12:16:37 +01:00
mxs ASoC: mxs: mxs-sgtl5000: Convert to platform remove callback returning void 2023-03-20 13:08:44 +00:00
pxa ASoC: pxa: pxa2xx-ac97: Convert to platform remove callback returning void 2023-03-20 13:08:46 +00:00
qcom ASoC: qcom: sdw: do not restart soundwire ports for every prepare 2023-04-06 14:45:12 +01:00
rockchip ALSA/ASoC: Convert to platform remove callback 2023-03-21 16:29:48 +00:00
samsung ASoC: samsung: switch to use c2c_params instead of params 2023-04-05 12:16:38 +01:00
sh ASoC: sh: siu_dai: Convert to platform remove callback returning void 2023-03-20 13:09:01 +00:00
sof ASoC: SOF: ipc3-topology: Make sure that only one cmd is sent in dai_config 2023-05-15 10:21:12 +09:00
spear ASoC: spear: use helper function 2023-01-31 11:04:59 +00:00
sprd ASoC: sprd: sprd-mcdt: Convert to platform remove callback returning void 2023-03-20 13:09:02 +00:00
sti
stm ASoC: stm: stm32_spdifrx: Convert to platform remove callback returning void 2023-03-20 13:09:05 +00:00
sunxi ASoC: sunxi: sun8i-codec: Convert to platform remove callback returning void 2023-03-20 13:09:10 +00:00
tegra ASoC: tegra20_ac97: Add missing unwind goto in tegra20_ac97_platform_probe() 2023-04-04 12:46:42 +01:00
ti ASoC: ti: remove unnecessary dai_link->platform 2023-03-24 12:15:19 +00:00
uniphier ASoC: uniphier: evea: Convert to platform remove callback returning void 2023-03-20 13:09:31 +00:00
ux500 ASoC: ux500: ux500_msp_dai: Convert to platform remove callback returning void 2023-03-20 13:09:32 +00:00
xilinx ASoC: xilinx: xlnx_spdif: Convert to platform remove callback returning void 2023-03-20 13:09:34 +00:00
xtensa ASoC: xtensa: xtfpga-i2s: Convert to platform remove callback returning void 2023-03-20 13:09:35 +00:00
Kconfig
Makefile
soc-ac97.c ASoC: soc-ac97: Return correct error codes 2023-02-15 16:09:07 +00:00
soc-acpi.c
soc-card.c
soc-component.c ASoC: expand snd_soc_dpcm_mutex_lock/unlock() 2023-04-17 12:57:25 +01:00
soc-compress.c ASoC: add snd_soc_card_mutex_lock/unlock() 2023-04-17 12:57:26 +01:00
soc-core.c ASoC: add snd_soc_card_mutex_lock/unlock() 2023-04-17 12:57:26 +01:00
soc-dai.c ASoC: soc-dai.c: add missing flag check at snd_soc_pcm_dai_probe() 2023-03-14 13:58:56 +00:00
soc-dapm.c ASoC: expand snd_soc_dapm_mutex_lock/unlock() 2023-04-17 12:57:24 +01:00
soc-devres.c
soc-generic-dmaengine-pcm.c ASoC: soc.h: remove num_cpus/codecs 2022-09-20 12:19:30 +01:00
soc-jack.c ASoC: jack: allow multiple interrupt per gpio 2023-03-05 23:38:38 +00:00
soc-link.c
soc-ops.c ASoC: ops: Correct bounds check for second channel on SX controls 2022-11-25 16:29:33 +00:00
soc-pcm.c ASoC: expand snd_soc_dpcm_mutex_lock/unlock() 2023-04-17 12:57:25 +01:00
soc-topology-test.c
soc-topology.c ASoC: soc-topology.c: dai_link->platform again 2023-03-29 17:43:23 +01:00
soc-utils-test.c
soc-utils.c ASoC: soc-utils: Remove __exit for snd_soc_util_exit() 2022-11-07 13:37:04 +00:00