Skip to content

Commit 306f3f7

Browse files
committed
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: Jaroslav Kysela <perex@perex.cz> Link: https://lore.kernel.org/r/20230606094035.14808-1-tiwai@suse.de Signed-off-by: Takashi Iwai <tiwai@suse.de>
1 parent ebcbfd8 commit 306f3f7

1 file changed

Lines changed: 10 additions & 2 deletions

File tree

sound/core/control.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -730,23 +730,31 @@ EXPORT_SYMBOL_GPL(snd_ctl_activate_id);
730730
* Finds the control with the old id from the card, and replaces the
731731
* id with the new one.
732732
*
733+
* The function tries to keep the already assigned numid while replacing
734+
* the rest.
735+
*
736+
* Note that this function should be used only in the card initialization
737+
* phase. Calling after the card instantiation may cause issues with
738+
* user-space expecting persistent numids.
739+
*
733740
* Return: Zero if successful, or a negative error code on failure.
734741
*/
735742
int snd_ctl_rename_id(struct snd_card *card, struct snd_ctl_elem_id *src_id,
736743
struct snd_ctl_elem_id *dst_id)
737744
{
738745
struct snd_kcontrol *kctl;
746+
int saved_numid;
739747

740748
down_write(&card->controls_rwsem);
741749
kctl = snd_ctl_find_id(card, src_id);
742750
if (kctl == NULL) {
743751
up_write(&card->controls_rwsem);
744752
return -ENOENT;
745753
}
754+
saved_numid = kctl->id.numid;
746755
remove_hash_entries(card, kctl);
747756
kctl->id = *dst_id;
748-
kctl->id.numid = card->last_numid + 1;
749-
card->last_numid += kctl->count;
757+
kctl->id.numid = saved_numid;
750758
add_hash_entries(card, kctl);
751759
up_write(&card->controls_rwsem);
752760
return 0;

0 commit comments

Comments
 (0)