Commit e946455c authored by Takashi Iwai's avatar Takashi Iwai

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.deSigned-off-by: default avatarTakashi Iwai <tiwai@suse.de>
parent 6278056e
...@@ -604,6 +604,7 @@ static inline int snd_ctl_remove_locked(struct snd_card *card, ...@@ -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. * Removes the control from the card and then releases the instance.
* You don't need to call snd_ctl_free_one(). * 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. * 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, ...@@ -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) int snd_ctl_remove(struct snd_card *card, struct snd_kcontrol *kcontrol)
{ {
if (!kcontrol)
return 0;
guard(rwsem_write)(&card->controls_rwsem); guard(rwsem_write)(&card->controls_rwsem);
return snd_ctl_remove_locked(card, kcontrol); return snd_ctl_remove_locked(card, kcontrol);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment