[MM 0.5] Limit the number of deferred tasks

Hey Dan,

Following a recent issue found with Huawei modems, it seems we cannot assume that usbif 0 will always be an AT port we can probe. If such a modem gets plugged, it will end up looping forever as no port will get probed before usbif 0, which never gets probed.

Attached is a patch for MM_05, which limits the number of 'defer' results a given port can reply; if the limit is reached, the port probing is forced in the port. Do you see a better/easier way of doing this in MM_05?

For MM_07, there's a related fix in the Huawei plugin in the 'probing-update' branch. If usbif0 isn't found in some seconds, the first next available usbif will be used instead. In the reporter's case, usbif 1 will end up getting probed. In this case, the behaviour will be more similar to what we currently have, this is, a single port gets up probed first, then the rest.

>From d36dcdd2c13f01dafc994d9b60f68e568a8f8ea0 Mon Sep 17 00:00:00 2001
From: Aleksander Morgado <aleksander lanedo com>
Date: Sun, 15 Jul 2012 18:26:11 +0200
Subject: [PATCH] huawei: limit the number of deferred tasks

The Huawei plugin requires to probe first the USB interface 0; all the other
probing tasks in the remaining ports will get deferred until the interface 0
gets probed. But, some modems (e.g. Huawei ET8282), don't expose the USB
interface 0 as an AT port, so we get an infinite loop as no port ends up being

In order to fix this, we will limit to a predefined maximum the number of times a given probing task is deferred, 4 in this case. So, if a given probing task is
deferred for more than 4x3s=12s, probing will get forced.
 plugins/mm-plugin-huawei.c |   30 ++++++++++++++++++++++++++++--
 1 file changed, 28 insertions(+), 2 deletions(-)

diff --git a/plugins/mm-plugin-huawei.c b/plugins/mm-plugin-huawei.c
index fe7ffa0..d861a37 100644
--- a/plugins/mm-plugin-huawei.c
+++ b/plugins/mm-plugin-huawei.c
@@ -159,6 +159,9 @@ add_regex (MMAtSerialPort *port, const char *match, gpointer user_data)
     g_regex_unref (regex);
+#define TAG_DEFER_COUNTS_PREFIX "huawei-defer-counts"
+#define MAX_DEFERS 4
 static MMPluginSupportsResult
 supports_port (MMPluginBase *base,
                MMModem *existing,
@@ -198,8 +201,31 @@ supports_port (MMPluginBase *base,
      * we need to use the first port that does respond to probing to create the
      * right type of mode (GSM or CDMA), and then re-check the other interfaces.
-    if (!existing && usbif != 0)
+    if (!existing && usbif != 0) {
+        gchar *tag;
+        guint n_deferred;
+        /* We need to defer the probing as usbif 0 wasn't probed yet. We need to
+         * protect against the case of not having usbif 0 as an AT port, and we
+         * do that by limiting the number of times we defer the probing. */
+        tag = g_strdup_printf ("%s-%s/%s", TAG_DEFER_COUNTS_PREFIX, subsys, name);
+        /* First time requested will be 0 */
+        n_deferred = GPOINTER_TO_UINT (g_object_get_data (G_OBJECT (base), tag));
+        if (n_deferred < MAX_DEFERS) {
+            /* Update defer count */
+            g_object_set_data (G_OBJECT (base), tag, GUINT_TO_POINTER (n_deferred + 1));
+            g_free (tag);
+            return MM_PLUGIN_SUPPORTS_PORT_DEFER;
+        }
+        mm_dbg ("(%s): no longer waiting for usbif 0, will launch probing in interface (%s/%s)",
+                mm_plugin_get_name (MM_PLUGIN (base)), subsys, name);
+        g_free (tag);
+        /* Clear tag */
+        g_object_set_data (G_OBJECT (base), tag, NULL);
+    }
     /* CDMA devices don't have problems with the secondary ports, so after
      * ensuring we have a device by probing the first port, probe the secondary

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]