From bc059353222273db8e2c757a17a01c8f50c239e7 Mon Sep 17 00:00:00 2001 From: Yaroslav Chvanov Date: Wed, 1 Mar 2023 03:04:35 +0300 Subject: [PATCH] sinowealth: use the first profile if active profile index is too high It seems like some devices now do have several profiles support enabled officially. We failed to probe such mice if they have had non-first profile as active. This fixes it. --- src/driver-sinowealth.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/driver-sinowealth.c b/src/driver-sinowealth.c index 710dd270..af6aeede 100644 --- a/src/driver-sinowealth.c +++ b/src/driver-sinowealth.c @@ -1523,6 +1523,21 @@ sinowealth_init_profile(struct ratbag_device *device) rc = sinowealth_get_active_profile(device); if (rc < 0) return rc; + /* If we are not compiled with support with support for this many profiles. */ + if (rc >= SINOWEALTH_NUM_PROFILES) { + const unsigned int PROFILE_TO_USE = 0; + log_error(device->ratbag, + "Active profile index is %d, but our max is %d; " + "Will use profile %d instead; " + "Report this to libratbag developers!\n", + rc, + SINOWEALTH_NUM_PROFILES - 1, + PROFILE_TO_USE); + sinowealth_set_active_profile(device, PROFILE_TO_USE); + if (rc < 0) + return rc; + rc = (int)PROFILE_TO_USE; + } const unsigned int active_profile_index = (unsigned int)rc; log_debug(device->ratbag, "Active profile index: %d\n", rc);