isimodem: Fix request cleanup code

Adds a check for when the driver is being removed, in which case no
new ISI requests should be generated.
This commit is contained in:
Aki Niemi 2010-10-19 11:28:06 +03:00
parent fd74feac0d
commit 255782f8c2
15 changed files with 84 additions and 59 deletions

View File

@ -128,10 +128,14 @@ static void isi_set(struct ofono_call_barring *barr, const char *lock,
DBG("lock code %s enable %d class %d password %s\n", DBG("lock code %s enable %d class %d password %s\n",
lock, enable, cls, passwd); lock, enable, cls, passwd);
if (cbd && g_isi_request_make(bd->client, msg, sizeof(msg), SS_TIMEOUT, if (!cbd || !bd)
set_resp_cb, cbd)) goto error;
if (g_isi_request_make(bd->client, msg, sizeof(msg), SS_TIMEOUT,
set_resp_cb, cbd))
return; return;
error:
CALLBACK_WITH_FAILURE(cb, data); CALLBACK_WITH_FAILURE(cb, data);
g_free(cbd); g_free(cbd);
} }
@ -271,10 +275,14 @@ static void isi_query(struct ofono_call_barring *barr, const char *lock,
DBG("barring query lock code %s\n", lock); DBG("barring query lock code %s\n", lock);
if (cbd && g_isi_request_make(bd->client, msg, sizeof(msg), SS_TIMEOUT, if (!cbd || !bd)
query_resp_cb, cbd)) goto error;
if (g_isi_request_make(bd->client, msg, sizeof(msg), SS_TIMEOUT,
query_resp_cb, cbd))
return; return;
error:
CALLBACK_WITH_FAILURE(cb, 0, data); CALLBACK_WITH_FAILURE(cb, 0, data);
g_free(cbd); g_free(cbd);
} }
@ -338,11 +346,14 @@ static void isi_set_passwd(struct ofono_call_barring *barr, const char *lock,
DBG("lock code %s (%u) old password %s new password %s\n", DBG("lock code %s (%u) old password %s new password %s\n",
lock, ss_code, old_passwd, new_passwd); lock, ss_code, old_passwd, new_passwd);
if (cbd && if (!cbd || !bd)
g_isi_request_make(bd->client, msg, sizeof(msg), SS_TIMEOUT, goto error;
if (g_isi_request_make(bd->client, msg, sizeof(msg), SS_TIMEOUT,
set_passwd_resp_cb, cbd)) set_passwd_resp_cb, cbd))
return; return;
error:
CALLBACK_WITH_FAILURE(cb, data); CALLBACK_WITH_FAILURE(cb, data);
g_free(cbd); g_free(cbd);
} }

View File

