Skip to content

Commit 033e404

Browse files
jason77-wangtiwai
authored andcommitted
ALSA: hda - Fix the return value if cb func is already registered
If the cb function is already registered, should return the pointer of the structure hda_jack_callback which contains this cb func, but instead it returns the NULL. Now fix it by replacing func_is_already_in_callback_list() with find_callback_from_list(). Fixes: f4794c6 ("ALSA: hda - Don't register a cb func if it is registered already") Reported-and-suggested-by: Dan Carpenter <dan.carpenter@oracle.com> Cc: <stable@vger.kernel.org> Signed-off-by: Hui Wang <hui.wang@canonical.com> Link: https://lore.kernel.org/r/20201022030221.22393-1-hui.wang@canonical.com Signed-off-by: Takashi Iwai <tiwai@suse.de>
1 parent 7da4c51 commit 033e404

1 file changed

Lines changed: 13 additions & 5 deletions

File tree

sound/pci/hda/hda_jack.c

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -275,16 +275,21 @@ 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)
278+
static struct hda_jack_callback *
279+
find_callback_from_list(struct hda_jack_tbl *jack,
280+
hda_jack_callback_fn func)
280281
{
281282
struct hda_jack_callback *cb;
282283

284+
if (!func)
285+
return NULL;
286+
283287
for (cb = jack->callback; cb; cb = cb->next) {
284288
if (cb->func == func)
285-
return true;
289+
return cb;
286290
}
287-
return false;
291+
292+
return NULL;
288293
}
289294

290295
/**
@@ -309,7 +314,10 @@ snd_hda_jack_detect_enable_callback_mst(struct hda_codec *codec, hda_nid_t nid,
309314
jack = snd_hda_jack_tbl_new(codec, nid, dev_id);
310315
if (!jack)
311316
return ERR_PTR(-ENOMEM);
312-
if (func && !func_is_already_in_callback_list(jack, func)) {
317+
318+
callback = find_callback_from_list(jack, func);
319+
320+
if (func && !callback) {
313321
callback = kzalloc(sizeof(*callback), GFP_KERNEL);
314322
if (!callback)
315323
return ERR_PTR(-ENOMEM);

0 commit comments

Comments
 (0)