Skip to content

Commit

Permalink
ALSA: control: Allow NULL passed to snd_ctl_remove()
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Takashi Iwai committed Jun 18, 2024
1 parent 6278056 commit e946455
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions sound/core/control.c
Original file line number Diff line number Diff line change
Expand Up @@ -604,13 +604,16 @@ 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.
*
* Note that this function takes card->controls_rwsem lock internally.
*/
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);
}
Expand Down

0 comments on commit e946455

Please sign in to comment.