a93d2afd3f
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
106 lines
2.5 KiB
C
106 lines
2.5 KiB
C
/* SPDX-License-Identifier: GPL-2.0
|
|
*
|
|
* mt8186-afe-clk.h -- Mediatek 8186 afe clock ctrl definition
|
|
*
|
|
* Copyright (c) 2022 MediaTek Inc.
|
|
* Author: Jiaxin Yu <jiaxin.yu@mediatek.com>
|
|
*/
|
|
|
|
#ifndef _MT8186_AFE_CLOCK_CTRL_H_
|
|
#define _MT8186_AFE_CLOCK_CTRL_H_
|
|
|
|
#define PERI_BUS_DCM_CTRL 0x74
|
|
|
|
/* APLL */
|
|
#define APLL1_W_NAME "APLL1"
|
|
#define APLL2_W_NAME "APLL2"
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M_SEL,
|
|
CLK_TOP_TDM_M_SEL,
|
|
CLK_TOP_APLL12_DIV0,
|
|
CLK_TOP_APLL12_DIV1,
|
|
CLK_TOP_APLL12_DIV2,
|
|
CLK_TOP_APLL12_DIV4,
|
|
CLK_TOP_APLL12_DIV_TDM,
|
|
CLK_CLK26M,
|
|
CLK_NUM
|
|
};
|
|
|
|
struct mtk_base_afe;
|
|
int mt8186_set_audio_int_bus_parent(struct mtk_base_afe *afe, int clk_id);
|
|
int mt8186_init_clock(struct mtk_base_afe *afe);
|
|
int mt8186_afe_enable_cgs(struct mtk_base_afe *afe);
|
|
void mt8186_afe_disable_cgs(struct mtk_base_afe *afe);
|
|
int mt8186_afe_enable_clock(struct mtk_base_afe *afe);
|
|
void mt8186_afe_disable_clock(struct mtk_base_afe *afe);
|
|
int mt8186_afe_suspend_clock(struct mtk_base_afe *afe);
|
|
int mt8186_afe_resume_clock(struct mtk_base_afe *afe);
|
|
|
|
int mt8186_apll1_enable(struct mtk_base_afe *afe);
|
|
void mt8186_apll1_disable(struct mtk_base_afe *afe);
|
|
|
|
int mt8186_apll2_enable(struct mtk_base_afe *afe);
|
|
void mt8186_apll2_disable(struct mtk_base_afe *afe);
|
|
|
|
int mt8186_get_apll_rate(struct mtk_base_afe *afe, int apll);
|
|
int mt8186_get_apll_by_rate(struct mtk_base_afe *afe, int rate);
|
|
int mt8186_get_apll_by_name(struct mtk_base_afe *afe, const char *name);
|
|
|
|
/* these will be replaced by using CCF */
|
|
int mt8186_mck_enable(struct mtk_base_afe *afe, int mck_id, int rate);
|
|
void mt8186_mck_disable(struct mtk_base_afe *afe, int mck_id);
|
|
|
|
#endif
|