Skip to content

Commit f4794c6

Browse files
jason77-wangtiwai
authored andcommitted
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 <[email protected]> Cc: <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Takashi Iwai <[email protected]>
1 parent 13468bf commit f4794c6

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

sound/pci/hda/hda_jack.c

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,18 @@ int snd_hda_jack_detect_state_mst(struct hda_codec *codec,
275275
}
276276
EXPORT_SYMBOL_GPL(snd_hda_jack_detect_state_mst);
277277

278+
static bool func_is_already_in_callback_list(struct hda_jack_tbl *jack,
279+
hda_jack_callback_fn func)
280+
{
281+
struct hda_jack_callback *cb;
282+
283+
for (cb = jack->callback; cb; cb = cb->next) {
284+
if (cb->func == func)
285+
return true;
286+
}
287+
return false;
288+
}
289+
278290
/**
279291
* snd_hda_jack_detect_enable_mst - enable the jack-detection
280292
* @codec: the HDA codec
@@ -297,7 +309,7 @@ snd_hda_jack_detect_enable_callback_mst(struct hda_codec *codec, hda_nid_t nid,
297309
jack = snd_hda_jack_tbl_new(codec, nid, dev_id);
298310
if (!jack)
299311
return ERR_PTR(-ENOMEM);
300-
if (func) {
312+
if (func && !func_is_already_in_callback_list(jack, func)) {
301313
callback = kzalloc(sizeof(*callback), GFP_KERNEL);
302314
if (!callback)
303315
return ERR_PTR(-ENOMEM);

0 commit comments

Comments
 (0)