Skip to content

Commit 343e02b

Browse files
committed
Improve USB2/3 duality handling
If hub and its dual have identical description except for vid:pid and USB version strings, we consider this preferred match.
1 parent f2a50dd commit 343e02b

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

uhubctl.c

+13-1
Original file line numberDiff line numberDiff line change
@@ -672,7 +672,19 @@ static int usb_find_hubs()
672672
if (hubs[i].nports != hubs[j].nports)
673673
continue;
674674

675-
/* Provisionally we choose this one as dual: */
675+
/* If description is the same, provisionally we choose this one as dual.
676+
* If description contained serial number, this will be most reliable matching.
677+
*/
678+
if (strlen(hubs[i].description) == strlen(hubs[j].description)) {
679+
/* strlen("vvvv:pppp ") + strlen(", USB x.yz, N ports") = 10+19 = 29 */
680+
if (strlen(hubs[i].description) >= 29) {
681+
if (strncmp(hubs[i].description+10, hubs[j].description+10, strlen(hubs[i].description)-29) == 0) {
682+
match = j;
683+
}
684+
}
685+
}
686+
687+
/* Running out of options - provisionally we choose this one as dual: */
676688
if (match < 0 && !hubs[j].actionable)
677689
match = j;
678690

0 commit comments

Comments
 (0)