From 019f0c92653a6547c9b07fecddab0ce87ed9736f Mon Sep 17 00:00:00 2001 From: Denis Kenzior Date: Thu, 29 Sep 2011 10:48:23 -0500 Subject: [PATCH] telit: Reflow sap_enable logic To cover some conditions where we do not clean up properly --- plugins/telit.c | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/plugins/telit.c b/plugins/telit.c index cb34ae6..d2f6c5a 100644 --- a/plugins/telit.c +++ b/plugins/telit.c @@ -279,10 +279,6 @@ static int telit_sap_enable(struct ofono_modem *modem, DBG("%p", modem); - data->aux = open_device(modem, "Data", "Aux: "); - if (data->aux == NULL) - return -EINVAL; - fd = telit_sap_open(); if (fd < 0) return fd; @@ -297,25 +293,26 @@ static int telit_sap_enable(struct ofono_modem *modem, g_io_channel_set_buffered(data->hw_io, FALSE); g_io_channel_set_close_on_unref(data->hw_io, TRUE); - data->hw_watch = g_io_add_watch_full(data->hw_io, G_PRIORITY_DEFAULT, - G_IO_HUP | G_IO_ERR | G_IO_NVAL | G_IO_IN, - hw_event_cb, modem, hw_watch_remove); + data->aux = open_device(modem, "Data", "Aux: "); + if (data->aux == NULL) + goto error; data->bt_io = g_io_channel_unix_new(bt_fd); - if (data->bt_io == NULL) { - sap_close_io(modem); - return -ENOMEM; - } + if (data->bt_io == NULL) + goto error; g_io_channel_set_encoding(data->bt_io, NULL, NULL); g_io_channel_set_buffered(data->bt_io, FALSE); g_io_channel_set_close_on_unref(data->bt_io, TRUE); + data->hw_watch = g_io_add_watch_full(data->hw_io, G_PRIORITY_DEFAULT, + G_IO_HUP | G_IO_ERR | G_IO_NVAL | G_IO_IN, + hw_event_cb, modem, hw_watch_remove); + data->bt_watch = g_io_add_watch_full(data->bt_io, G_PRIORITY_DEFAULT, G_IO_HUP | G_IO_ERR | G_IO_NVAL | G_IO_IN, bt_event_cb, modem, bt_watch_remove); - data->sap_modem = sap_modem; g_at_chat_register(data->aux, "#RSEN:", telit_rsen_notify, @@ -328,6 +325,10 @@ static int telit_sap_enable(struct ofono_modem *modem, rsen_enable_cb, modem, NULL); return -EINPROGRESS; + +error: + sap_close_io(modem); + return -EINVAL; } static struct bluetooth_sap_driver sap_driver = { -- 2.7.4