Commit 306f3f78 authored by Takashi Iwai's avatar Takashi Iwai

ALSA: control: Keep the previous numid at snd_ctl_rename_id()

We don't need to change the numid at each time snd_ctl_rename_id() is
called, as the control element size itself doesn't change.  Let's keep
the previous numid value.

Along with it, add a note about calling this function only in the
card init phase.
Reviewed-by: default avatarJaroslav Kysela <perex@perex.cz>
Link: https://lore.kernel.org/r/20230606094035.14808-1-tiwai@suse.deSigned-off-by: default avatarTakashi Iwai <tiwai@suse.de>
parent ebcbfd84
...@@ -730,12 +730,20 @@ EXPORT_SYMBOL_GPL(snd_ctl_activate_id); ...@@ -730,12 +730,20 @@ EXPORT_SYMBOL_GPL(snd_ctl_activate_id);
* Finds the control with the old id from the card, and replaces the * Finds the control with the old id from the card, and replaces the
* id with the new one. * id with the new one.
* *
* The function tries to keep the already assigned numid while replacing
* the rest.
*
* Note that this function should be used only in the card initialization
* phase. Calling after the card instantiation may cause issues with
* user-space expecting persistent numids.
*
* Return: Zero if successful, or a negative error code on failure. * Return: Zero if successful, or a negative error code on failure.
*/ */
int snd_ctl_rename_id(struct snd_card *card, struct snd_ctl_elem_id *src_id, int snd_ctl_rename_id(struct snd_card *card, struct snd_ctl_elem_id *src_id,
struct snd_ctl_elem_id *dst_id) struct snd_ctl_elem_id *dst_id)
{ {
struct snd_kcontrol *kctl; struct snd_kcontrol *kctl;
int saved_numid;
down_write(&card->controls_rwsem); down_write(&card->controls_rwsem);
kctl = snd_ctl_find_id(card, src_id); kctl = snd_ctl_find_id(card, src_id);
...@@ -743,10 +751,10 @@ int snd_ctl_rename_id(struct snd_card *card, struct snd_ctl_elem_id *src_id, ...@@ -743,10 +751,10 @@ int snd_ctl_rename_id(struct snd_card *card, struct snd_ctl_elem_id *src_id,
up_write(&card->controls_rwsem); up_write(&card->controls_rwsem);
return -ENOENT; return -ENOENT;
} }
saved_numid = kctl->id.numid;
remove_hash_entries(card, kctl); remove_hash_entries(card, kctl);
kctl->id = *dst_id; kctl->id = *dst_id;
kctl->id.numid = card->last_numid + 1; kctl->id.numid = saved_numid;
card->last_numid += kctl->count;
add_hash_entries(card, kctl); add_hash_entries(card, kctl);
up_write(&card->controls_rwsem); up_write(&card->controls_rwsem);
return 0; return 0;
......
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