From abde78e6c4a95679950c9d834ff00248f847d326 Mon Sep 17 00:00:00 2001 From: Benjamin Tissoires Date: Wed, 7 Oct 2015 16:46:28 -0400 Subject: [PATCH] hidraw: check if the hidraw node corresponds to the ratbag device We were retrieving the hidraw information but did not use them. Now the debug output "foo is device 'bar'" is only shown when there is a match. Signed-off-by: Benjamin Tissoires --- src/libratbag-hidraw.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/libratbag-hidraw.c b/src/libratbag-hidraw.c index 0c01cf6d..0dca5101 100644 --- a/src/libratbag-hidraw.c +++ b/src/libratbag-hidraw.c @@ -147,11 +147,6 @@ ratbag_open_hidraw(struct ratbag_device *device) if (!hidraw_udev) return -ENODEV; - log_debug(device->ratbag, - "%s is device '%s'.\n", - device->name, - udev_device_get_devnode(hidraw_udev)); - devnode = udev_device_get_devnode(hidraw_udev); fd = ratbag_open_path(device, devnode, O_RDWR); if (fd < 0) @@ -165,6 +160,19 @@ ratbag_open_hidraw(struct ratbag_device *device) goto err; } + /* check basic matching between the hidraw node and the ratbag device */ + if (info.bustype != device->ids.bustype || + (info.vendor & 0xFFFF )!= device->ids.vendor || + (info.product & 0xFFFF) != device->ids.product) { + errno = ENODEV; + goto err; + } + + log_debug(device->ratbag, + "%s is device '%s'.\n", + device->name, + udev_device_get_devnode(hidraw_udev)); + device->hidraw.fd = fd; /* parse first to count the number of reports */