[PATCH] huawei: avoid creating Connect3gppContext when no data port is available

Ben Chan benchan at chromium.org
Wed Jan 8 16:10:06 PST 2014


This patch modifies MMBroadbandBearerHuawei such that connect_3gpp
simply reports an error via g_simple_async_report_error_in_idle, without
creating a Connect3gppContext, if no data port is available.
---
 plugins/huawei/mm-broadband-bearer-huawei.c | 30 ++++++++++++++---------------
 1 file changed, 15 insertions(+), 15 deletions(-)

diff --git a/plugins/huawei/mm-broadband-bearer-huawei.c b/plugins/huawei/mm-broadband-bearer-huawei.c
index be84ff8..df2d6d4 100644
--- a/plugins/huawei/mm-broadband-bearer-huawei.c
+++ b/plugins/huawei/mm-broadband-bearer-huawei.c
@@ -69,8 +69,7 @@ connect_3gpp_context_complete_and_free (Connect3gppContext *ctx)
     g_simple_async_result_complete_in_idle (ctx->result);
     g_object_unref (ctx->cancellable);
     g_object_unref (ctx->result);
-    if (ctx->data)
-        g_object_unref (ctx->data);
+    g_object_unref (ctx->data);
     g_object_unref (ctx->primary);
     g_object_unref (ctx->modem);
     g_object_unref (ctx->self);
@@ -377,14 +376,28 @@ connect_3gpp (MMBroadbandBearer *self,
               gpointer user_data)
 {
     Connect3gppContext  *ctx;
+    MMPort *data;
 
     g_assert (primary != NULL);
 
+    /* We need a net data port */
+    data = mm_base_modem_peek_best_data_port (MM_BASE_MODEM (modem), MM_PORT_TYPE_NET);
+    if (!data) {
+        g_simple_async_report_error_in_idle (G_OBJECT (self),
+                                             callback,
+                                             user_data,
+                                             MM_CORE_ERROR,
+                                             MM_CORE_ERROR_NOT_FOUND,
+                                             "No valid data port found to launch connection");
+        return;
+    }
+
     /* Setup connection context */
     ctx = g_slice_new0 (Connect3gppContext);
     ctx->self = g_object_ref (self);
     ctx->modem = g_object_ref (modem);
     ctx->primary = g_object_ref (primary);
+    ctx->data = g_object_ref (data);
     ctx->result = g_simple_async_result_new (G_OBJECT (self),
                                              callback,
                                              user_data,
@@ -395,19 +408,6 @@ connect_3gpp (MMBroadbandBearer *self,
     g_assert (ctx->self->priv->connect_pending == NULL);
     g_assert (ctx->self->priv->disconnect_pending == NULL);
 
-    /* We need a net data port */
-    ctx->data = mm_base_modem_get_best_data_port (MM_BASE_MODEM (modem),
-                                                  MM_PORT_TYPE_NET);
-    if (!ctx->data) {
-        g_simple_async_result_set_error (
-            ctx->result,
-            MM_CORE_ERROR,
-            MM_CORE_ERROR_NOT_FOUND,
-            "No valid data port found to launch connection");
-        connect_3gpp_context_complete_and_free (ctx);
-        return;
-    }
-
     /* Run! */
     connect_3gpp_context_step (ctx);
 }
-- 
1.8.5.1



More information about the ModemManager-devel mailing list