diff mbox series

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

Message ID 20230606094035.14808-1-tiwai@suse.de (mailing list archive)
State New, archived
Headers show
Series ALSA: control: Keep the previous numid at snd_ctl_rename_id() | expand

Commit Message

Takashi Iwai June 6, 2023, 9:40 a.m. UTC
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.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
---
 sound/core/control.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

Comments

Jaroslav Kysela June 6, 2023, 11:15 a.m. UTC | #1
On 06. 06. 23 11:40, Takashi Iwai wrote:
> 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.

I would also highlight in the comment that snd_ctl_rename_id() should be used 
only in the card initialization phase. It may cause issues with the user space 
(persistent numid) for the dynamic controls.

Reviewed-by: Jaroslav Kysela <perex@perex.cz>
Takashi Iwai June 6, 2023, 12:35 p.m. UTC | #2
On Tue, 06 Jun 2023 13:15:20 +0200,
Jaroslav Kysela wrote:
> 
> On 06. 06. 23 11:40, Takashi Iwai wrote:
> > 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.
> 
> I would also highlight in the comment that snd_ctl_rename_id() should
> be used only in the card initialization phase. It may cause issues
> with the user space (persistent numid) for the dynamic controls.

Sounds good.  I'll add the note in the commit.

> Reviewed-by: Jaroslav Kysela <perex@perex.cz>


Thanks!

Takashi
diff mbox series

Patch

diff --git a/sound/core/control.c b/sound/core/control.c
index 82aa1af1d1d8..f4a90a687ae5 100644
--- a/sound/core/control.c
+++ b/sound/core/control.c
@@ -730,12 +730,16 @@  EXPORT_SYMBOL_GPL(snd_ctl_activate_id);
  * Finds the control with the old id from the card, and replaces the
  * id with the new one.
  *
+ * The function tries to keep the already assigned numid while replacing
+ * the rest.
+ *
  * 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,
 		      struct snd_ctl_elem_id *dst_id)
 {
 	struct snd_kcontrol *kctl;
+	int saved_numid;
 
 	down_write(&card->controls_rwsem);
 	kctl = snd_ctl_find_id(card, src_id);
@@ -743,10 +747,10 @@  int snd_ctl_rename_id(struct snd_card *card, struct snd_ctl_elem_id *src_id,
 		up_write(&card->controls_rwsem);
 		return -ENOENT;
 	}
+	saved_numid = kctl->id.numid;
 	remove_hash_entries(card, kctl);
 	kctl->id = *dst_id;
-	kctl->id.numid = card->last_numid + 1;
-	card->last_numid += kctl->count;
+	kctl->id.numid = saved_numid;
 	add_hash_entries(card, kctl);
 	up_write(&card->controls_rwsem);
 	return 0;