[prev in list] [next in list] [prev in thread] [next in thread] 

List:       libusb-devel
Subject:    [libusb] [PATCH 2/4] linux: Filter hotplug events by DEVTYPE of "usb_device"
From:       Chris Dickens <christopher.a.dickens () gmail ! com>
Date:       2015-09-18 5:27:20
Message-ID: 1442554042-44377-3-git-send-email-christopher.a.dickens () gmail ! com
[Download RAW message or body]

Many different hotplug events can occur for the "usb" subsystem
(e.g. attaching/detaching a class driver), but libusb only needs
to care about events where the device type is "usb_device". All
other events cause needless attempts to lookup the device address,
which will fail as the paths for such events do not correspond to
actual USB device nodes.

Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
---
 libusb/os/linux_netlink.c | 7 +++++++
 libusb/os/linux_udev.c    | 3 ++-
 2 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/libusb/os/linux_netlink.c b/libusb/os/linux_netlink.c
index 7a30561..72d3589 100644
--- a/libusb/os/linux_netlink.c
+++ b/libusb/os/linux_netlink.c
@@ -222,6 +222,13 @@ static int linux_netlink_parse(char *buffer, size_t len, int *detached, const ch
 		return -1;
 	}
 
+	/* check that this is an actual usb device */
+	tmp = netlink_message_parse(buffer, len, "DEVTYPE");
+	if (NULL == tmp || 0 != strcmp(tmp, "usb_device")) {
+		/* not usb. ignore */
+		return -1;
+	}
+
 	tmp = netlink_message_parse(buffer, len, "BUSNUM");
 	if (NULL == tmp) {
 		/* no bus number. try "DEVICE" */
diff --git a/libusb/os/linux_udev.c b/libusb/os/linux_udev.c
index 6577240..b63db98 100644
--- a/libusb/os/linux_udev.c
+++ b/libusb/os/linux_udev.c
@@ -69,7 +69,7 @@ int linux_udev_start_event_monitor(void)
 		goto err_free_ctx;
 	}
 
-	r = udev_monitor_filter_add_match_subsystem_devtype(udev_monitor, "usb", 0);
+	r = udev_monitor_filter_add_match_subsystem_devtype(udev_monitor, "usb", "usb_device");
 	if (r) {
 		usbi_err(NULL, "could not initialize udev monitor filter for \"usb\" subsystem");
 		goto err_free_monitor;
@@ -266,6 +266,7 @@ int linux_udev_scan_devices(struct libusb_context *ctx)
 	}
 
 	udev_enumerate_add_match_subsystem(enumerator, "usb");
+	udev_enumerate_add_match_property(enumerator, "DEVTYPE", "usb_device");
 	udev_enumerate_scan_devices(enumerator);
 	devices = udev_enumerate_get_list_entry(enumerator);
 
-- 
2.4.3


------------------------------------------------------------------------------
_______________________________________________
libusb-devel mailing list
libusb-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/libusb-devel
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic