From a3f568db3da946bdd5e922e025c11d9ab6420cb6 Mon Sep 17 00:00:00 2001 From: Matthew Mirvish Date: Mon, 21 Jun 2021 13:39:24 -0400 Subject: [PATCH] fp-context: Check hidraw VID/PID with udev instead of an ioctl Previously, we checked hidraw devices against drivers by using the HIDIOCGRAWINFO ioctl. While this works, it's not ideal for doing unit tests since umockdev would have to implement hidraw ioctls. The new approach uses the HID_ID property on the parent hid device, which contains the VID/PID pair. --- libfprint/fp-context.c | 25 ++++++++----------------- 1 file changed, 8 insertions(+), 17 deletions(-) diff --git a/libfprint/fp-context.c b/libfprint/fp-context.c index fc0eb8d7..578766b9 100644 --- a/libfprint/fp-context.c +++ b/libfprint/fp-context.c @@ -23,16 +23,11 @@ #include "fpi-context.h" #include "fpi-device.h" #include +#include #include #ifdef HAVE_UDEV -#include -#include -#include -#include -#include -#include #include #endif @@ -521,22 +516,18 @@ fp_context_enumerate (FpContext *context) { for (matched_hidraw = hidraw_devices; matched_hidraw; matched_hidraw = matched_hidraw->next) { - const gchar * devnode = g_udev_device_get_device_file (matched_hidraw->data); - int temp_hid = -1, res; - struct hidraw_devinfo info; + /* Find the parent HID node, and check the vid/pid from its HID_ID property */ + g_autoptr(GUdevDevice) parent = g_udev_device_get_parent_with_subsystem (matched_hidraw->data, "hid", NULL); + const gchar * hid_id = g_udev_device_get_property (parent, "HID_ID"); + guint32 vendor, product; - if (!devnode) + if (!parent || !hid_id) continue; - temp_hid = open (devnode, O_RDWR); - if (temp_hid < 0) + if (sscanf (hid_id, "%*X:%X:%X", &vendor, &product) != 2) continue; - res = ioctl (temp_hid, HIDIOCGRAWINFO, &info); - close (temp_hid); - if (res < 0) - continue; - if (info.vendor == entry->hid_id.vid && info.product == entry->hid_id.pid) + if (vendor == entry->hid_id.vid && product == entry->hid_id.pid) break; } /* If match was not found exit */