@ -229,7 +229,7 @@ static void isi_registration(struct ofono_call_forwarding *cf,
DBG("forwarding type %d class %d\n", type, cls); DBG("forwarding type %d class %d\n", type, cls);
if (!cbd || !number->number || strlen(number->number) > 28) if (!cbd || !fd || !number->number || strlen(number->number) > 28)
goto error; goto error;
ss_code = forw_type_to_isi_code(type); ss_code = forw_type_to_isi_code(type);
@ -349,7 +349,7 @@ static void isi_erasure(struct ofono_call_forwarding *cf, int type, int cls,
DBG("forwarding type %d class %d\n", type, cls); DBG("forwarding type %d class %d\n", type, cls);
if (!cbd) if (!cbd || !fd)
goto error; goto error;
ss_code = forw_type_to_isi_code(type); ss_code = forw_type_to_isi_code(type);
@ -481,7 +481,7 @@ static void isi_query(struct ofono_call_forwarding *cf, int type, int cls,
DBG("forwarding type %d class %d\n", type, cls); DBG("forwarding type %d class %d\n", type, cls);
if (!cbd || cls != 7) if (!cbd || !fd || cls != 7)
goto error; goto error;
ss_code = forw_type_to_isi_code(type); ss_code = forw_type_to_isi_code(type);

View File

@ -177,7 +177,7 @@ static void isi_cw_query(struct ofono_call_settings *cs, int cls,
DBG("waiting class %d\n", cls); DBG("waiting class %d\n", cls);
if (!cbd) if (!cbd || !sd)
goto error; goto error;
if (g_isi_request_make(sd->client, msg, sizeof(msg), SS_TIMEOUT, if (g_isi_request_make(sd->client, msg, sizeof(msg), SS_TIMEOUT,
@ -268,7 +268,7 @@ static void isi_cw_set(struct ofono_call_settings *cs, int mode, int cls,
DBG("waiting mode %d class %d\n", mode, cls); DBG("waiting mode %d class %d\n", mode, cls);
if (!cbd) if (!cbd || !sd)
goto error; goto error;
if (g_isi_request_make(sd->client, msg, sizeof(msg), SS_TIMEOUT, if (g_isi_request_make(sd->client, msg, sizeof(msg), SS_TIMEOUT,

View File

@ -128,7 +128,7 @@ static void isi_query_manufacturer(struct ofono_devinfo *info,
INFO_PRODUCT_MANUFACTURER INFO_PRODUCT_MANUFACTURER
}; };
if (!cbd) if (!cbd || !dev)
goto error; goto error;
if (g_isi_request_make(dev->client, msg, sizeof(msg), if (g_isi_request_make(dev->client, msg, sizeof(msg),
@ -177,7 +177,7 @@ static void isi_query_revision(struct ofono_devinfo *info,
0x00, 0x00, 0x00, 0x00 0x00, 0x00, 0x00, 0x00
}; };
if (!cbd) if (!cbd || !dev)
goto error; goto error;
if (g_isi_request_make(dev->client, msg, sizeof(msg), if (g_isi_request_make(dev->client, msg, sizeof(msg),
@ -201,7 +201,7 @@ static void isi_query_serial(struct ofono_devinfo *info,
INFO_SN_IMEI_PLAIN INFO_SN_IMEI_PLAIN
}; };
if (!cbd) if (!cbd || !dev)
goto error; goto error;
if (g_isi_request_make(dev->client, msg, sizeof(msg), if (g_isi_request_make(dev->client, msg, sizeof(msg),

View File

@ -515,7 +515,7 @@ static void isi_gprs_activate_primary(struct ofono_gprs_context *gc,
struct context_data *cd = g_try_new0(struct context_data, 1); struct context_data *cd = g_try_new0(struct context_data, 1);
struct context_data *old = NULL; struct context_data *old = NULL;
if (!cd) if (!gcd || !cd)
return; return;
cd->cid = ctx->cid; cd->cid = ctx->cid;
@ -599,6 +599,9 @@ static void isi_gprs_deactivate_primary(struct ofono_gprs_context *gc,
0x00, /* GPDS context ID, added later */ 0x00, /* GPDS context ID, added later */
}; };
if (!gcd)
return;
cd = find_context_by_cid(gcd->contexts, cid); cd = find_context_by_cid(gcd->contexts, cid);
if (!cd) { if (!cd) {
DBG("unknown context: %u", cid); DBG("unknown context: %u", cid);

View File

@ -286,7 +286,7 @@ static void isi_gprs_set_attached(struct ofono_gprs *gprs, int attached,
GIsiRequest *req; GIsiRequest *req;
if (!cbd) if (!cbd || !gd)
goto error; goto error;
if (attached) if (attached)
@ -356,7 +356,7 @@ static void isi_gprs_attached_status(struct ofono_gprs *gprs,
GPDS_STATUS_REQ, GPDS_STATUS_REQ,
}; };
if (!cbd) if (!cbd || !gd)
goto error; goto error;
if (g_isi_send(gd->client, msg, sizeof(msg), GPDS_TIMEOUT, if (g_isi_send(gd->client, msg, sizeof(msg), GPDS_TIMEOUT,

View File

@ -34,7 +34,6 @@ static inline struct isi_cb_data *isi_cb_data_new(void *user, void *cb,
struct isi_cb_data *ret; struct isi_cb_data *ret;
ret = g_try_new0(struct isi_cb_data, 1); ret = g_try_new0(struct isi_cb_data, 1);
if (ret) { if (ret) {
ret->cb = cb; ret->cb = cb;
ret->data = data; ret->data = data;

View File

@ -263,7 +263,7 @@ static void isi_registration_status(struct ofono_netreg *netreg,
NET_REG_STATUS_GET_REQ NET_REG_STATUS_GET_REQ
}; };
if (!cbd) if (!cbd || !nd)
goto error; goto error;
if (g_isi_request_make(nd->client, msg, sizeof(msg), if (g_isi_request_make(nd->client, msg, sizeof(msg),
@ -368,7 +368,7 @@ static void isi_current_operator(struct ofono_netreg *netreg,
0x00 /* No sub-blocks */ 0x00 /* No sub-blocks */
}; };
if (!cbd) if (!cbd || !nd)
goto error; goto error;
if (g_isi_request_make(nd->client, msg, sizeof(msg), if (g_isi_request_make(nd->client, msg, sizeof(msg),
@ -490,7 +490,7 @@ static void isi_list_operators(struct ofono_netreg *netreg,
0x00 0x00
}; };
if (!cbd) if (!cbd || !net)
goto error; goto error;
if (g_isi_request_make(net->client, msg, sizeof(msg), if (g_isi_request_make(net->client, msg, sizeof(msg),
@ -556,7 +556,7 @@ static void isi_register_auto(struct ofono_netreg *netreg,
0x00 /* Index not used */ 0x00 /* Index not used */
}; };
if (!cbd) if (!cbd || !net)
goto error; goto error;
if (g_isi_request_make(net->client, msg, sizeof(msg), if (g_isi_request_make(net->client, msg, sizeof(msg),
@ -629,7 +629,7 @@ static void isi_register_manual(struct ofono_netreg *netreg,
0x00, 0x00 /* Filler */ 0x00, 0x00 /* Filler */
}; };
if (!cbd) if (!cbd || !nd)
goto error; goto error;
if (g_isi_request_make(nd->client, msg, sizeof(msg), if (g_isi_request_make(nd->client, msg, sizeof(msg),
@ -876,7 +876,7 @@ static void isi_strength(struct ofono_netreg *netreg,
NET_CURRENT_CELL_RSSI NET_CURRENT_CELL_RSSI
}; };
if (!cbd) if (!cbd || !nd)
goto error; goto error;
if (g_isi_request_make(nd->client, msg, sizeof(msg), if (g_isi_request_make(nd->client, msg, sizeof(msg),

View File

@ -259,7 +259,7 @@ static void isi_export_entries(struct ofono_phonebook *pb, const char *storage,
0, 0 /* filler */ 0, 0 /* filler */
}; };
if (!cbd) if (!cbd || !pbd)
goto error; goto error;
if (strcmp(storage, "SM")) if (strcmp(storage, "SM"))
@ -335,10 +335,12 @@ static void isi_phonebook_remove(struct ofono_phonebook *pb)
{ {
struct pb_data *data = ofono_phonebook_get_data(pb); struct pb_data *data = ofono_phonebook_get_data(pb);
if (data) { if (!data)
g_isi_client_destroy(data->client); return;
g_free(data);
} ofono_phonebook_set_data(pb, NULL);
g_isi_client_destroy(data->client);
g_free(data);
} }
static struct ofono_phonebook_driver driver = { static struct ofono_phonebook_driver driver = {

View File

@ -154,7 +154,7 @@ static void isi_query_rat_mode(struct ofono_radio_settings *rs,
0x00 /* subblock count */ 0x00 /* subblock count */
}; };
if (!cbd) if (!cbd || !rd)
goto error; goto error;
if (g_isi_request_make(rd->client, msg, sizeof(msg), GSS_TIMEOUT, if (g_isi_request_make(rd->client, msg, sizeof(msg), GSS_TIMEOUT,
@ -221,7 +221,7 @@ static void isi_set_rat_mode(struct ofono_radio_settings *rs,
0x00 /* filler */ 0x00 /* filler */
}; };
if (!cbd) if (!cbd || !rd)
goto error; goto error;
if (isi_mode == -1) if (isi_mode == -1)
@ -297,9 +297,11 @@ static void isi_radio_settings_remove(struct ofono_radio_settings *rs)
{ {
struct radio_data *rd = ofono_radio_settings_get_data(rs); struct radio_data *rd = ofono_radio_settings_get_data(rs);
if (rd->client) if (!rd)
g_isi_client_destroy(rd->client); return;
ofono_radio_settings_set_data(rs, NULL);
g_isi_client_destroy(rd->client);
g_free(rd); g_free(rd);
} }

View File

@ -156,6 +156,9 @@ static gboolean isi_read_spn(struct ofono_sim *sim, struct isi_cb_data *cbd)
0 0
}; };
if (!sd)
return FALSE;
return g_isi_request_make(sd->client, msg, sizeof(msg), return g_isi_request_make(sd->client, msg, sizeof(msg),
SIM_TIMEOUT, spn_resp_cb, cbd) != NULL; SIM_TIMEOUT, spn_resp_cb, cbd) != NULL;
} }
@ -197,6 +200,9 @@ static gboolean isi_read_iccid(struct ofono_sim *sim, struct isi_cb_data *cbd)
struct sim_data *sd = ofono_sim_get_data(sim); struct sim_data *sd = ofono_sim_get_data(sim);
const unsigned char req[] = { SIM_READ_FIELD_REQ, ICC }; const unsigned char req[] = { SIM_READ_FIELD_REQ, ICC };
if (!sd)
return FALSE;
return g_isi_request_make(sd->client, req, sizeof(req), SIM_TIMEOUT, return g_isi_request_make(sd->client, req, sizeof(req), SIM_TIMEOUT,
read_iccid_resp_cb, cbd) != NULL; read_iccid_resp_cb, cbd) != NULL;
} }
@ -337,11 +343,10 @@ static void isi_read_imsi(struct ofono_sim *sim,
READ_IMSI READ_IMSI
}; };
if (!cbd) if (!cbd || !sd)
goto error; goto error;
if (g_isi_request_make(sd->client, msg, sizeof(msg), if (g_isi_request_make(sd->client, msg, sizeof(msg), SIM_TIMEOUT,
SIM_TIMEOUT,
imsi_resp_cb, cbd)) imsi_resp_cb, cbd))
return; return;

View File

@ -111,7 +111,7 @@ static void isi_sca_query(struct ofono_sms *sms,
1, /* Location, default is 1 */ 1, /* Location, default is 1 */
}; };
if (!cbd) if (!cbd || !sd)
goto error; goto error;
if (g_isi_request_make(sd->sim, msg, sizeof(msg), SIM_TIMEOUT, if (g_isi_request_make(sd->sim, msg, sizeof(msg), SIM_TIMEOUT,
@ -177,7 +177,7 @@ static void isi_sca_set(struct ofono_sms *sms,
{ filler, 38 }, { filler, 38 },
}; };
if (!cbd) if (!cbd || !sd)
goto error; goto error;
encode_bcd_number(sca->number, bcd + 2); encode_bcd_number(sca->number, bcd + 2);
@ -313,7 +313,7 @@ static void isi_submit(struct ofono_sms *sms, unsigned char *pdu,
{ sca, sca_len }, { sca, sca_len },
}; };
if (!cbd) if (!cbd || !sd)
goto error; goto error;
if (g_isi_request_vmake(sd->client, iov, use_default ? 2 : 4, SMS_TIMEOUT, if (g_isi_request_vmake(sd->client, iov, use_default ? 2 : 4, SMS_TIMEOUT,
@ -564,17 +564,16 @@ static void isi_sms_remove(struct ofono_sms *sms)
if (!data) if (!data)
return; return;
if (data->client) { ofono_sms_set_data(sms, NULL);
/* Send a promiscuous routing release, so as not to
* hog resources unnecessarily after being removed */
g_isi_request_make(data->client, msg, sizeof(msg),
SMS_TIMEOUT, NULL, NULL);
g_isi_client_destroy(data->client);
}
if (data->sim)
g_isi_client_destroy(data->sim);
/*
* Send a promiscuous routing release, so as not to
* hog resources unnecessarily after being removed
*/
g_isi_request_make(data->client, msg, sizeof(msg),
SMS_TIMEOUT, NULL, NULL);
g_isi_client_destroy(data->client);
g_isi_client_destroy(data->sim);
g_free(data); g_free(data);
} }

View File

@ -67,10 +67,12 @@ static void isi_ssn_remove(struct ofono_ssn *ssn)
{ {
struct ssn_data *data = ofono_ssn_get_data(ssn); struct ssn_data *data = ofono_ssn_get_data(ssn);
if (data) { if (!data)
g_isi_client_destroy(data->client); return;
g_free(data);
} ofono_ssn_set_data(ssn, NULL);
g_isi_client_destroy(data->client);
g_free(data);
} }
static struct ofono_ssn_driver driver = { static struct ofono_ssn_driver driver = {

View File

@ -181,7 +181,7 @@ static void isi_request(struct ofono_ussd *ussd, int dcs,
{ (uint8_t *)pdu, len } { (uint8_t *)pdu, len }
}; };
if (!cbd) if (!cbd || !ud)
goto error; goto error;
if (g_isi_vsend(ud->client, iov, 2, SS_TIMEOUT, if (g_isi_vsend(ud->client, iov, 2, SS_TIMEOUT,
@ -205,7 +205,7 @@ static void isi_cancel(struct ofono_ussd *ussd,
0x00 /* subblock count */ 0x00 /* subblock count */
}; };
if (!cbd) if (!cbd || !ud)
goto error; goto error;
if (g_isi_send(ud->client, msg, sizeof(msg), SS_TIMEOUT, if (g_isi_send(ud->client, msg, sizeof(msg), SS_TIMEOUT,

View File

@ -1303,10 +1303,12 @@ static void isi_voicecall_remove(struct ofono_voicecall *call)
{ {
struct isi_voicecall *data = ofono_voicecall_get_data(call); struct isi_voicecall *data = ofono_voicecall_get_data(call);
if (data) { if (!data)
g_isi_client_destroy(data->client); return;
g_free(data);
} ofono_voicecall_set_data(call, NULL);
g_isi_client_destroy(data->client);
g_free(data);
} }
static struct ofono_voicecall_driver driver = { static struct ofono_voicecall_driver driver = {