mirror of https://gitee.com/openkylin/linux.git
ALSA: hda - Don't register a cb func if it is registered already
If the caller of enable_callback_mst() passes a cb func, the callee function will malloc memory and link this cb func to the list unconditionally. This will introduce problem if caller is in the hda_codec_ops.init() since the init() will be repeatedly called in the codec rt_resume(). So far, the patch_hdmi.c and patch_ca0132.c call enable_callback_mst() in the hda_codec_ops.init(). Signed-off-by: Hui Wang <hui.wang@canonical.com> Cc: <stable@vger.kernel.org> Link: https://lore.kernel.org/r/20200930055146.5665-1-hui.wang@canonical.com Signed-off-by: Takashi Iwai <tiwai@suse.de>
This commit is contained in:
parent
13468bfa8c
commit
f4794c6064
|
@ -275,6 +275,18 @@ int snd_hda_jack_detect_state_mst(struct hda_codec *codec,
|
||||||
}
|
}
|
||||||
EXPORT_SYMBOL_GPL(snd_hda_jack_detect_state_mst);
|
EXPORT_SYMBOL_GPL(snd_hda_jack_detect_state_mst);
|
||||||
|
|
||||||
|
static bool func_is_already_in_callback_list(struct hda_jack_tbl *jack,
|
||||||
|
hda_jack_callback_fn func)
|
||||||
|
{
|
||||||
|
struct hda_jack_callback *cb;
|
||||||
|
|
||||||
|
for (cb = jack->callback; cb; cb = cb->next) {
|
||||||
|
if (cb->func == func)
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* snd_hda_jack_detect_enable_mst - enable the jack-detection
|
* snd_hda_jack_detect_enable_mst - enable the jack-detection
|
||||||
* @codec: the HDA codec
|
* @codec: the HDA codec
|
||||||
|
@ -297,7 +309,7 @@ snd_hda_jack_detect_enable_callback_mst(struct hda_codec *codec, hda_nid_t nid,
|
||||||
jack = snd_hda_jack_tbl_new(codec, nid, dev_id);
|
jack = snd_hda_jack_tbl_new(codec, nid, dev_id);
|
||||||
if (!jack)
|
if (!jack)
|
||||||
return ERR_PTR(-ENOMEM);
|
return ERR_PTR(-ENOMEM);
|
||||||
if (func) {
|
if (func && !func_is_already_in_callback_list(jack, func)) {
|
||||||
callback = kzalloc(sizeof(*callback), GFP_KERNEL);
|
callback = kzalloc(sizeof(*callback), GFP_KERNEL);
|
||||||
if (!callback)
|
if (!callback)
|
||||||
return ERR_PTR(-ENOMEM);
|
return ERR_PTR(-ENOMEM);
|
||||||
|
|
Loading…
Reference in New Issue