From ba9f126716db3ae0bf6a3139088d9657cfb8b851 Mon Sep 17 00:00:00 2001 From: Denis Kenzior Date: Wed, 8 Nov 2017 21:37:12 -0600 Subject: [PATCH] atmodem: Rework at_pin_send_cb Instead of delaying the cpin entry callback until the sim is found to be 'ready', call back into the core right away. The core will wait until the initialized notification is called from the driver before proceeding with the rest of the initialization procedure. The sim state query is now being done in the background and potential leaking of cbd is now fixed. --- drivers/atmodem/sim.c | 24 +++++++++--------------- 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/drivers/atmodem/sim.c b/drivers/atmodem/sim.c index ba7ea6b9..ab75b32a 100644 --- a/drivers/atmodem/sim.c +++ b/drivers/atmodem/sim.c @@ -1275,25 +1275,22 @@ static void at_pin_query(struct ofono_sim *sim, ofono_sim_passwd_cb_t cb, static void sim_state_cb(gboolean present, gpointer user_data) { - struct cb_data *cbd = user_data; - struct sim_data *sd = cbd->user; - ofono_sim_lock_unlock_cb_t cb = cbd->cb; - void *data = cbd->data; + struct ofono_sim *sim = user_data; + struct sim_data *sd = ofono_sim_get_data(sim); at_util_sim_state_query_free(sd->sim_state_query); sd->sim_state_query = NULL; if (present == 1) - CALLBACK_WITH_SUCCESS(cb, data); - else - CALLBACK_WITH_FAILURE(cb, data); + ofono_sim_initialized_notify(sim); } static void at_pin_send_cb(gboolean ok, GAtResult *result, gpointer user_data) { struct cb_data *cbd = user_data; - struct sim_data *sd = cbd->user; + struct ofono_sim *sim = cbd->user; + struct sim_data *sd = ofono_sim_get_data(sim); ofono_sim_lock_unlock_cb_t cb = cbd->cb; struct ofono_error error; @@ -1320,15 +1317,12 @@ static void at_pin_send_cb(gboolean ok, GAtResult *result, * state. */ sd->sim_state_query = at_util_sim_state_query_new(sd->chat, - 2, 20, sim_state_cb, cbd, - g_free); - return; + 2, 20, sim_state_cb, sim, + NULL); } done: cb(&error, cbd->data); - - g_free(cbd); } static void at_pin_send(struct ofono_sim *sim, const char *passwd, @@ -1339,12 +1333,12 @@ static void at_pin_send(struct ofono_sim *sim, const char *passwd, char buf[64]; int ret; - cbd->user = sd; + cbd->user = sim; snprintf(buf, sizeof(buf), "AT+CPIN=\"%s\"", passwd); ret = g_at_chat_send(sd->chat, buf, none_prefix, - at_pin_send_cb, cbd, NULL); + at_pin_send_cb, cbd, g_free); memset(buf, 0, sizeof(buf));