All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] ALSA: hda - Fix the return value if cb func is already registered
@ 2020-10-22  3:02 Hui Wang
  2020-10-22  6:19   ` Takashi Iwai
  0 siblings, 1 reply; 3+ messages in thread
From: Hui Wang @ 2020-10-22  3:02 UTC (permalink / raw)
  To: alsa-devel, tiwai, dan.carpenter, stable

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 <dan.carpenter@oracle.com>
Cc: <stable@vger.kernel.org>
Signed-off-by: Hui Wang <hui.wang@canonical.com>
---
 sound/pci/hda/hda_jack.c | 18 +++++++++++++-----
 1 file changed, 13 insertions(+), 5 deletions(-)

diff --git a/sound/pci/hda/hda_jack.c b/sound/pci/hda/hda_jack.c
index ded4813f8b54..588059428d8f 100644
--- a/sound/pci/hda/hda_jack.c
+++ b/sound/pci/hda/hda_jack.c
@@ -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);
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] ALSA: hda - Fix the return value if cb func is already registered
  2020-10-22  3:02 [PATCH] ALSA: hda - Fix the return value if cb func is already registered Hui Wang
@ 2020-10-22  6:19   ` Takashi Iwai
  0 siblings, 0 replies; 3+ messages in thread
From: Takashi Iwai @ 2020-10-22  6:19 UTC (permalink / raw)
  To: Hui Wang; +Cc: alsa-devel, dan.carpenter, stable

On Thu, 22 Oct 2020 05:02:21 +0200,
Hui Wang wrote:
> 
> 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 <dan.carpenter@oracle.com>
> Cc: <stable@vger.kernel.org>
> Signed-off-by: Hui Wang <hui.wang@canonical.com>

Thanks, applied.


Takashi

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] ALSA: hda - Fix the return value if cb func is already registered
@ 2020-10-22  6:19   ` Takashi Iwai
  0 siblings, 0 replies; 3+ messages in thread
From: Takashi Iwai @ 2020-10-22  6:19 UTC (permalink / raw)
  To: Hui Wang; +Cc: alsa-devel, stable, dan.carpenter

On Thu, 22 Oct 2020 05:02:21 +0200,
Hui Wang wrote:
> 
> 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 <dan.carpenter@oracle.com>
> Cc: <stable@vger.kernel.org>
> Signed-off-by: Hui Wang <hui.wang@canonical.com>

Thanks, applied.


Takashi

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2020-10-22  6:20 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-22  3:02 [PATCH] ALSA: hda - Fix the return value if cb func is already registered Hui Wang
2020-10-22  6:19 ` Takashi Iwai
2020-10-22  6:19   ` Takashi Iwai

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.