ALSA: scarlett2: Allow passing any output to line_out_remap()
authorGeoffrey D. Bennett <g@b4.vu>
Thu, 26 Oct 2023 18:06:16 +0000 (04:36 +1030)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 25 Jan 2024 23:35:39 +0000 (15:35 -0800)
[ Upstream commit 2190b9aea4eb92ccf3176e35c17c959e40f1a81b ]

Line outputs 3 & 4 on the Gen 3 18i8 are internally the analogue 7 and
8 outputs, and this renumbering is hidden from the user by
line_out_remap(). By allowing higher values (representing non-analogue
outputs) to be passed to line_out_remap(), repeated code from
scarlett2_mux_src_enum_ctl_get() and scarlett2_mux_src_enum_ctl_put()
can be removed.

Signed-off-by: Geoffrey D. Bennett <g@b4.vu>
Link: https://lore.kernel.org/r/3b70267931f5994628ab27306c73cddd17b93c8f.1698342632.git.g@b4.vu
Signed-off-by: Takashi Iwai <tiwai@suse.de>
Stable-dep-of: 50603a67daef ("ALSA: scarlett2: Add missing error checks to *_ctl_get()")
Signed-off-by: Sasha Levin <sashal@kernel.org>
sound/usb/mixer_scarlett_gen2.c

index 834b936e7106e5064839bc66698236954482d9b1..5e3118bd0dc1a1228f65d43910be0949dcccfcd9 100644 (file)
@@ -1901,9 +1901,16 @@ static int scarlett2_master_volume_ctl_get(struct snd_kcontrol *kctl,
 static int line_out_remap(struct scarlett2_data *private, int index)
 {
        const struct scarlett2_device_info *info = private->info;
+       const int (*port_count)[SCARLETT2_PORT_DIRNS] = info->port_count;
+       int line_out_count =
+               port_count[SCARLETT2_PORT_TYPE_ANALOGUE][SCARLETT2_PORT_OUT];
 
        if (!info->line_out_remap_enable)
                return index;
+
+       if (index >= line_out_count)
+               return index;
+
        return info->line_out_remap[index];
 }
 
@@ -3388,14 +3395,7 @@ static int scarlett2_mux_src_enum_ctl_get(struct snd_kcontrol *kctl,
        struct usb_mixer_elem_info *elem = kctl->private_data;
        struct usb_mixer_interface *mixer = elem->head.mixer;
        struct scarlett2_data *private = mixer->private_data;
-       const struct scarlett2_device_info *info = private->info;
-       const int (*port_count)[SCARLETT2_PORT_DIRNS] = info->port_count;
-       int line_out_count =
-               port_count[SCARLETT2_PORT_TYPE_ANALOGUE][SCARLETT2_PORT_OUT];
-       int index = elem->control;
-
-       if (index < line_out_count)
-               index = line_out_remap(private, index);
+       int index = line_out_remap(private, elem->control);
 
        mutex_lock(&private->data_mutex);
        if (private->mux_updated)
@@ -3412,16 +3412,9 @@ static int scarlett2_mux_src_enum_ctl_put(struct snd_kcontrol *kctl,
        struct usb_mixer_elem_info *elem = kctl->private_data;
        struct usb_mixer_interface *mixer = elem->head.mixer;
        struct scarlett2_data *private = mixer->private_data;
-       const struct scarlett2_device_info *info = private->info;
-       const int (*port_count)[SCARLETT2_PORT_DIRNS] = info->port_count;
-       int line_out_count =
-               port_count[SCARLETT2_PORT_TYPE_ANALOGUE][SCARLETT2_PORT_OUT];
-       int index = elem->control;
+       int index = line_out_remap(private, elem->control);
        int oval, val, err = 0;
 
-       if (index < line_out_count)
-               index = line_out_remap(private, index);
-
        mutex_lock(&private->data_mutex);
 
        oval = private->mux[index];