alsa-ucm: Fix UCM devices which names share a prefix being seen as the same
authorHans de Goede <hdegoede@redhat.com>
Mon, 24 Dec 2018 11:45:48 +0000 (12:45 +0100)
committerHans de Goede <hdegoede@redhat.com>
Mon, 24 Dec 2018 11:45:48 +0000 (12:45 +0100)
Before this commit ucm_port_contains() was using a strncmp to compare
UCM-device-names without first checking that the part of the port_name
being compared and the device-name have the same length, this was causing
it to return true for both "InternalMic-IN1" and "InternalMic-IN12" when
port_name contained "InternalMic-IN1".

We hit this with the bytcr_rt5651 UCM profile which has "InternalMic-IN1",
"InternalMic-IN2" and "InternalMic-IN12" devices, for devices with their
internal mic connected to IN1, or IN2, or using stereo internal mics
connected to both. This problem resulted in various problems including
the RECMIXL? BST2 switch getting turned on when selecting only
"InternalMic-IN1", as well as confusing the gnome-control-center sound
panel, which could not figure out which device is selected in this case.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
src/modules/alsa/alsa-ucm.c

index b42c040..d2d3ee1 100644 (file)
@@ -809,7 +809,7 @@ static int ucm_port_contains(const char *port_name, const char *dev_name, bool i
     port_name += is_sink ? strlen(PA_UCM_PRE_TAG_OUTPUT) : strlen(PA_UCM_PRE_TAG_INPUT);
 
     while ((r = pa_split_in_place(port_name, "+", &len, &state))) {
-        if (!strncmp(r, dev_name, len)) {
+        if (strlen(dev_name) == len && !strncmp(r, dev_name, len)) {
             ret = 1;
             break;
         }