diff options
author | Jonas Bonn <jonas@norrbonn.se> | 2019-09-25 06:35:05 +0200 |
---|---|---|
committer | Denis Kenzior <denkenz@gmail.com> | 2019-09-25 21:25:16 -0500 |
commit | 4bf76718817cd2fe68a37d5edf72d8d6983d9672 (patch) | |
tree | 4f1d51fbf479996aec120f2f52a851622faab999 /plugins | |
parent | 388248d6a1c10c5412785f55276b1f7dde0ac1a3 (diff) | |
download | ofono-4bf76718817cd2fe68a37d5edf72d8d6983d9672.tar.gz |
ublox: consolidate teardown in common function
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.
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/ublox.c | 30 |
1 files 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) |