[PATCH] base-manager: avoid events of USB interface from removing MMDevice

Ben Chan benchan at chromium.org
Tue Aug 22 01:42:25 UTC 2017


When a USB modem is switching its USB configuration, udev may deliver
the remove events of USB interfaces associated with the old USB
configuration and the add events of USB interfaces associated with the new USB
configuration in an interleaved fashion. An interleaved remove event of USB
interface could trigger the special case handling code in
mm-base-manager.c:device_removed() and incorrectly remove a MMDevice under
probing.

See https://lists.freedesktop.org/archives/modemmanager-devel/2017-August/005626.html
for more details.

This patch adds a check to ensure that only remove events of USB
device (i.e. not interface) can trigger the special handling code.
---
Given that we'll eventually remove the special handling code, this is probably
the least intrusive way to work around the issue in the meantime.


 src/mm-base-manager.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/src/mm-base-manager.c b/src/mm-base-manager.c
index 48e2f25d..f5ccb1c5 100644
--- a/src/mm-base-manager.c
+++ b/src/mm-base-manager.c
@@ -248,6 +248,18 @@ device_removed (MMBaseManager  *self,
      * device has been removed.  That way, if the device is reinserted later, we'll go through
      * the process of exporting it.
      */
+#if defined WITH_UDEV
+    /* When a USB modem is switching its USB configuration, udev may deliver
+     * the remove events of USB interfaces associated with the old USB
+     * configuration and the add events of USB interfaces associated with the
+     * new USB configuration in an interleaved fashion. As we don't want a
+     * remove event of an USB interface trigger the removal of a MMDevice for
+     * the special case being handled here, we ignore any remove event with
+     * DEVTYPE != usb_device.
+     */
+    if (g_strcmp0 (mm_kernel_device_get_property (kernel_device, "DEVTYPE"), "usb_device") != 0)
+        return;
+#endif
     device = find_device_by_kernel_device (self, kernel_device);
     if (device) {
         mm_dbg ("Removing device '%s'", mm_device_get_uid (device));
-- 
2.14.1.480.gb18f417b89-goog



More information about the ModemManager-devel mailing list