Alsa-Devel Archive mirror
 help / color / mirror / Atom feed
From: Richard Fitzgerald <rf@opensource.cirrus.com>
To: <tiwai@suse.com>
Cc: <linux-kernel@vger.kernel.org>, <patches@opensource.cirrus.com>,
	<alsa-devel@alsa-project.org>, <linux-sound@vger.kernel.org>
Subject: [PATCH] ALSA: hda/cs_dsp_ctl: Actually remove ALSA controls
Date: Fri, 3 May 2024 15:49:20 +0100	[thread overview]
Message-ID: <20240503144920.61075-1-rf@opensource.cirrus.com> (raw)

hda_cs_dsp_control_remove() must remove the ALSA control when
deleting all the infrastructure for handling the control.

Without this it is possible for ALSA controls to be left in
the Soundcard after the amp driver module has been unloaded.
So the get/set callbacks point to code that no longer exists.

Signed-off-by: Richard Fitzgerald <rf@opensource.cirrus.com>
Fixes: 3233b978af23 ("ALSA: hda: hda_cs_dsp_ctl: Add Library to support CS_DSP ALSA controls")
---
Note: it would be better to use the control private_free to do the
cleanup, and that is my plan long-term. But that is a larger change
to the code.

I like to keep bugfix patches as simple as possible so they are
low-risk and easy to cherry-pick into older kernels. So this patch
fixes the bug. Sometime I will send a patch for future kernel
versions that reworks the cleanup to use private_free.
---
 sound/pci/hda/hda_cs_dsp_ctl.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/sound/pci/hda/hda_cs_dsp_ctl.c b/sound/pci/hda/hda_cs_dsp_ctl.c
index 463ca06036bf..a42653d3473d 100644
--- a/sound/pci/hda/hda_cs_dsp_ctl.c
+++ b/sound/pci/hda/hda_cs_dsp_ctl.c
@@ -203,6 +203,10 @@ void hda_cs_dsp_control_remove(struct cs_dsp_coeff_ctl *cs_ctl)
 {
 	struct hda_cs_dsp_coeff_ctl *ctl = cs_ctl->priv;
 
+	/* Only public firmware controls will have an associated kcontrol */
+	if (ctl && ctl->kctl)
+		snd_ctl_remove(ctl->card, ctl->kctl);
+
 	kfree(ctl);
 }
 EXPORT_SYMBOL_NS_GPL(hda_cs_dsp_control_remove, SND_HDA_CS_DSP_CONTROLS);
-- 
2.39.2


             reply	other threads:[~2024-05-03 14:50 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-03 14:49 Richard Fitzgerald [this message]
2024-05-03 15:17 ` [PATCH] ALSA: hda/cs_dsp_ctl: Actually remove ALSA controls Takashi Iwai
2024-05-03 15:31   ` Richard Fitzgerald
2024-05-03 16:16     ` Takashi Iwai

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240503144920.61075-1-rf@opensource.cirrus.com \
    --to=rf@opensource.cirrus.com \
    --cc=alsa-devel@alsa-project.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-sound@vger.kernel.org \
    --cc=patches@opensource.cirrus.com \
    --cc=tiwai@suse.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).