summaryrefslogtreecommitdiff
path: root/sound/core/control.c
diff options
context:
space:
mode:
authorTakashi Iwai <tiwai@suse.de>2024-06-17 13:05:23 +0300
committerTakashi Iwai <tiwai@suse.de>2024-06-18 13:51:35 +0300
commite946455ce116fd822718d6acd874f3f4cf306520 (patch)
tree92e593444c7d79a3426729e3a735e8efc9473a73 /sound/core/control.c
parent6278056e42d953e207e2afd416be39d09ed2d496 (diff)
downloadlinux-e946455ce116fd822718d6acd874f3f4cf306520.tar.xz
ALSA: control: Allow NULL passed to snd_ctl_remove()
There are lots of code checking NULL for kcontrol passed to snd_ctl_remove() in the caller side. Let's make snd_ctl_remove() accepting the NULL kcontrol instead a la free(), so that we can clean up the caller side. Link: https://lore.kernel.org/20240617100529.6667-2-tiwai@suse.de Signed-off-by: Takashi Iwai <tiwai@suse.de>
Diffstat (limited to 'sound/core/control.c')
-rw-r--r--sound/core/control.c3
1 files changed, 3 insertions, 0 deletions
diff --git a/sound/core/control.c b/sound/core/control.c
index 1dd2337e2930..f64a555f404f 100644
--- a/sound/core/control.c
+++ b/sound/core/control.c
@@ -604,6 +604,7 @@ static inline int snd_ctl_remove_locked(struct snd_card *card,
*
* Removes the control from the card and then releases the instance.
* You don't need to call snd_ctl_free_one().
+ * Passing NULL to @kcontrol argument is allowed as noop.
*
* Return: 0 if successful, or a negative error code on failure.
*
@@ -611,6 +612,8 @@ static inline int snd_ctl_remove_locked(struct snd_card *card,
*/
int snd_ctl_remove(struct snd_card *card, struct snd_kcontrol *kcontrol)
{
+ if (!kcontrol)
+ return 0;
guard(rwsem_write)(&card->controls_rwsem);
return snd_ctl_remove_locked(card, kcontrol);
}