Skip to contentSkip to conversation

ALSA: hda - Fix the return value if cb func is already registered

PATCH Applied Hui Wang 2 participants 2 messages Oct 22, 2020

Subsystems (2)
lore
Share & tools
lore

Hui Wang

author
#0 lore raw

PATCH 1/1 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 f4794c6064a8 ("ALSA:hda - Don't register a cb func if it is registered already")
Reported-and-suggested-by Dan Carpenter <[email protected]>
---
 sound/pci/hda/hda_jack.c | 18 +++++++++++++-----
 1 file changed, 13 insertions(+), 5 deletions(-)
sound/pci/hda/hda_jack.c +13 -5
index ded4813f8b54..588059428d8f 100644
@@ -275,16 +275,21 @@ int snd_hda_jack_detect_state_mst(struct hda_codec *codec,
 }
 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)
+static struct hda_jack_callback *
+find_callback_from_list(struct hda_jack_tbl *jack,
+			hda_jack_callback_fn func)
 {
 	struct hda_jack_callback *cb;
 
+	if (!func)
+		return NULL;
+
 	for (cb = jack->callback; cb; cb = cb->next) {
 		if (cb->func == func)
-			return true;
+			return cb;
 	}
-	return false;
+
+	return NULL;
 }
 
 /**
@@ -309,7 +314,10 @@ 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);
 	if (!jack)
 		return ERR_PTR(-ENOMEM);
-	if (func && !func_is_already_in_callback_list(jack, func)) {
+
+	callback = find_callback_from_list(jack, func);
+
+	if (func && !callback) {
 		callback = kzalloc(sizeof(*callback), GFP_KERNEL);
 		if (!callback)
 			return ERR_PTR(-ENOMEM);
Signature · 1 line
2.25.1
Applied
#1 lore raw
Quoted 5 lines · Hui Wang

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.

Quoted 7 lines

Now fix it by replacing func_is_already_in_callback_list() with find_callback_from_list().

Fixes f4794c6064a8 ("ALSA:hda - Don't register a cb func if it is registered already")
Reported-and-suggested-by Dan Carpenter <[email protected]>

Thanks, applied.

Takashi