diff --git a/src/driver-hidpp20.c b/src/driver-hidpp20.c index ed889edb..a84f5496 100644 --- a/src/driver-hidpp20.c +++ b/src/driver-hidpp20.c @@ -54,8 +54,6 @@ struct hidpp20drv_data { struct hidpp20_device *dev; - unsigned proto_major; - unsigned proto_minor; unsigned long capabilities; unsigned num_sensors; struct hidpp20_sensor *sensors; @@ -496,19 +494,10 @@ hidpp20drv_probe(struct ratbag_device *device) } drv_data->dev = dev; - drv_data->proto_major = 1; - drv_data->proto_minor = 0; - rc = hidpp20_root_get_protocol_version(drv_data->dev, &drv_data->proto_major, &drv_data->proto_minor); - if (rc) { - /* communication error, best to ignore the device */ - rc = -EINVAL; - goto err; - } + log_debug(device->ratbag, "'%s' is using protocol v%d.%d\n", ratbag_device_get_name(device), dev->proto_major, dev->proto_minor); - log_debug(device->ratbag, "'%s' is using protocol v%d.%d\n", ratbag_device_get_name(device), drv_data->proto_major, drv_data->proto_minor); - - if (drv_data->proto_major >= 2) { + if (dev->proto_major >= 2) { rc = hidpp20drv_20_probe(device); if (rc) goto err; diff --git a/src/hidpp20.c b/src/hidpp20.c index 954704cc..f02aa704 100644 --- a/src/hidpp20.c +++ b/src/hidpp20.c @@ -915,13 +915,26 @@ struct hidpp20_device * hidpp20_device_new(const struct hidpp_device *base, unsigned int idx) { struct hidpp20_device *dev; + int rc; dev = zalloc(sizeof(*dev)); dev->index = idx; dev->base = *base; + dev->proto_major = 1; + dev->proto_minor = 0; + + rc = hidpp20_root_get_protocol_version(dev, &dev->proto_major, &dev->proto_minor); + if (rc) { + /* communication error, best to ignore the device */ + goto err; + } + return dev; +err: + free(dev); + return NULL; } void diff --git a/src/hidpp20.h b/src/hidpp20.h index ccab08dd..2abc41bc 100644 --- a/src/hidpp20.h +++ b/src/hidpp20.h @@ -49,6 +49,8 @@ union hidpp20_message { struct hidpp20_device { struct hidpp_device base; unsigned int index; + unsigned proto_major; + unsigned proto_minor; }; int hidpp20_request_command(struct hidpp20_device *dev, union hidpp20_message *msg);