forked from drath/libratbag
sinowealth: check if ButtonCount field in device file is correct
Fixes such scenario: Set ButtonCount to -1. Start libratbag. Watch sun burn.
This commit is contained in:
@@ -1668,7 +1668,18 @@ sinowealth_init_profile(struct ratbag_device *device)
|
||||
const unsigned int active_profile_index = (unsigned int)rc;
|
||||
log_debug(device->ratbag, "Active profile index: %d\n", rc);
|
||||
|
||||
drv_data->button_count = device_data->button_count;
|
||||
rc = device_data->button_count;
|
||||
if (rc == -1) {
|
||||
drv_data->button_count = 0;
|
||||
} else if (rc >= 0) {
|
||||
drv_data->button_count = (unsigned int)rc;
|
||||
} else {
|
||||
log_error(device->ratbag,
|
||||
"Device file for firmware version %s specifies button count: %d\n",
|
||||
fw_version, rc);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
drv_data->led_type = device_data->led_type;
|
||||
|
||||
log_info(device->ratbag, "Found device: %s\n", device_data->device_name);
|
||||
|
||||
@@ -35,7 +35,7 @@ struct sinowealth_device_data {
|
||||
char *fw_version;
|
||||
char *device_name;
|
||||
enum sinowealth_led_format led_type;
|
||||
unsigned int button_count;
|
||||
int button_count;
|
||||
int profile_count;
|
||||
|
||||
struct list link;
|
||||
|
||||
@@ -248,7 +248,12 @@ init_data_sinowealth(struct ratbag *ratbag,
|
||||
|
||||
struct sinowealth_device_data *device = zalloc(sizeof(struct sinowealth_device_data));
|
||||
|
||||
device->button_count = g_key_file_get_integer(keyfile, device_group, "ButtonCount", &error);
|
||||
rc = g_key_file_get_integer(keyfile, device_group, "ButtonCount", &error);
|
||||
if (rc != 0 && !error) {
|
||||
device->button_count = rc;
|
||||
} else {
|
||||
device->button_count = -1;
|
||||
}
|
||||
g_clear_error(&error);
|
||||
|
||||
device->device_name = g_key_file_get_string(keyfile, device_group, "DeviceName", &error);
|
||||
|
||||
Reference in New Issue
Block a user