The code for closing all the modem devices and flagging the modem as
unpowered is repeated several times in the driver... this patch puts
this code into a common helper for readability.
---
plugins/ublox.c | 30 ++++++++++++++----------------
1 file changed, 14 insertions(+), 16 deletions(-)
diff --git a/plugins/ublox.c b/plugins/ublox.c
index 9ee38a6b..60a734ce 100644
--- a/plugins/ublox.c
+++ b/plugins/ublox.c
@@ -102,19 +102,25 @@ static void ublox_remove(struct ofono_modem *modem)
g_free(data);
}
+static void close_devices(struct ofono_modem* modem)
+{
+ struct ublox_data * data = ofono_modem_get_data(modem);
+
+ g_at_chat_unref(data->aux);
+ data->aux = NULL;
+ g_at_chat_unref(data->modem);
+ data->modem = NULL;
+ ofono_modem_set_powered(modem, FALSE);
+}
+
static void cfun_enable(gboolean ok, GAtResult *result, gpointer user_data)
{
struct ofono_modem *modem = user_data;
- struct ublox_data * data = ofono_modem_get_data(modem);
DBG("ok %d", ok);
if (!ok) {
- g_at_chat_unref(data->aux);
- data->aux = NULL;
- g_at_chat_unref(data->modem);
- data->modem = NULL;
- ofono_modem_set_powered(modem, FALSE);
+ close_devices(modem);
return;
}
@@ -165,11 +171,7 @@ retry:
return;
error:
- g_at_chat_unref(data->aux);
- data->aux = NULL;
- g_at_chat_unref(data->modem);
- data->modem = NULL;
- ofono_modem_set_powered(modem, FALSE);
+ close_devices(modem);
}
static void query_model_cb(gboolean ok, GAtResult *result, gpointer user_data)
@@ -216,11 +218,7 @@ static void query_model_cb(gboolean ok, GAtResult *result,
gpointer user_data)
return;
fail:
- g_at_chat_unref(data->aux);
- data->aux = NULL;
- g_at_chat_unref(data->modem);
- data->modem = NULL;
- ofono_modem_set_powered(modem, FALSE);
+ close_devices(modem);
}
static int ublox_enable(struct ofono_modem *modem)
--
2.20.1
_______________________________________________
ofono mailing list
[email protected]
https://lists.ofono.org/mailman/listinfo/ofono