Re: [PATCH 20/24] stk: don't rely on undefined behavior when casting function pointers

2016-04-22 Thread Denis Kenzior

Hi John,

On 04/22/2016 08:10 AM, John Ernberg wrote:

From: John Ernberg 

---
  src/stk.c | 10 +++---
  1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/src/stk.c b/src/stk.c
index 01c95b5..16c7152 100644
--- a/src/stk.c
+++ b/src/stk.c
@@ -2315,8 +2315,7 @@ static gboolean handle_command_refresh(const struct 
stk_command *cmd,
break;
}

-   g_slist_foreach(file_list, (GFunc) g_free, NULL);
-   g_slist_free(file_list);
+   g_slist_free_full(file_list, g_free);

return FALSE;
}
@@ -3131,6 +3130,11 @@ void ofono_stk_driver_unregister(const struct 
ofono_stk_driver *d)
g_drivers = g_slist_remove(g_drivers, (void *) d);
  }

+static void free_envelope_item(gpointer pointer, gpointer user_data)
+{
+   g_free(pointer);
+}
+
  static void stk_unregister(struct ofono_atom *atom)
  {
struct ofono_stk *stk = __ofono_atom_get_data(atom);
@@ -3163,7 +3167,7 @@ static void stk_unregister(struct ofono_atom *atom)
stk->main_menu = NULL;
}

-   g_queue_foreach(stk->envelope_q, (GFunc) g_free, NULL);
+   g_queue_foreach(stk->envelope_q, free_envelope_item, NULL);


Why not g_queue_free_full?


g_queue_free(stk->envelope_q);

ofono_modem_remove_interface(modem, OFONO_STK_INTERFACE);



Regards,
-Denis
___
ofono mailing list
ofono@ofono.org
https://lists.ofono.org/mailman/listinfo/ofono


Re: [PATCH 00/24] [RFC] Don't rely on undefined behavior when casting function pointers

2016-04-22 Thread Denis Kenzior

Hi John,

On 04/22/2016 08:10 AM, John Ernberg wrote:

From: John Ernberg 

Casting between incompatible function pointer types is undefined.
While it works fine on x86, it's not a good idea to depend on this.

This RFC uses g_slist_free_full where possible, and when it's not works around
the casting using other means such as wrappers or fixing function parameters.



I applied all of these except patch 20.  See my comments in the relevant 
reply.


Thanks for doing all the work.

Regards,
-Denis

___
ofono mailing list
ofono@ofono.org
https://lists.ofono.org/mailman/listinfo/ofono


Re: [PATCH 4/5] push notification: track and clean up atom watches

2016-04-22 Thread Denis Kenzior

Hi John,

On 04/22/2016 08:07 AM, John Ernberg wrote:

From: John Ernberg 

Prevents glib from causing SIGFPE during certain circumstances of modem
removal.


Do you have a stack trace handy?


---
  plugins/push-notification.c | 26 +++---
  1 file changed, 23 insertions(+), 3 deletions(-)

diff --git a/plugins/push-notification.c b/plugins/push-notification.c
index ff388d9..ecf100f 100644
--- a/plugins/push-notification.c
+++ b/plugins/push-notification.c
@@ -45,6 +45,7 @@
  #define WAP_PUSH_DST_PORT 2948

  static unsigned int modemwatch_id;
+static GHashTable *sms_watches = NULL;

  struct push_notification {
struct ofono_modem *modem;
@@ -164,6 +165,16 @@ static void push_notification_cleanup(gpointer user)
ofono_modem_remove_interface(pn->modem, PUSH_NOTIFICATION_INTERFACE);
  }

+static gboolean atom_watch_remove(gpointer key, gpointer value,
+   gpointer user_data)
+{
+   struct ofono_modem *modem = key;
+
+   __ofono_modem_remove_atom_watch(modem, GPOINTER_TO_UINT(value));
+
+   return TRUE;
+}
+
  static void sms_watch(struct ofono_atom *atom,
enum ofono_atom_watch_condition cond,
void *data)
@@ -197,18 +208,22 @@ static void sms_watch(struct ofono_atom *atom,
  static void modem_watch(struct ofono_modem *modem, gboolean added, void *user)
  {
struct push_notification *pn;
+   int sms;
DBG("modem: %p, added: %d", modem, added);

-   if (added == FALSE)
+   if (added == FALSE) {
+   g_hash_table_remove(sms_watches, modem);
return;
+   }


This has no effect.  The atom_watches for that particular modem have 
already been freed by the time the modem watch has been called in 
call_modemwatches().  See modem_unregister for details.




pn = g_try_new0(struct push_notification, 1);
if (pn == NULL)
return;

pn->modem = modem;
-   __ofono_modem_add_atom_watch(modem, OFONO_ATOM_TYPE_SMS,
-   sms_watch, pn, g_free);
+   sms = __ofono_modem_add_atom_watch(modem, OFONO_ATOM_TYPE_SMS,
+   sms_watch, pn, g_free);
+   g_hash_table_insert(sms_watches, modem, GUINT_TO_POINTER(sms));
  }

  static void call_modemwatch(struct ofono_modem *modem, void *user)
@@ -220,6 +235,8 @@ static int push_notification_init(void)
  {
DBG("");

+   sms_watches = g_hash_table_new(g_direct_hash, g_direct_equal);
+
modemwatch_id = __ofono_modemwatch_add(modem_watch, NULL, NULL);

__ofono_modem_foreach(call_modemwatch, NULL);
@@ -232,6 +249,9 @@ static void push_notification_exit(void)
DBG("");

__ofono_modemwatch_remove(modemwatch_id);
+
+   g_hash_table_foreach_remove(sms_watches, atom_watch_remove, NULL);
+   g_hash_table_destroy(sms_watches);


atom watches are already being removed by the virtue of modems being 
unregistered.



  }

  OFONO_PLUGIN_DEFINE(push_notification, "Push Notification Plugin", VERSION,



Regards,
-Denis
___
ofono mailing list
ofono@ofono.org
https://lists.ofono.org/mailman/listinfo/ofono


Re: [PATCH 1/5] modem: clean up atoms on modem_unregister

2016-04-22 Thread Denis Kenzior

Hi John,

On 04/22/2016 08:07 AM, John Ernberg wrote:

From: John Ernberg 

This resolves a crash that can happen when a e.g. usb modem is removed.
---
  src/modem.c | 3 +++
  1 file changed, 3 insertions(+)

diff --git a/src/modem.c b/src/modem.c
index a89fa48..4968839 100644
--- a/src/modem.c
+++ b/src/modem.c
@@ -2071,6 +2071,9 @@ static void modem_unregister(struct ofono_modem *modem)
if (modem->powered == TRUE)
set_powered(modem, FALSE);



So in theory, set_powered calls flush_atoms...


+   if (modem->atoms)
+   flush_atoms(modem, MODEM_STATE_POWER_OFF);
+


So why is this needed?

Do you have a stack trace handy?


__ofono_watchlist_free(modem->atom_watches);
modem->atom_watches = NULL;




Regards,
-Denis
___
ofono mailing list
ofono@ofono.org
https://lists.ofono.org/mailman/listinfo/ofono


Re: [PATCH] plugins/ril: Move GPRS atom creating to 'post_online' state

2016-04-22 Thread Denis Kenzior

Hi Caiwen,

On 04/21/2016 03:15 AM, caiwen.zh...@intel.com wrote:

From: Caiwen Zhang 

At gprs atom 'probe' state, max cid query may fail due to rild
status isn't RADIO_STATUS_ON. It causes gprs atom is removed, gprs
feature is inavailable. Move gprs atom creating to 'post_online'
state to make sure rild status is RADIO_STATUS_ON when query max
cid.
---
  plugins/ril.c | 36 +---
  1 file changed, 17 insertions(+), 19 deletions(-)



Applied, thanks.

Regards,
-Denis

___
ofono mailing list
ofono@ofono.org
https://lists.ofono.org/mailman/listinfo/ofono


Re: [PATCH] voicecall: limit g_drivers variable exposure

2016-04-22 Thread Denis Kenzior

Hi John,

On 04/22/2016 08:06 AM, John Ernberg wrote:

From: John Ernberg 

---
  src/voicecall.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)



Applied, thanks.

Regards,
-Denis

___
ofono mailing list
ofono@ofono.org
https://lists.ofono.org/mailman/listinfo/ofono


Re: [PATCH] voicecall: fix CreateMultiparty method introspection

2016-04-22 Thread Denis Kenzior

Hi John,

On 04/22/2016 08:06 AM, John Ernberg wrote:

From: John Ernberg 

This caused problems with stricter dbus wrappers such as dbus-c++.

---
  src/voicecall.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)



Applied, thanks.

Regards,
-Denis

___
ofono mailing list
ofono@ofono.org
https://lists.ofono.org/mailman/listinfo/ofono


Re: [PATCH 1/2] rilmodem: Add address to protocol type util func

2016-04-22 Thread Denis Kenzior

Hi Nishanth,

On 04/21/2016 10:25 PM, Nishanth V wrote:

---
  drivers/rilmodem/rilutil.c | 27 +++
  drivers/rilmodem/rilutil.h |  2 ++
  2 files changed, 29 insertions(+)



Applied, thanks.

Regards,
-Denis

___
ofono mailing list
ofono@ofono.org
https://lists.ofono.org/mailman/listinfo/ofono


Re: [PATCH 2/2] rilmodem: Add IPv6 support in gprs-context

2016-04-22 Thread Denis Kenzior

Hi Nishanth,

On 04/21/2016 10:25 PM, Nishanth V wrote:

---
  drivers/rilmodem/gprs-context.c | 251 +++-
  1 file changed, 225 insertions(+), 26 deletions(-)



Applied, thanks.

Regards,
-Denis

___
ofono mailing list
ofono@ofono.org
https://lists.ofono.org/mailman/listinfo/ofono


Re: Ublox Toby Modem

2016-04-22 Thread Dragos Tatulea
Hi Yorn,

On 04/22/2016 01:51 PM, Yorn wrote:
> Hi Dragos,
> 
> many thanks for all the effort! Comments inline:
> 
> Am 22.04.2016 um 12:23 schrieb Dragos Tatulea:
>> Hi Yorn,
>>
>> On 04/21/2016 08:37 PM, Yorn wrote:
>>> Hi Dragos
>>>
>>> Am 21.04.2016 um 11:03 schrieb Dragos Tatulea:
 Hi Yarn,

 On 04/20/2016 07:54 PM, Yorn wrote:
> Hi Dragos,
>
> logs + comments inline
>
> Am 20.04.2016 um 17:01 schrieb Dragos Tatulea:
>> Hi Yorn,
>>
>> On 04/20/2016 04:24 PM, Yorn wrote:
>>> Hi Dragos,
>>>
>>> it is still active=0 :(
>>>
>>> root@colibri-vf:~/test# ./list-contexts
>>> [ /ublox_0 ]
>>>[ /ublox_0/context1 ]
>>>Username =
>>>AuthenticationMethod = chap
>>>Protocol = ip
>>>Name = Internet
>>>Settings = { }
>>>IPv6.Settings = { }
>>>Active = 0
>>>AccessPointName =
>>>Password =
>>>Type = internet
>>>
>> Can you run only oFono (no connman) with OFONO_AT_DEBUG env variable set
>> and run the following scripts:
>>
>> enable-modem
>> online-modem
>> activate-context
>>
>> Then send the logs.
> Here they are [1]
>>> I am actually a bit lost in the ublox AT Commands manual..
>>>
>>> Do you have a chance to see something at the ofonod+AT logs with your 
>>> expertice!?
>>>
>> oFono was able to register on the network an activate the context. This
>> part is interesting for you:
>>
>> ofonod[369]: drivers/ubloxmodem/gprs-context.c:ublox_gprs_activate_primary() 
>> cid 1
>> ofonod[369]: Aux: > AT\r
>> ofonod[369]: Aux: < \r\nOK\r\n
>> ofonod[369]: Aux: Finally woke up the modem
>> ofonod[369]: Aux: > AT+CGDCONT=1,"IP","m2m.tele2.com"\r
>> *> context defined
>>
>> ofonod[369]: Aux: < \r\nOK\r\n
>> ofonod[369]: drivers/ubloxmodem/gprs-context.c:cgdcont_cb() ok 1
>> ofonod[369]: Aux: > AT+CGACT=1,1\r
>> *> context activated
>>
>> ofonod[369]: Aux: < \r\nOK\r\n
>> ofonod[369]: drivers/ubloxmodem/gprs-context.c:cgact_enable_cb() ok 1
>> ofonod[369]: Aux: > AT+CGCONTRDP=1\r
>> ofonod[369]: Aux: < \r\n+CREG: 5,"","0010",4\r\n\r\n+CGEV: ME PDN 
>> ACT 1\r\n
>> ofonod[369]: src/network.c:ofono_netreg_status_notify() /ublox_0 status 5 
>> tech 4
>> ofonod[369]: src/gprs.c:netreg_status_changed() 5
>> ofonod[369]: src/gprs.c:gprs_netreg_update() attach: 1, driver_attached: 1
>> ofonod[369]: Aux: < \r\n+CGCONTRDP: 1,0,"m2m.tele2.com","
>> ofonod[369]: Aux: < 
>> 100.98.55.207.255.255.255.255","100.98.55.207","130.244.127.161","130.244.127.169","0.0.0.0","0.0.0.0",0\r\n
>> ofonod[369]: Aux: < \r\nOK\r\n
>> *> connection properties read successfully
>>
>> ofonod[369]: drivers/ubloxmodem/gprs-context.c:cgcontrdp_cb() ok 1
>> ofonod[369]: src/modem.c:get_modem_property() modem 0x192a900 property 
>> NetworkInterface
>>
>>> The connman cellular service is set to "a" (association) from starting
>>> connect cellular_240075810199181_context1
>>> up until timeout.
>>>
>> Do you still run the oFono scripts? From the logs it looks like connman
>> is trying to activate an already active context.
> The technologie and the service is running, but the association does not end 
> successfully. Do I need to set something else in connman? Where do I have to 
> look?
> 
> The try to connect ends up with:
> Error /net/connman/service/cellular_240075810199181_context1: Did not receive 
> a reply. Possible causes include: the remote application did not send a 
> reply, the message bus security policy blocked the reply, the reply timeout 
> expired, or the network connection was broken.
> 
Can you send the connman logs as well? I'm not really sure what's
happening here.

Thanks
-- 
Dragos Tatulea
Software Developer @ Endocode AG
dra...@endocode.com

Endocode AG, Brückenstraße 5A, 10179 Berlin
+49 30 1206 4472 | i...@endocode.com | www.endocode.com

Vorstandsvorsitzender: Mirko Boehm
Vorstände: Dr. Thomas Fricke, Sebastian Sucker
Aufsichtsratsvorsitzende: Alexandra Boehm

Registergericht: Amtsgericht Charlottenburg - HRB 150748 B
___
ofono mailing list
ofono@ofono.org
https://lists.ofono.org/mailman/listinfo/ofono


[PATCH 23/24] voicecall: don't rely on undefined behavior when casting function pointers

2016-04-22 Thread John Ernberg
From: John Ernberg 

---
 src/voicecall.c | 7 ++-
 1 file changed, 2 insertions(+), 5 deletions(-)

diff --git a/src/voicecall.c b/src/voicecall.c
index c9b1b43..027f03e 100644
--- a/src/voicecall.c
+++ b/src/voicecall.c
@@ -2534,9 +2534,7 @@ static void free_sim_ecc_numbers(struct ofono_voicecall 
*vc, gboolean old_only)
 */
if (old_only == FALSE) {
if (vc->new_sim_en_list) {
-   g_slist_foreach(vc->new_sim_en_list, (GFunc) g_free,
-   NULL);
-   g_slist_free(vc->new_sim_en_list);
+   g_slist_free_full(vc->new_sim_en_list, g_free);
vc->new_sim_en_list = NULL;
}
 
@@ -2544,8 +2542,7 @@ static void free_sim_ecc_numbers(struct ofono_voicecall 
*vc, gboolean old_only)
}
 
if (vc->sim_en_list) {
-   g_slist_foreach(vc->sim_en_list, (GFunc) g_free, NULL);
-   g_slist_free(vc->sim_en_list);
+   g_slist_free_full(vc->sim_en_list, g_free);
vc->sim_en_list = NULL;
}
 }
-- 
1.9.1
___
ofono mailing list
ofono@ofono.org
https://lists.ofono.org/mailman/listinfo/ofono


[PATCH 17/24] simutil: don't rely on undefined behavior when casting function pointers

2016-04-22 Thread John Ernberg
From: John Ernberg 

---
 src/simutil.c | 6 ++
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/src/simutil.c b/src/simutil.c
index 5f8c8b8..4731d3b 100644
--- a/src/simutil.c
+++ b/src/simutil.c
@@ -980,8 +980,7 @@ void sim_spdi_free(struct sim_spdi *spdi)
if (spdi == NULL)
return;
 
-   g_slist_foreach(spdi->operators, (GFunc)g_free, NULL);
-   g_slist_free(spdi->operators);
+   g_slist_free_full(spdi->operators, g_free);
g_free(spdi);
 }
 
@@ -1088,8 +1087,7 @@ void sim_eons_free(struct sim_eons *eons)
 
g_free(eons->pnn_list);
 
-   g_slist_foreach(eons->opl_list, (GFunc)g_free, NULL);
-   g_slist_free(eons->opl_list);
+   g_slist_free_full(eons->opl_list, g_free);
 
g_free(eons);
 }
-- 
1.9.1
___
ofono mailing list
ofono@ofono.org
https://lists.ofono.org/mailman/listinfo/ofono


[PATCH 19/24] smsutil: don't rely on undefined behavior when casting function pointers

2016-04-22 Thread John Ernberg
From: John Ernberg 

---
 src/smsutil.c | 21 +++--
 1 file changed, 7 insertions(+), 14 deletions(-)

diff --git a/src/smsutil.c b/src/smsutil.c
index 19e2016..b6f7348 100644
--- a/src/smsutil.c
+++ b/src/smsutil.c
@@ -2541,8 +2541,7 @@ void sms_assembly_free(struct sms_assembly *assembly)
for (l = assembly->assembly_list; l; l = l->next) {
struct sms_assembly_node *node = l->data;
 
-   g_slist_foreach(node->fragment_list, (GFunc) g_free, 0);
-   g_slist_free(node->fragment_list);
+   g_slist_free_full(node->fragment_list, g_free);
g_free(node);
}
 
@@ -2692,8 +2691,7 @@ void sms_assembly_expire(struct sms_assembly *assembly, 
time_t before)
 
sms_assembly_backup_free(assembly, node);
 
-   g_slist_foreach(node->fragment_list, (GFunc) g_free, 0);
-   g_slist_free(node->fragment_list);
+   g_slist_free_full(node->fragment_list, g_free);
g_free(node);
 
if (prev)
@@ -3506,8 +3504,7 @@ GSList *sms_datagram_prepare(const char *to,
}
 
if (left > 0) {
-   g_slist_foreach(r, (GFunc) g_free, NULL);
-   g_slist_free(r);
+   g_slist_free_full(r, g_free);
 
return NULL;
} else {
@@ -3698,8 +3695,7 @@ GSList *sms_text_prepare_with_alphabet(const char *to, 
const char *utf8,
g_free(ucs2_encoded);
 
if (left > 0) {
-   g_slist_foreach(r, (GFunc) g_free, NULL);
-   g_slist_free(r);
+   g_slist_free_full(r, g_free);
 
return NULL;
} else {
@@ -4214,8 +4210,7 @@ void cbs_assembly_free(struct cbs_assembly *assembly)
for (l = assembly->assembly_list; l; l = l->next) {
struct cbs_assembly_node *node = l->data;
 
-   g_slist_foreach(node->pages, (GFunc) g_free, 0);
-   g_slist_free(node->pages);
+   g_slist_free_full(node->pages, g_free);
g_free(node);
}
 
@@ -4294,8 +4289,7 @@ static void cbs_assembly_expire(struct cbs_assembly 
*assembly,
else
assembly->assembly_list = l->next;
 
-   g_slist_foreach(node->pages, (GFunc) g_free, NULL);
-   g_slist_free(node->pages);
+   g_slist_free_full(node->pages, g_free);
g_free(node->pages);
tmp = l;
l = l->next;
@@ -4604,8 +4598,7 @@ GSList *cbs_extract_topic_ranges(const char *ranges)
}
 
tmp = cbs_optimize_ranges(ret);
-   g_slist_foreach(ret, (GFunc) g_free, NULL);
-   g_slist_free(ret);
+   g_slist_free_full(ret, g_free);
 
return tmp;
 }
-- 
1.9.1
___
ofono mailing list
ofono@ofono.org
https://lists.ofono.org/mailman/listinfo/ofono


[PATCH 24/24] unittest: don't rely on undefined behavior when casting function pointers

2016-04-22 Thread John Ernberg
From: John Ernberg 

---
 unit/test-sms.c | 21 +++--
 1 file changed, 7 insertions(+), 14 deletions(-)

diff --git a/unit/test-sms.c b/unit/test-sms.c
index 259594e..3d0f016 100644
--- a/unit/test-sms.c
+++ b/unit/test-sms.c
@@ -1132,8 +1132,7 @@ static void test_assembly(void)
 
utf8 = sms_decode_text(l);
 
-   g_slist_foreach(l, (GFunc)g_free, NULL);
-   g_slist_free(l);
+   g_slist_free_full(l, g_free);
 
sms_assembly_free(assembly);
 
@@ -1214,8 +1213,7 @@ static void test_prepare_7bit(void)
g_assert(strcmp(expected_no_fragmentation_7bit, encoded_pdu) == 0);
 
g_free(encoded_pdu);
-   g_slist_foreach(r, (GFunc)g_free, NULL);
-   g_slist_free(r);
+   g_slist_free_full(r, g_free);
 }
 
 struct sms_concat_data {
@@ -1273,8 +1271,7 @@ static void test_prepare_concat(gconstpointer data)
pdus = g_slist_append(pdus, strpdu);
}
 
-   g_slist_foreach(r, (GFunc)g_free, NULL);
-   g_slist_free(r);
+   g_slist_free_full(r, g_free);
 
for (l = pdus; l; l = l->next) {
long len;
@@ -1474,16 +1471,14 @@ static void test_cbs_assembly(void)
l = cbs_assembly_add_page(assembly, &dec1);
g_assert(l);
g_assert(g_slist_length(assembly->recv_cell) == 1);
-   g_slist_foreach(l, (GFunc)g_free, NULL);
-   g_slist_free(l);
+   g_slist_free_full(l, g_free);
 
/* Can we receive new updates ? */
dec1.update_number = 8;
l = cbs_assembly_add_page(assembly, &dec1);
g_assert(l);
g_assert(g_slist_length(assembly->recv_cell) == 1);
-   g_slist_foreach(l, (GFunc)g_free, NULL);
-   g_slist_free(l);
+   g_slist_free_full(l, g_free);
 
/* Do we ignore old pages ? */
l = cbs_assembly_add_page(assembly, &dec1);
@@ -1529,8 +1524,7 @@ static void test_cbs_assembly(void)
g_assert(strcmp(utf8, "BelconnenFraserBelconnen") == 0);
 
g_free(utf8);
-   g_slist_foreach(l, (GFunc)g_free, NULL);
-   g_slist_free(l);
+   g_slist_free_full(l, g_free);
 
cbs_assembly_free(assembly);
 }
@@ -1621,8 +1615,7 @@ static void test_range_minimizer(void)
g_print("range: %s\n", rangestr);
 
g_free(rangestr);
-   g_slist_foreach(r, (GFunc)g_free, NULL);
-   g_slist_free(r);
+   g_slist_free_full(r, g_free);
}
 }
 
-- 
1.9.1
___
ofono mailing list
ofono@ofono.org
https://lists.ofono.org/mailman/listinfo/ofono


[PATCH 21/24] stkutil: don't rely on undefined behavior when casting function pointers

2016-04-22 Thread John Ernberg
From: John Ernberg 

---
 src/stkutil.c | 39 ---
 1 file changed, 12 insertions(+), 27 deletions(-)

diff --git a/src/stkutil.c b/src/stkutil.c
index a03e9b7..ec3f825 100644
--- a/src/stkutil.c
+++ b/src/stkutil.c
@@ -649,8 +649,7 @@ static gboolean parse_dataobj_file_list(struct 
comprehension_tlv_iter *iter,
return TRUE;
 
 error:
-   g_slist_foreach(*fl, (GFunc) g_free, NULL);
-   g_slist_free(*fl);
+   g_slist_free_full(*fl, g_free);
return FALSE;
 }
 
@@ -2253,8 +2252,9 @@ static dataobj_handler handler_for_type(enum 
stk_data_object_type type)
}
 }
 
-static void destroy_stk_item(struct stk_item *item)
+static void destroy_stk_item(gpointer pointer)
 {
+   struct stk_item *item = pointer;
g_free(item->text);
g_free(item);
 }
@@ -2297,8 +2297,7 @@ static gboolean parse_item_list(struct 
comprehension_tlv_iter *iter,
if (count == 1)
return TRUE;
 
-   g_slist_foreach(list, (GFunc) destroy_stk_item, NULL);
-   g_slist_free(list);
+   g_slist_free_full(list, destroy_stk_item);
return FALSE;
 
 }
@@ -2420,8 +2419,7 @@ static enum stk_command_parse_result parse_dataobj(
minimum_set = FALSE;
}
 
-   g_slist_foreach(entries, (GFunc) g_free, NULL);
-   g_slist_free(entries);
+   g_slist_free_full(entries, g_free);
 
if (minimum_set == FALSE)
return STK_PARSE_RESULT_MISSING_VALUE;
@@ -2624,9 +2622,7 @@ static enum stk_command_parse_result parse_poll_interval(
 static void destroy_setup_menu(struct stk_command *command)
 {
g_free(command->setup_menu.alpha_id);
-   g_slist_foreach(command->setup_menu.items,
-   (GFunc) destroy_stk_item, NULL);
-   g_slist_free(command->setup_menu.items);
+   g_slist_free_full(command->setup_menu.items, destroy_stk_item);
 }
 
 static enum stk_command_parse_result parse_setup_menu(
@@ -2671,9 +2667,7 @@ static enum stk_command_parse_result parse_setup_menu(
 static void destroy_select_item(struct stk_command *command)
 {
g_free(command->select_item.alpha_id);
-   g_slist_foreach(command->select_item.items,
-   (GFunc) destroy_stk_item, NULL);
-   g_slist_free(command->select_item.items);
+   g_slist_free_full(command->select_item.items, destroy_stk_item);
 }
 
 static enum stk_command_parse_result parse_select_item(
@@ -2948,8 +2942,7 @@ static enum stk_command_parse_result parse_setup_call(
 
 static void destroy_refresh(struct stk_command *command)
 {
-   g_slist_foreach(command->refresh.file_list, (GFunc) g_free, NULL);
-   g_slist_free(command->refresh.file_list);
+   g_slist_free_full(command->refresh.file_list, g_free);
g_free(command->refresh.alpha_id);
 }
 
@@ -3264,9 +3257,7 @@ static void destroy_launch_browser(struct stk_command 
*command)
 {
g_free(command->launch_browser.url);
g_free(command->launch_browser.bearer.array);
-   g_slist_foreach(command->launch_browser.prov_file_refs,
-   (GFunc) g_free, NULL);
-   g_slist_free(command->launch_browser.prov_file_refs);
+   g_slist_free_full(command->launch_browser.prov_file_refs, g_free);
g_free(command->launch_browser.text_gateway_proxy_id);
g_free(command->launch_browser.alpha_id);
g_free(command->launch_browser.network_name.array);
@@ -3652,9 +3643,7 @@ static enum stk_command_parse_result 
parse_get_frames_status(
 static void destroy_retrieve_mms(struct stk_command *command)
 {
g_free(command->retrieve_mms.alpha_id);
-   g_slist_foreach(command->retrieve_mms.mms_rec_files,
-   (GFunc) g_free, NULL);
-   g_slist_free(command->retrieve_mms.mms_rec_files);
+   g_slist_free_full(command->retrieve_mms.mms_rec_files, g_free);
 }
 
 static enum stk_command_parse_result parse_retrieve_mms(
@@ -3701,9 +3690,7 @@ static enum stk_command_parse_result parse_retrieve_mms(
 static void destroy_submit_mms(struct stk_command *command)
 {
g_free(command->submit_mms.alpha_id);
-   g_slist_foreach(command->submit_mms.mms_subm_files,
-   (GFunc) g_free, NULL);
-   g_slist_free(command->submit_mms.mms_subm_files);
+   g_slist_free_full(command->submit_mms.mms_subm_files, g_free);
 }
 
 static enum stk_command_parse_result parse_submit_mms(
@@ -3743,9 +3730,7 @@ static enum stk_command_parse_result parse_submit_mms(
 
 static void destroy_display_mms(struct stk_command *command)
 {
-   g_slist_foreach(command->display_mms.mms_subm_files,
-   (GFunc) g_free, NULL);
-   g_slist_free(command->display_mms.mms_subm_files);
+   g_slist_free_full(command->display_mms.mms_subm_files, g_free);
 }
 
 static enum stk_command_parse_result parse_display_mms(
-- 
1.9.1
__

[PATCH 18/24] sms: don't rely on undefined behavior when casting function pointers

2016-04-22 Thread John Ernberg
From: John Ernberg 

---
 src/sms.c | 9 +++--
 1 file changed, 3 insertions(+), 6 deletions(-)

diff --git a/src/sms.c b/src/sms.c
index 72972b2..17c5a9c 100644
--- a/src/sms.c
+++ b/src/sms.c
@@ -988,8 +988,7 @@ static DBusMessage *sms_send_message(DBusConnection *conn, 
DBusMessage *msg,
err = __ofono_sms_txq_submit(sms, msg_list, flags, &uuid,
message_queued, msg);
 
-   g_slist_foreach(msg_list, (GFunc) g_free, NULL);
-   g_slist_free(msg_list);
+   g_slist_free_full(msg_list, g_free);
 
if (err < 0)
return __ofono_error_failed(msg);
@@ -1425,8 +1424,7 @@ static void handle_deliver(struct ofono_sms *sms, const 
struct sms *incoming)
return;
 
sms_dispatch(sms, sms_list);
-   g_slist_foreach(sms_list, (GFunc) g_free, NULL);
-   g_slist_free(sms_list);
+   g_slist_free_full(sms_list, g_free);
 
return;
}
@@ -1946,8 +1944,7 @@ static void sms_restore_tx_queue(struct ofono_sms *sms)
g_queue_push_tail(sms->txq, txq_entry);
 
 loop_out:
-   g_slist_foreach(backup_entry->msg_list, (GFunc)g_free, NULL);
-   g_slist_free(backup_entry->msg_list);
+   g_slist_free_full(backup_entry->msg_list, g_free);
g_free(backup_entry);
}
 
-- 
1.9.1
___
ofono mailing list
ofono@ofono.org
https://lists.ofono.org/mailman/listinfo/ofono


[PATCH 20/24] stk: don't rely on undefined behavior when casting function pointers

2016-04-22 Thread John Ernberg
From: John Ernberg 

---
 src/stk.c | 10 +++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/src/stk.c b/src/stk.c
index 01c95b5..16c7152 100644
--- a/src/stk.c
+++ b/src/stk.c
@@ -2315,8 +2315,7 @@ static gboolean handle_command_refresh(const struct 
stk_command *cmd,
break;
}
 
-   g_slist_foreach(file_list, (GFunc) g_free, NULL);
-   g_slist_free(file_list);
+   g_slist_free_full(file_list, g_free);
 
return FALSE;
}
@@ -3131,6 +3130,11 @@ void ofono_stk_driver_unregister(const struct 
ofono_stk_driver *d)
g_drivers = g_slist_remove(g_drivers, (void *) d);
 }
 
+static void free_envelope_item(gpointer pointer, gpointer user_data)
+{
+   g_free(pointer);
+}
+
 static void stk_unregister(struct ofono_atom *atom)
 {
struct ofono_stk *stk = __ofono_atom_get_data(atom);
@@ -3163,7 +3167,7 @@ static void stk_unregister(struct ofono_atom *atom)
stk->main_menu = NULL;
}
 
-   g_queue_foreach(stk->envelope_q, (GFunc) g_free, NULL);
+   g_queue_foreach(stk->envelope_q, free_envelope_item, NULL);
g_queue_free(stk->envelope_q);
 
ofono_modem_remove_interface(modem, OFONO_STK_INTERFACE);
-- 
1.9.1
___
ofono mailing list
ofono@ofono.org
https://lists.ofono.org/mailman/listinfo/ofono


[PATCH 16/24] simfs: don't rely on undefined behavior when casting function pointers

2016-04-22 Thread John Ernberg
From: John Ernberg 

---
 src/simfs.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/src/simfs.c b/src/simfs.c
index 03c8c9e..595dbad 100644
--- a/src/simfs.c
+++ b/src/simfs.c
@@ -74,8 +74,9 @@ struct sim_fs_op {
struct ofono_sim_context *context;
 };
 
-static void sim_fs_op_free(struct sim_fs_op *node)
+static void sim_fs_op_free(gpointer pointer)
 {
+   struct sim_fs_op *node = pointer;
g_free(node->buffer);
g_free(node);
 }
@@ -105,8 +106,7 @@ void sim_fs_free(struct sim_fs *fs)
 * for operations still in progress
 */
if (fs->op_q) {
-   g_queue_foreach(fs->op_q, (GFunc) sim_fs_op_free, NULL);
-   g_queue_free(fs->op_q);
+   g_queue_free_full(fs->op_q, sim_fs_op_free);
fs->op_q = NULL;
}
 
-- 
1.9.1
___
ofono mailing list
ofono@ofono.org
https://lists.ofono.org/mailman/listinfo/ofono


[PATCH 11/24] handsfree: don't rely on undefined behavior when casting function pointers

2016-04-22 Thread John Ernberg
From: John Ernberg 

---
 src/handsfree.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/src/handsfree.c b/src/handsfree.c
index 31b9d7d..3b518fd 100644
--- a/src/handsfree.c
+++ b/src/handsfree.c
@@ -687,8 +687,7 @@ static void handsfree_unregister(struct ofono_atom *atom)
__ofono_dbus_pending_reply(&hf->pending, reply);
}
 
-   g_slist_foreach(hf->subscriber_numbers, (GFunc) g_free, NULL);
-   g_slist_free(hf->subscriber_numbers);
+   g_slist_free_full(hf->subscriber_numbers, g_free);
hf->subscriber_numbers = NULL;
 
ofono_modem_remove_interface(modem, OFONO_HANDSFREE_INTERFACE);
-- 
1.9.1
___
ofono mailing list
ofono@ofono.org
https://lists.ofono.org/mailman/listinfo/ofono


[PATCH 12/24] modem: don't rely on undefined behavior when casting function pointers

2016-04-22 Thread John Ernberg
From: John Ernberg 

---
 src/modem.c | 6 ++
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/src/modem.c b/src/modem.c
index a89fa48..b1e8d3e 100644
--- a/src/modem.c
+++ b/src/modem.c
@@ -2083,12 +2083,10 @@ static void modem_unregister(struct ofono_modem *modem)
modem->sim_watch = 0;
modem->sim_ready_watch = 0;
 
-   g_slist_foreach(modem->interface_list, (GFunc) g_free, NULL);
-   g_slist_free(modem->interface_list);
+   g_slist_free_full(modem->interface_list, g_free);
modem->interface_list = NULL;
 
-   g_slist_foreach(modem->feature_list, (GFunc) g_free, NULL);
-   g_slist_free(modem->feature_list);
+   g_slist_free_full(modem->feature_list, g_free);
modem->feature_list = NULL;
 
if (modem->timeout) {
-- 
1.9.1
___
ofono mailing list
ofono@ofono.org
https://lists.ofono.org/mailman/listinfo/ofono


[PATCH 22/24] ussd: don't rely on undefined behavior when casting function pointers

2016-04-22 Thread John Ernberg
From: John Ernberg 

---
 src/ussd.c | 10 +-
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/src/ussd.c b/src/ussd.c
index bc8e0f6..99fa753 100644
--- a/src/ussd.c
+++ b/src/ussd.c
@@ -102,8 +102,10 @@ static struct ssc_entry *ssc_entry_create(const char *sc, 
void *cb, void *data,
return r;
 }
 
-static void ssc_entry_destroy(struct ssc_entry *ca)
+static void ssc_entry_destroy(gpointer pointer)
 {
+   struct ssc_entry *ca = pointer;
+
if (ca->destroy)
ca->destroy(ca->user);
 
@@ -790,12 +792,10 @@ static void ussd_unregister(struct ofono_atom *atom)
struct ofono_modem *modem = __ofono_atom_get_modem(atom);
const char *path = __ofono_atom_get_path(atom);
 
-   g_slist_foreach(ussd->ss_control_list, (GFunc) ssc_entry_destroy, NULL);
-   g_slist_free(ussd->ss_control_list);
+   g_slist_free_full(ussd->ss_control_list, ssc_entry_destroy);
ussd->ss_control_list = NULL;
 
-   g_slist_foreach(ussd->ss_passwd_list, (GFunc) ssc_entry_destroy, NULL);
-   g_slist_free(ussd->ss_passwd_list);
+   g_slist_free_full(ussd->ss_passwd_list, ssc_entry_destroy);
ussd->ss_passwd_list = NULL;
 
ofono_modem_remove_interface(modem,
-- 
1.9.1
___
ofono mailing list
ofono@ofono.org
https://lists.ofono.org/mailman/listinfo/ofono


[PATCH 14/24] phonebook: don't rely on undefined behavior when casting function pointers

2016-04-22 Thread John Ernberg
From: John Ernberg 

---
 src/phonebook.c | 24 ++--
 1 file changed, 14 insertions(+), 10 deletions(-)

diff --git a/src/phonebook.c b/src/phonebook.c
index 531b5a6..07bfcae 100644
--- a/src/phonebook.c
+++ b/src/phonebook.c
@@ -233,23 +233,28 @@ static void vcard_printf_end(GString *vcards)
vcard_printf(vcards, "");
 }
 
-static void print_number(struct phonebook_number *pn, GString *vcards)
+static void print_number(gpointer pointer, gpointer user_data)
 {
+   struct phonebook_number *pn = pointer;
+   GString *vcards = user_data;
vcard_printf_number(vcards, pn->number, pn->type, pn->category);
 }
 
-static void destroy_number(struct phonebook_number *pn)
+static void destroy_number(gpointer pointer)
 {
+   struct phonebook_number *pn = pointer;
g_free(pn->number);
g_free(pn);
 }
 
-static void print_merged_entry(struct phonebook_person *person, GString 
*vcards)
+static void print_merged_entry(gpointer pointer, gpointer user_data)
 {
+   struct phonebook_person *person = pointer;
+   GString *vcards = user_data;
vcard_printf_begin(vcards);
vcard_printf_text(vcards, person->text);
 
-   g_slist_foreach(person->number_list, (GFunc) print_number, vcards);
+   g_slist_foreach(person->number_list, print_number, vcards);
 
vcard_printf_group(vcards, person->group);
vcard_printf_email(vcards, person->email);
@@ -257,15 +262,15 @@ static void print_merged_entry(struct phonebook_person 
*person, GString *vcards)
vcard_printf_end(vcards);
 }
 
-static void destroy_merged_entry(struct phonebook_person *person)
+static void destroy_merged_entry(gpointer pointer)
 {
+   struct phonebook_person *person = pointer;
g_free(person->text);
g_free(person->group);
g_free(person->email);
g_free(person->sip_uri);
 
-   g_slist_foreach(person->number_list, (GFunc) destroy_number, NULL);
-   g_slist_free(person->number_list);
+   g_slist_free_full(person->number_list, destroy_number);
 
g_free(person);
 }
@@ -419,10 +424,9 @@ static void export_phonebook_cb(const struct ofono_error 
*error, void *data)
 
/* convert the collected entries that are already merged to vcard */
phonebook->merge_list = g_slist_reverse(phonebook->merge_list);
-   g_slist_foreach(phonebook->merge_list, (GFunc) print_merged_entry,
+   g_slist_foreach(phonebook->merge_list, print_merged_entry,
phonebook->vcards);
-   g_slist_foreach(phonebook->merge_list, (GFunc) destroy_merged_entry,
-   NULL);
+   g_slist_free_full(phonebook->merge_list, destroy_merged_entry);
g_slist_free(phonebook->merge_list);
phonebook->merge_list = NULL;
 
-- 
1.9.1
___
ofono mailing list
ofono@ofono.org
https://lists.ofono.org/mailman/listinfo/ofono


[PATCH 15/24] sim: don't rely on undefined behavior when casting function pointers

2016-04-22 Thread John Ernberg
From: John Ernberg 

---
 src/sim.c | 29 ++---
 1 file changed, 10 insertions(+), 19 deletions(-)

diff --git a/src/sim.c b/src/sim.c
index bcf5afd..94d8840 100644
--- a/src/sim.c
+++ b/src/sim.c
@@ -321,8 +321,9 @@ static char **get_service_numbers(GSList *service_numbers)
return ret;
 }
 
-static void service_number_free(struct service_number *num)
+static void service_number_free(gpointer pointer)
 {
+   struct service_number *num = pointer;
g_free(num->id);
g_free(num);
 }
@@ -615,8 +616,7 @@ static DBusMessage *sim_set_property(DBusConnection *conn, 
DBusMessage *msg,
set_ok = set_own_numbers(sim, own_numbers, msg);
 
 error:
-   g_slist_foreach(own_numbers, (GFunc) g_free, 0);
-   g_slist_free(own_numbers);
+   g_slist_free_full(own_numbers, g_free);
 
if (set_ok)
return NULL;
@@ -1195,8 +1195,7 @@ check:
char **own_numbers;
DBusConnection *conn = ofono_dbus_get_connection();
 
-   g_slist_foreach(sim->own_numbers, (GFunc) g_free, NULL);
-   g_slist_free(sim->own_numbers);
+   g_slist_free_full(sim->own_numbers, g_free);
sim->own_numbers = sim->new_numbers;
 
own_numbers = get_own_numbers(sim->own_numbers);
@@ -1208,8 +1207,7 @@ check:
 
g_strfreev(own_numbers);
} else {
-   g_slist_foreach(sim->new_numbers, (GFunc) g_free, NULL);
-   g_slist_free(sim->new_numbers);
+   g_slist_free_full(sim->new_numbers, g_free);
}
 
sim->new_numbers = NULL;
@@ -1302,9 +1300,7 @@ static void sim_service_numbers_changed(int id, void 
*userdata)
struct ofono_sim *sim = userdata;
 
if (sim->service_numbers) {
-   g_slist_foreach(sim->service_numbers,
-   (GFunc)service_number_free, NULL);
-   g_slist_free(sim->service_numbers);
+   g_slist_free_full(sim->service_numbers, service_number_free);
sim->service_numbers = NULL;
}
 
@@ -2025,13 +2021,11 @@ skip_efpl:
}
 
if (efli) {
-   g_slist_foreach(efli, (GFunc)g_free, NULL);
-   g_slist_free(efli);
+   g_slist_free_full(efli, g_free);
}
 
if (efpl) {
-   g_slist_foreach(efpl, (GFunc)g_free, NULL);
-   g_slist_free(efpl);
+   g_slist_free_full(efpl, g_free);
}
 
if (sim->language_prefs != NULL)
@@ -2394,15 +2388,12 @@ static void sim_free_main_state(struct ofono_sim *sim)
sim->mnc[0] = '\0';
 
if (sim->own_numbers) {
-   g_slist_foreach(sim->own_numbers, (GFunc)g_free, NULL);
-   g_slist_free(sim->own_numbers);
+   g_slist_free_full(sim->own_numbers, g_free);
sim->own_numbers = NULL;
}
 
if (sim->service_numbers) {
-   g_slist_foreach(sim->service_numbers,
-   (GFunc)service_number_free, NULL);
-   g_slist_free(sim->service_numbers);
+   g_slist_free_full(sim->service_numbers, service_number_free);
sim->service_numbers = NULL;
sim->sdn_ready = FALSE;
}
-- 
1.9.1
___
ofono mailing list
ofono@ofono.org
https://lists.ofono.org/mailman/listinfo/ofono


[PATCH 13/24] network: don't rely on undefined behavior when casting function pointers

2016-04-22 Thread John Ernberg
From: John Ernberg 

---
 src/network.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/src/network.c b/src/network.c
index 8ad11d3..a3d41a7 100644
--- a/src/network.c
+++ b/src/network.c
@@ -746,8 +746,7 @@ static gboolean update_operator_list(struct ofono_netreg 
*netreg, int total,
}
}
 
-   g_slist_foreach(compressed, (GFunc)g_free, NULL);
-   g_slist_free(compressed);
+   g_slist_free_full(compressed, g_free);
 
if (n)
n = g_slist_reverse(n);
-- 
1.9.1
___
ofono mailing list
ofono@ofono.org
https://lists.ofono.org/mailman/listinfo/ofono


[PATCH 04/24] ril: don't rely on undefined behavior when casting function pointers

2016-04-22 Thread John Ernberg
From: John Ernberg 

---
 drivers/rilmodem/voicecall.c | 6 ++
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/drivers/rilmodem/voicecall.c b/drivers/rilmodem/voicecall.c
index 8515ebb..b7180b9 100644
--- a/drivers/rilmodem/voicecall.c
+++ b/drivers/rilmodem/voicecall.c
@@ -302,8 +302,7 @@ no_calls:
}
}
 
-   g_slist_foreach(vd->calls, (GFunc) g_free, NULL);
-   g_slist_free(vd->calls);
+   g_slist_free_full(vd->calls, g_free);
 
vd->calls = calls;
vd->local_release = 0;
@@ -848,8 +847,7 @@ void ril_voicecall_remove(struct ofono_voicecall *vc)
if (vd->clcc_source)
g_source_remove(vd->clcc_source);
 
-   g_slist_foreach(vd->calls, (GFunc) g_free, NULL);
-   g_slist_free(vd->calls);
+   g_slist_free_full(vd->calls, g_free);
 
ofono_voicecall_set_data(vc, NULL);
 
-- 
1.9.1
___
ofono mailing list
ofono@ofono.org
https://lists.ofono.org/mailman/listinfo/ofono


[PATCH 06/24] gatchat: don't rely on undefined behavior when casting function pointers

2016-04-22 Thread John Ernberg
From: John Ernberg 

---
 gatchat/gatchat.c | 13 +
 1 file changed, 5 insertions(+), 8 deletions(-)

diff --git a/gatchat/gatchat.c b/gatchat/gatchat.c
index d7d0060..3f290ac 100644
--- a/gatchat/gatchat.c
+++ b/gatchat/gatchat.c
@@ -305,8 +305,9 @@ static void at_command_destroy(struct at_command *cmd)
g_free(cmd);
 }
 
-static void free_terminator(struct terminator_info *info)
+static void free_terminator(gpointer pointer)
 {
+   struct terminator_info *info = pointer;
g_free(info->terminator);
info->terminator = NULL;
g_free(info);
@@ -325,8 +326,7 @@ static void chat_cleanup(struct at_chat *chat)
chat->command_queue = NULL;
 
/* Cleanup any response lines we have pending */
-   g_slist_foreach(chat->response_lines, (GFunc)g_free, NULL);
-   g_slist_free(chat->response_lines);
+   g_slist_free_full(chat->response_lines, g_free);
chat->response_lines = NULL;
 
/* Cleanup registered notifications */
@@ -357,9 +357,7 @@ static void chat_cleanup(struct at_chat *chat)
chat->syntax = NULL;
 
if (chat->terminator_list) {
-   g_slist_foreach(chat->terminator_list,
-   (GFunc)free_terminator, NULL);
-   g_slist_free(chat->terminator_list);
+   g_slist_free_full(chat->terminator_list, free_terminator);
chat->terminator_list = NULL;
}
 }
@@ -461,8 +459,7 @@ static void at_chat_finish_command(struct at_chat *p, 
gboolean ok, char *final)
cmd->callback(ok, &result, cmd->user_data);
}
 
-   g_slist_foreach(response_lines, (GFunc)g_free, NULL);
-   g_slist_free(response_lines);
+   g_slist_free_full(response_lines, g_free);
 
g_free(final);
at_command_destroy(cmd);
-- 
1.9.1
___
ofono mailing list
ofono@ofono.org
https://lists.ofono.org/mailman/listinfo/ofono


[PATCH 08/24] sm: don't rely on undefined behavior when casting function pointers

2016-04-22 Thread John Ernberg
From: John Ernberg 

---
 plugins/smart-messaging.c | 6 ++
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/plugins/smart-messaging.c b/plugins/smart-messaging.c
index b368917..bbbdaa9 100644
--- a/plugins/smart-messaging.c
+++ b/plugins/smart-messaging.c
@@ -216,8 +216,7 @@ static DBusMessage 
*smart_messaging_send_vcard(DBusConnection *conn,
err = __ofono_sms_txq_submit(sm->sms, msg_list, flags, &uuid,
message_queued, msg);
 
-   g_slist_foreach(msg_list, (GFunc)g_free, NULL);
-   g_slist_free(msg_list);
+   g_slist_free_full(msg_list, g_free);
 
if (err < 0)
return __ofono_error_failed(msg);
@@ -259,8 +258,7 @@ static DBusMessage 
*smart_messaging_send_vcal(DBusConnection *conn,
err = __ofono_sms_txq_submit(sm->sms, msg_list, flags, &uuid,
message_queued, msg);
 
-   g_slist_foreach(msg_list, (GFunc)g_free, NULL);
-   g_slist_free(msg_list);
+   g_slist_free_full(msg_list, g_free);
 
if (err < 0)
return __ofono_error_failed(msg);
-- 
1.9.1
___
ofono mailing list
ofono@ofono.org
https://lists.ofono.org/mailman/listinfo/ofono


[PATCH 09/24] cbs: don't rely on undefined behavior when casting function pointers

2016-04-22 Thread John Ernberg
From: John Ernberg 

---
 src/cbs.c | 27 +--
 1 file changed, 9 insertions(+), 18 deletions(-)

diff --git a/src/cbs.c b/src/cbs.c
index fdc44a1..8e3296b 100644
--- a/src/cbs.c
+++ b/src/cbs.c
@@ -272,8 +272,7 @@ void ofono_cbs_notify(struct ofono_cbs *cbs, const unsigned 
char *pdu,
 
 out:
g_free(message);
-   g_slist_foreach(cbs_list, (GFunc)g_free, NULL);
-   g_slist_free(cbs_list);
+   g_slist_free_full(cbs_list, g_free);
 }
 
 static DBusMessage *cbs_get_properties(DBusConnection *conn,
@@ -337,8 +336,7 @@ static void cbs_set_topics_cb(const struct ofono_error 
*error, void *data)
char *topics;
 
if (error->type != OFONO_ERROR_TYPE_NO_ERROR) {
-   g_slist_foreach(cbs->new_topics, (GFunc)g_free, NULL);
-   g_slist_free(cbs->new_topics);
+   g_slist_free_full(cbs->new_topics, g_free);
cbs->new_topics = NULL;
 
DBG("Setting Cell Broadcast topics failed");
@@ -347,8 +345,7 @@ static void cbs_set_topics_cb(const struct ofono_error 
*error, void *data)
return;
}
 
-   g_slist_foreach(cbs->topics, (GFunc)g_free, NULL);
-   g_slist_free(cbs->topics);
+   g_slist_free_full(cbs->topics, g_free);
cbs->topics = cbs->new_topics;
cbs->new_topics = NULL;
 
@@ -590,21 +587,18 @@ static void cbs_unregister(struct ofono_atom *atom)
ofono_modem_remove_interface(modem, OFONO_CELL_BROADCAST_INTERFACE);
 
if (cbs->topics) {
-   g_slist_foreach(cbs->topics, (GFunc) g_free, NULL);
-   g_slist_free(cbs->topics);
+   g_slist_free_full(cbs->topics, g_free);
cbs->topics = NULL;
}
 
if (cbs->new_topics) {
-   g_slist_foreach(cbs->new_topics, (GFunc) g_free, NULL);
-   g_slist_free(cbs->new_topics);
+   g_slist_free_full(cbs->new_topics, g_free);
cbs->new_topics = NULL;
}
 
if (cbs->efcbmid_length) {
cbs->efcbmid_length = 0;
-   g_slist_foreach(cbs->efcbmid_contents, (GFunc) g_free, NULL);
-   g_slist_free(cbs->efcbmid_contents);
+   g_slist_free_full(cbs->efcbmid_contents, g_free);
cbs->efcbmid_contents = NULL;
}
 
@@ -729,15 +723,13 @@ static void cbs_got_file_contents(struct ofono_cbs *cbs)
 
if (cbs->efcbmi_length) {
cbs->efcbmi_length = 0;
-   g_slist_foreach(cbs->efcbmi_contents, (GFunc) g_free, NULL);
-   g_slist_free(cbs->efcbmi_contents);
+   g_slist_free_full(cbs->efcbmi_contents, g_free);
cbs->efcbmi_contents = NULL;
}
 
if (cbs->efcbmir_length) {
cbs->efcbmir_length = 0;
-   g_slist_foreach(cbs->efcbmir_contents, (GFunc) g_free, NULL);
-   g_slist_free(cbs->efcbmir_contents);
+   g_slist_free_full(cbs->efcbmir_contents, g_free);
cbs->efcbmir_contents = NULL;
}
 
@@ -907,8 +899,7 @@ static void cbs_efcbmid_changed(int id, void *userdata)
 
if (cbs->efcbmid_length) {
cbs->efcbmid_length = 0;
-   g_slist_foreach(cbs->efcbmid_contents, (GFunc) g_free, NULL);
-   g_slist_free(cbs->efcbmid_contents);
+   g_slist_free_full(cbs->efcbmid_contents, g_free);
cbs->efcbmid_contents = NULL;
}
 
-- 
1.9.1
___
ofono mailing list
ofono@ofono.org
https://lists.ofono.org/mailman/listinfo/ofono


[PATCH 07/24] bluez4: don't rely on undefined behavior when casting function pointers

2016-04-22 Thread John Ernberg
From: John Ernberg 

---
 plugins/bluez4.c | 7 +++
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/plugins/bluez4.c b/plugins/bluez4.c
index 6a29d9f..0558da3 100644
--- a/plugins/bluez4.c
+++ b/plugins/bluez4.c
@@ -225,8 +225,7 @@ void bluetooth_parse_properties(DBusMessage *reply, const 
char *property, ...)
}
 
 done:
-   g_slist_foreach(prop_handlers, (GFunc) g_free, NULL);
-   g_slist_free(prop_handlers);
+   g_slist_free_full(prop_handlers, g_free);
 }
 
 static void parse_uuids(DBusMessageIter *array, gpointer user_data)
@@ -692,7 +691,7 @@ static void find_adapter_cb(DBusPendingCall *call, gpointer 
user_data)
 
adapter_any_path = g_strdup(path);
 
-   g_slist_foreach(server_list, (GFunc) add_record, NULL);
+   g_slist_foreach(server_list, add_record, NULL);
 
 done:
dbus_message_unref(reply);
@@ -820,7 +819,7 @@ static void bluetooth_disconnect(DBusConnection *conn, void 
*user_data)
 
g_hash_table_foreach(uuid_hash, bluetooth_remove, NULL);
 
-   g_slist_foreach(server_list, (GFunc) remove_service_handle, NULL);
+   g_slist_foreach(server_list, remove_service_handle, NULL);
 }
 
 static guint bluetooth_watch;
-- 
1.9.1
___
ofono mailing list
ofono@ofono.org
https://lists.ofono.org/mailman/listinfo/ofono


[PATCH 05/24] stemodem: don't rely on undefined behavior when casting function pointers

2016-04-22 Thread John Ernberg
From: John Ernberg 

---
 drivers/stemodem/voicecall.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/stemodem/voicecall.c b/drivers/stemodem/voicecall.c
index 1cbf51a..356ab7c 100644
--- a/drivers/stemodem/voicecall.c
+++ b/drivers/stemodem/voicecall.c
@@ -574,8 +574,7 @@ static void ste_voicecall_remove(struct ofono_voicecall *vc)
 {
struct voicecall_data *vd = ofono_voicecall_get_data(vc);
 
-   g_slist_foreach(vd->calls, (GFunc) g_free, NULL);
-   g_slist_free(vd->calls);
+   g_slist_free_full(vd->calls, g_free);
 
ofono_voicecall_set_data(vc, NULL);
 
-- 
1.9.1
___
ofono mailing list
ofono@ofono.org
https://lists.ofono.org/mailman/listinfo/ofono


[PATCH 10/24] cdma/sms: don't rely on undefined behavior when casting function pointers

2016-04-22 Thread John Ernberg
From: John Ernberg 

---
 src/cdma-smsutil.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/src/cdma-smsutil.c b/src/cdma-smsutil.c
index e36f2e3..35b77e0 100644
--- a/src/cdma-smsutil.c
+++ b/src/cdma-smsutil.c
@@ -533,8 +533,7 @@ static gboolean decode_subparams(struct simple_iter *iter, 
guint32 *bitmap,
}
}
 
-   g_slist_foreach(entries, (GFunc) g_free, NULL);
-   g_slist_free(entries);
+   g_slist_free_full(entries, g_free);
 
return decode_result;
 }
-- 
1.9.1
___
ofono mailing list
ofono@ofono.org
https://lists.ofono.org/mailman/listinfo/ofono


[PATCH 02/24] hfpmodem: don't rely on undefined behavior when casting function pointers

2016-04-22 Thread John Ernberg
From: John Ernberg 

---
 drivers/hfpmodem/voicecall.c | 6 ++
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/drivers/hfpmodem/voicecall.c b/drivers/hfpmodem/voicecall.c
index f8db584..ffdf4b7 100644
--- a/drivers/hfpmodem/voicecall.c
+++ b/drivers/hfpmodem/voicecall.c
@@ -286,8 +286,7 @@ static void clcc_poll_cb(gboolean ok, GAtResult *result, 
gpointer user_data)
 
ofono_voicecall_mpty_hint(vc, mpty_ids);
 
-   g_slist_foreach(vd->calls, (GFunc) g_free, NULL);
-   g_slist_free(vd->calls);
+   g_slist_free_full(vd->calls, g_free);
 
vd->calls = calls;
 
@@ -1256,8 +1255,7 @@ static void hfp_voicecall_remove(struct ofono_voicecall 
*vc)
if (vd->expect_release_source)
g_source_remove(vd->expect_release_source);
 
-   g_slist_foreach(vd->calls, (GFunc) g_free, NULL);
-   g_slist_free(vd->calls);
+   g_slist_free_full(vd->calls, g_free);
 
ofono_voicecall_set_data(vc, NULL);
 
-- 
1.9.1
___
ofono mailing list
ofono@ofono.org
https://lists.ofono.org/mailman/listinfo/ofono


[PATCH 03/24] ifxmodem: don't rely on undefined behavior when casting function pointers

2016-04-22 Thread John Ernberg
From: John Ernberg 

---
 drivers/ifxmodem/voicecall.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/ifxmodem/voicecall.c b/drivers/ifxmodem/voicecall.c
index 7c27642..45b5ca4 100644
--- a/drivers/ifxmodem/voicecall.c
+++ b/drivers/ifxmodem/voicecall.c
@@ -1009,8 +1009,7 @@ static void ifx_voicecall_remove(struct ofono_voicecall 
*vc)
 {
struct voicecall_data *vd = ofono_voicecall_get_data(vc);
 
-   g_slist_foreach(vd->calls, (GFunc) g_free, NULL);
-   g_slist_free(vd->calls);
+   g_slist_free_full(vd->calls, g_free);
 
g_strfreev(vd->en_list);
 
-- 
1.9.1
___
ofono mailing list
ofono@ofono.org
https://lists.ofono.org/mailman/listinfo/ofono


[PATCH 00/24] [RFC] Don't rely on undefined behavior when casting function pointers

2016-04-22 Thread John Ernberg
From: John Ernberg 

Casting between incompatible function pointer types is undefined.
While it works fine on x86, it's not a good idea to depend on this.

This RFC uses g_slist_free_full where possible, and when it's not works around
the casting using other means such as wrappers or fixing function parameters.

John Ernberg (24):
  atmodem: don't rely on undefined behavior when casting function
pointers
  hfpmodem: don't rely on undefined behavior when casting function
pointers
  ifxmodem: don't rely on undefined behavior when casting function
pointers
  ril: don't rely on undefined behavior when casting function pointers
  stemodem: don't rely on undefined behavior when casting function
pointers
  gatchat: don't rely on undefined behavior when casting function
pointers
  bluez4: don't rely on undefined behavior when casting function
pointers
  sm: don't rely on undefined behavior when casting function pointers
  cbs: don't rely on undefined behavior when casting function pointers
  cdma/sms: don't rely on undefined behavior when casting function
pointers
  handsfree: don't rely on undefined behavior when casting function
pointers
  modem: don't rely on undefined behavior when casting function pointers
  network: don't rely on undefined behavior when casting function
pointers
  phonebook: don't rely on undefined behavior when casting function
pointers
  sim: don't rely on undefined behavior when casting function pointers
  simfs: don't rely on undefined behavior when casting function pointers
  simutil: don't rely on undefined behavior when casting function
pointers
  sms: don't rely on undefined behavior when casting function pointers
  smsutil: don't rely on undefined behavior when casting function
pointers
  stk: don't rely on undefined behavior when casting function pointers
  stkutil: don't rely on undefined behavior when casting function
pointers
  ussd: don't rely on undefined behavior when casting function pointers
  voicecall: don't rely on undefined behavior when casting function
pointers
  unittest: don't rely on undefined behavior when casting function
pointers

 drivers/atmodem/voicecall.c  |  6 ++
 drivers/hfpmodem/voicecall.c |  6 ++
 drivers/ifxmodem/voicecall.c |  3 +--
 drivers/rilmodem/voicecall.c |  6 ++
 drivers/stemodem/voicecall.c |  3 +--
 gatchat/gatchat.c| 13 +
 plugins/bluez4.c |  7 +++
 plugins/smart-messaging.c|  6 ++
 src/cbs.c| 27 +--
 src/cdma-smsutil.c   |  3 +--
 src/handsfree.c  |  3 +--
 src/modem.c  |  6 ++
 src/network.c|  3 +--
 src/phonebook.c  | 24 ++--
 src/sim.c| 29 ++---
 src/simfs.c  |  6 +++---
 src/simutil.c|  6 ++
 src/sms.c|  9 +++--
 src/smsutil.c| 21 +++--
 src/stk.c| 10 +++---
 src/stkutil.c| 39 ---
 src/ussd.c   | 10 +-
 src/voicecall.c  |  7 ++-
 unit/test-sms.c  | 21 +++--
 24 files changed, 104 insertions(+), 170 deletions(-)

-- 
1.9.1
___
ofono mailing list
ofono@ofono.org
https://lists.ofono.org/mailman/listinfo/ofono


[PATCH 01/24] atmodem: don't rely on undefined behavior when casting function pointers

2016-04-22 Thread John Ernberg
From: John Ernberg 

---
 drivers/atmodem/voicecall.c | 6 ++
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/drivers/atmodem/voicecall.c b/drivers/atmodem/voicecall.c
index 7d823a2..e4c59c2 100644
--- a/drivers/atmodem/voicecall.c
+++ b/drivers/atmodem/voicecall.c
@@ -253,8 +253,7 @@ static void clcc_poll_cb(gboolean ok, GAtResult *result, 
gpointer user_data)
}
}
 
-   g_slist_foreach(vd->calls, (GFunc) g_free, NULL);
-   g_slist_free(vd->calls);
+   g_slist_free_full(vd->calls, g_free);
 
vd->calls = calls;
 
@@ -1147,8 +1146,7 @@ static void at_voicecall_remove(struct ofono_voicecall 
*vc)
if (vd->vts_source)
g_source_remove(vd->vts_source);
 
-   g_slist_foreach(vd->calls, (GFunc) g_free, NULL);
-   g_slist_free(vd->calls);
+   g_slist_free_full(vd->calls, g_free);
 
ofono_voicecall_set_data(vc, NULL);
 
-- 
1.9.1
___
ofono mailing list
ofono@ofono.org
https://lists.ofono.org/mailman/listinfo/ofono


[PATCH 1/5] modem: clean up atoms on modem_unregister

2016-04-22 Thread John Ernberg
From: John Ernberg 

This resolves a crash that can happen when a e.g. usb modem is removed.
---
 src/modem.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/src/modem.c b/src/modem.c
index a89fa48..4968839 100644
--- a/src/modem.c
+++ b/src/modem.c
@@ -2071,6 +2071,9 @@ static void modem_unregister(struct ofono_modem *modem)
if (modem->powered == TRUE)
set_powered(modem, FALSE);
 
+   if (modem->atoms)
+   flush_atoms(modem, MODEM_STATE_POWER_OFF);
+
__ofono_watchlist_free(modem->atom_watches);
modem->atom_watches = NULL;
 
-- 
1.9.1
___
ofono mailing list
ofono@ofono.org
https://lists.ofono.org/mailman/listinfo/ofono


[PATCH 4/5] push notification: track and clean up atom watches

2016-04-22 Thread John Ernberg
From: John Ernberg 

Prevents glib from causing SIGFPE during certain circumstances of modem
removal.
---
 plugins/push-notification.c | 26 +++---
 1 file changed, 23 insertions(+), 3 deletions(-)

diff --git a/plugins/push-notification.c b/plugins/push-notification.c
index ff388d9..ecf100f 100644
--- a/plugins/push-notification.c
+++ b/plugins/push-notification.c
@@ -45,6 +45,7 @@
 #define WAP_PUSH_DST_PORT 2948
 
 static unsigned int modemwatch_id;
+static GHashTable *sms_watches = NULL;
 
 struct push_notification {
struct ofono_modem *modem;
@@ -164,6 +165,16 @@ static void push_notification_cleanup(gpointer user)
ofono_modem_remove_interface(pn->modem, PUSH_NOTIFICATION_INTERFACE);
 }
 
+static gboolean atom_watch_remove(gpointer key, gpointer value,
+   gpointer user_data)
+{
+   struct ofono_modem *modem = key;
+
+   __ofono_modem_remove_atom_watch(modem, GPOINTER_TO_UINT(value));
+
+   return TRUE;
+}
+
 static void sms_watch(struct ofono_atom *atom,
enum ofono_atom_watch_condition cond,
void *data)
@@ -197,18 +208,22 @@ static void sms_watch(struct ofono_atom *atom,
 static void modem_watch(struct ofono_modem *modem, gboolean added, void *user)
 {
struct push_notification *pn;
+   int sms;
DBG("modem: %p, added: %d", modem, added);
 
-   if (added == FALSE)
+   if (added == FALSE) {
+   g_hash_table_remove(sms_watches, modem);
return;
+   }
 
pn = g_try_new0(struct push_notification, 1);
if (pn == NULL)
return;
 
pn->modem = modem;
-   __ofono_modem_add_atom_watch(modem, OFONO_ATOM_TYPE_SMS,
-   sms_watch, pn, g_free);
+   sms = __ofono_modem_add_atom_watch(modem, OFONO_ATOM_TYPE_SMS,
+   sms_watch, pn, g_free);
+   g_hash_table_insert(sms_watches, modem, GUINT_TO_POINTER(sms));
 }
 
 static void call_modemwatch(struct ofono_modem *modem, void *user)
@@ -220,6 +235,8 @@ static int push_notification_init(void)
 {
DBG("");
 
+   sms_watches = g_hash_table_new(g_direct_hash, g_direct_equal);
+
modemwatch_id = __ofono_modemwatch_add(modem_watch, NULL, NULL);
 
__ofono_modem_foreach(call_modemwatch, NULL);
@@ -232,6 +249,9 @@ static void push_notification_exit(void)
DBG("");
 
__ofono_modemwatch_remove(modemwatch_id);
+
+   g_hash_table_foreach_remove(sms_watches, atom_watch_remove, NULL);
+   g_hash_table_destroy(sms_watches);
 }
 
 OFONO_PLUGIN_DEFINE(push_notification, "Push Notification Plugin", VERSION,
-- 
1.9.1
___
ofono mailing list
ofono@ofono.org
https://lists.ofono.org/mailman/listinfo/ofono


[PATCH 0/5] Clean up atoms on modem_unregister

2016-04-22 Thread John Ernberg
From: John Ernberg 

When using e.g. a USB modem and it's unplugged oFono may crash with a
SIGSEGV or SIGFPE due to atoms not getting cleaned up properly.

John Ernberg (5):
  modem: clean up atoms on modem_unregister
  bluez4: track and clean up atom watches
  bluez5: track and clean up atom watches
  push notification: track and clean up atom watches
  smart messaging: track and clean up atom watches

 plugins/dun_gw_bluez4.c | 24 ++--
 plugins/dun_gw_bluez5.c | 24 ++--
 plugins/hfp_ag_bluez4.c | 25 ++---
 plugins/hfp_ag_bluez5.c | 36 +++-
 plugins/push-notification.c | 26 +++---
 plugins/smart-messaging.c   | 26 +++---
 src/modem.c |  3 +++
 7 files changed, 146 insertions(+), 18 deletions(-)

-- 
1.9.1
___
ofono mailing list
ofono@ofono.org
https://lists.ofono.org/mailman/listinfo/ofono


[PATCH 3/5] bluez5: track and clean up atom watches

2016-04-22 Thread John Ernberg
From: John Ernberg 

Prevents glib from causing SIGFPE during certain circumstances of modem
removal.
---
 plugins/dun_gw_bluez5.c | 24 ++--
 plugins/hfp_ag_bluez5.c | 36 +++-
 2 files changed, 53 insertions(+), 7 deletions(-)

diff --git a/plugins/dun_gw_bluez5.c b/plugins/dun_gw_bluez5.c
index faea12b..af78795 100644
--- a/plugins/dun_gw_bluez5.c
+++ b/plugins/dun_gw_bluez5.c
@@ -48,6 +48,7 @@
 
 static guint modemwatch_id;
 static GList *modems;
+static GHashTable *gprs_watches = NULL;
 
 static DBusMessage *profile_new_connection(DBusConnection *conn,
DBusMessage *msg, void *data)
@@ -151,6 +152,16 @@ static const GDBusMethodTable profile_methods[] = {
{ }
 };
 
+static gboolean atom_watch_remove(gpointer key, gpointer value,
+   gpointer user_data)
+{
+   struct ofono_modem *modem = key;
+
+   __ofono_modem_remove_atom_watch(modem, GPOINTER_TO_UINT(value));
+
+   return TRUE;
+}
+
 static void gprs_watch(struct ofono_atom *atom,
enum ofono_atom_watch_condition cond,
void *data)
@@ -177,13 +188,17 @@ static void gprs_watch(struct ofono_atom *atom,
 
 static void modem_watch(struct ofono_modem *modem, gboolean added, void *user)
 {
+   int gprs;
DBG("modem: %p, added: %d", modem, added);
 
-   if (added == FALSE)
+   if (added == FALSE) {
+   g_hash_table_remove(gprs_watches, modem);
return;
+   }
 
-   __ofono_modem_add_atom_watch(modem, OFONO_ATOM_TYPE_GPRS,
+   gprs = __ofono_modem_add_atom_watch(modem, OFONO_ATOM_TYPE_GPRS,
gprs_watch, modem, NULL);
+   g_hash_table_insert(gprs_watches, modem, GUINT_TO_POINTER(gprs));
 }
 
 static void call_modemwatch(struct ofono_modem *modem, void *user)
@@ -210,6 +225,8 @@ static int dun_gw_init(void)
return -EIO;
}
 
+   gprs_watches = g_hash_table_new(g_direct_hash, g_direct_equal);
+
modemwatch_id = __ofono_modemwatch_add(modem_watch, NULL, NULL);
 
__ofono_modem_foreach(call_modemwatch, NULL);
@@ -228,6 +245,9 @@ static void dun_gw_exit(void)
bt_unregister_profile(conn, DUN_GW_EXT_PROFILE_PATH);
g_dbus_unregister_interface(conn, DUN_GW_EXT_PROFILE_PATH,
BLUEZ_PROFILE_INTERFACE);
+
+   g_hash_table_foreach_remove(gprs_watches, atom_watch_remove, NULL);
+   g_hash_table_destroy(gprs_watches);
 }
 
 OFONO_PLUGIN_DEFINE(dun_gw_bluez5, "Dial-up Networking Profile Plugins",
diff --git a/plugins/hfp_ag_bluez5.c b/plugins/hfp_ag_bluez5.c
index 22faeb7..ba0f802 100644
--- a/plugins/hfp_ag_bluez5.c
+++ b/plugins/hfp_ag_bluez5.c
@@ -60,6 +60,8 @@ static guint modemwatch_id;
 static GList *modems;
 static GHashTable *sim_hash = NULL;
 static GHashTable *connection_hash;
+static GHashTable *sim_atom_watches = NULL;
+static GHashTable *vc_atom_watches = NULL;
 
 static int hfp_card_probe(struct ofono_handsfree_card *card,
unsigned int vendor, void *data)
@@ -374,6 +376,16 @@ static void sim_state_watch(enum ofono_sim_state 
new_state, void *data)
HFP_AG_EXT_PROFILE_PATH, NULL, 0);
 }
 
+static gboolean atom_watch_remove(gpointer key, gpointer value,
+   gpointer user_data)
+{
+   struct ofono_modem *modem = key;
+
+   __ofono_modem_remove_atom_watch(modem, GPOINTER_TO_UINT(value));
+
+   return TRUE;
+}
+
 static gboolean sim_watch_remove(gpointer key, gpointer value,
gpointer user_data)
 {
@@ -443,15 +455,21 @@ static void voicecall_watch(struct ofono_atom *atom,
 
 static void modem_watch(struct ofono_modem *modem, gboolean added, void *user)
 {
+   int sim, vc;
DBG("modem: %p, added: %d", modem, added);
 
-   if (added == FALSE)
+   if (added == FALSE) {
+   g_hash_table_remove(sim_atom_watches, modem);
+   g_hash_table_remove(vc_atom_watches, modem);
return;
+   }
 
-   __ofono_modem_add_atom_watch(modem, OFONO_ATOM_TYPE_SIM,
-   sim_watch, modem, NULL);
-   __ofono_modem_add_atom_watch(modem, OFONO_ATOM_TYPE_VOICECALL,
-   voicecall_watch, modem, NULL);
+   sim = __ofono_modem_add_atom_watch(modem, OFONO_ATOM_TYPE_SIM,
+   sim_watch, modem, NULL);
+   vc = __ofono_modem_add_atom_watch(modem, OFONO_ATOM_TYPE_VOICECALL,
+   voicecall_watch, modem, NULL);
+   g_hash_table_insert(sim_atom_watches, modem, GUINT_TO_POINTER(sim));
+   g_hash_table_insert(vc_atom_watches, modem, GUINT_TO_POINTER(vc));
 }
 
 static void call_modemwatch(s

[PATCH 5/5] smart messaging: track and clean up atom watches

2016-04-22 Thread John Ernberg
From: John Ernberg 

Prevents glib from causing SIGFPE during certain circumstances of modem
removal.
---
 plugins/smart-messaging.c | 26 +++---
 1 file changed, 23 insertions(+), 3 deletions(-)

diff --git a/plugins/smart-messaging.c b/plugins/smart-messaging.c
index b368917..38a03f3 100644
--- a/plugins/smart-messaging.c
+++ b/plugins/smart-messaging.c
@@ -48,6 +48,7 @@
 #define VCAL_SRC_PORT -1
 #define VCAL_DST_PORT 9205
 
+static GHashTable *sms_watches = NULL;
 static unsigned int modemwatch_id;
 
 struct smart_messaging {
@@ -284,6 +285,16 @@ static const GDBusMethodTable smart_messaging_methods[] = {
{ }
 };
 
+static gboolean atom_watch_remove(gpointer key, gpointer value,
+   gpointer user_data)
+{
+   struct ofono_modem *modem = key;
+
+   __ofono_modem_remove_atom_watch(modem, GPOINTER_TO_UINT(value));
+
+   return TRUE;
+}
+
 static void smart_messaging_cleanup(gpointer user)
 {
struct smart_messaging *sm = user;
@@ -333,18 +344,22 @@ static void sms_watch(struct ofono_atom *atom,
 static void modem_watch(struct ofono_modem *modem, gboolean added, void *user)
 {
struct smart_messaging *sm;
+   int sms;
DBG("modem: %p, added: %d", modem, added);
 
-   if (added == FALSE)
+   if (added == FALSE) {
+   g_hash_table_remove(sms_watches, modem);
return;
+   }
 
sm = g_try_new0(struct smart_messaging, 1);
if (sm == NULL)
return;
 
sm->modem = modem;
-   __ofono_modem_add_atom_watch(modem, OFONO_ATOM_TYPE_SMS,
-   sms_watch, sm, g_free);
+   sms = __ofono_modem_add_atom_watch(modem, OFONO_ATOM_TYPE_SMS,
+   sms_watch, sm, g_free);
+   g_hash_table_insert(sms_watches, modem, GUINT_TO_POINTER(sms));
 }
 
 static void call_modemwatch(struct ofono_modem *modem, void *user)
@@ -356,6 +371,8 @@ static int smart_messaging_init(void)
 {
DBG("");
 
+   sms_watches = g_hash_table_new(g_direct_hash, g_direct_equal);
+
modemwatch_id = __ofono_modemwatch_add(modem_watch, NULL, NULL);
 
__ofono_modem_foreach(call_modemwatch, NULL);
@@ -368,6 +385,9 @@ static void smart_messaging_exit(void)
DBG("");
 
__ofono_modemwatch_remove(modemwatch_id);
+
+   g_hash_table_foreach_remove(sms_watches, atom_watch_remove, NULL);
+   g_hash_table_destroy(sms_watches);
 }
 
 OFONO_PLUGIN_DEFINE(smart_messaging, "Smart Messaging Plugin", VERSION,
-- 
1.9.1
___
ofono mailing list
ofono@ofono.org
https://lists.ofono.org/mailman/listinfo/ofono


[PATCH 2/5] bluez4: track and clean up atom watches

2016-04-22 Thread John Ernberg
From: John Ernberg 

Prevents glib from causing SIGFPE during certain circumstances of modem
removal.
---
 plugins/dun_gw_bluez4.c | 24 ++--
 plugins/hfp_ag_bluez4.c | 25 ++---
 2 files changed, 44 insertions(+), 5 deletions(-)

diff --git a/plugins/dun_gw_bluez4.c b/plugins/dun_gw_bluez4.c
index a1de7a4..570da7f 100644
--- a/plugins/dun_gw_bluez4.c
+++ b/plugins/dun_gw_bluez4.c
@@ -40,6 +40,7 @@
 static struct server *server;
 static guint modemwatch_id;
 static GList *modems;
+static GHashTable *gprs_watches = NULL;
 
 static const gchar *dun_record =
 "\n"
@@ -129,15 +130,29 @@ static void gprs_watch(struct ofono_atom *atom,
}
 }
 
+static gboolean atom_watch_remove(gpointer key, gpointer value,
+   gpointer user_data)
+{
+   struct ofono_modem *modem = key;
+
+   __ofono_modem_remove_atom_watch(modem, GPOINTER_TO_UINT(value));
+
+   return TRUE;
+}
+
 static void modem_watch(struct ofono_modem *modem, gboolean added, void *user)
 {
+   int gprs;
DBG("modem: %p, added: %d", modem, added);
 
-   if (added == FALSE)
+   if (added == FALSE) {
+   g_hash_table_remove(gprs_watches, modem);
return;
+   }
 
-   __ofono_modem_add_atom_watch(modem, OFONO_ATOM_TYPE_GPRS,
+   gprs = __ofono_modem_add_atom_watch(modem, OFONO_ATOM_TYPE_GPRS,
gprs_watch, modem, NULL);
+   g_hash_table_insert(gprs_watches, modem, GUINT_TO_POINTER(gprs));
 }
 
 static void call_modemwatch(struct ofono_modem *modem, void *user)
@@ -149,6 +164,8 @@ static int dun_gw_init(void)
 {
DBG("");
 
+   gprs_watches = g_hash_table_new(g_direct_hash, g_direct_equal);
+
modemwatch_id = __ofono_modemwatch_add(modem_watch, NULL, NULL);
 
__ofono_modem_foreach(call_modemwatch, NULL);
@@ -161,6 +178,9 @@ static void dun_gw_exit(void)
__ofono_modemwatch_remove(modemwatch_id);
g_list_free(modems);
 
+   g_hash_table_foreach_remove(gprs_watches, atom_watch_remove, NULL);
+   g_hash_table_destroy(gprs_watches);
+
if (server) {
bluetooth_unregister_server(server);
server = NULL;
diff --git a/plugins/hfp_ag_bluez4.c b/plugins/hfp_ag_bluez4.c
index 039b665..b931ae1 100644
--- a/plugins/hfp_ag_bluez4.c
+++ b/plugins/hfp_ag_bluez4.c
@@ -41,6 +41,7 @@ static struct server *server;
 static guint modemwatch_id;
 static GList *modems;
 static GHashTable *sim_hash = NULL;
+static GHashTable *sim_watches = NULL;
 
 static const gchar *hfp_ag_record =
 "\n"
@@ -142,6 +143,16 @@ static void sim_state_watch(enum ofono_sim_state 
new_state, void *data)
hfp_ag_connect_cb, NULL);
 }
 
+static gboolean atom_watch_remove(gpointer key, gpointer value,
+   gpointer user_data)
+{
+   struct ofono_modem *modem = key;
+
+   __ofono_modem_remove_atom_watch(modem, GPOINTER_TO_UINT(value));
+
+   return TRUE;
+}
+
 static gboolean sim_watch_remove(gpointer key, gpointer value,
gpointer user_data)
 {
@@ -176,13 +187,17 @@ static void sim_watch(struct ofono_atom *atom,
 
 static void modem_watch(struct ofono_modem *modem, gboolean added, void *user)
 {
+   int sim;
DBG("modem: %p, added: %d", modem, added);
 
-   if (added == FALSE)
+   if (added == FALSE) {
+   g_hash_table_remove(sim_watches, modem);
return;
+   }
 
-   __ofono_modem_add_atom_watch(modem, OFONO_ATOM_TYPE_SIM,
-   sim_watch, modem, NULL);
+   sim = __ofono_modem_add_atom_watch(modem, OFONO_ATOM_TYPE_SIM,
+   sim_watch, modem, NULL);
+   g_hash_table_insert(sim_watches, modem, GUINT_TO_POINTER(sim));
 }
 
 static void call_modemwatch(struct ofono_modem *modem, void *user)
@@ -193,6 +208,7 @@ static void call_modemwatch(struct ofono_modem *modem, void 
*user)
 static int hfp_ag_init(void)
 {
sim_hash = g_hash_table_new(g_direct_hash, g_direct_equal);
+   sim_watches = g_hash_table_new(g_direct_hash, g_direct_equal);
 
modemwatch_id = __ofono_modemwatch_add(modem_watch, NULL, NULL);
__ofono_modem_foreach(call_modemwatch, NULL);
@@ -207,6 +223,9 @@ static void hfp_ag_exit(void)
g_hash_table_foreach_remove(sim_hash, sim_watch_remove, NULL);
g_hash_table_destroy(sim_hash);
 
+   g_hash_table_foreach_remove(sim_watches, atom_watch_remove, NULL);
+   g_hash_table_destroy(sim_watches);
+
if (server) {
bluetooth_unregister_server(server);
server = NULL;
-- 
1.9.1
___
ofono mailing list
ofono@ofono.org
https://lists.ofono.org/mailman/listinfo/ofono


[PATCH] voicecall: limit g_drivers variable exposure

2016-04-22 Thread John Ernberg
From: John Ernberg 

---
 src/voicecall.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/voicecall.c b/src/voicecall.c
index c9b1b43..2d15d12 100644
--- a/src/voicecall.c
+++ b/src/voicecall.c
@@ -47,7 +47,7 @@
 #define SETTINGS_STORE "voicecall"
 #define SETTINGS_GROUP "Settings"
 
-GSList *g_drivers = NULL;
+static GSList *g_drivers = NULL;
 
 struct ofono_voicecall {
GSList *call_list;
-- 
1.9.1
___
ofono mailing list
ofono@ofono.org
https://lists.ofono.org/mailman/listinfo/ofono


[PATCH] voicecall: fix CreateMultiparty method introspection

2016-04-22 Thread John Ernberg
From: John Ernberg 

This caused problems with stricter dbus wrappers such as dbus-c++.

---
 src/voicecall.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/voicecall.c b/src/voicecall.c
index 2d15d12..bdad125 100644
--- a/src/voicecall.c
+++ b/src/voicecall.c
@@ -2165,7 +2165,7 @@ static const GDBusMethodTable manager_methods[] = {
GDBUS_ARGS({ "calls", "ao" }),
multiparty_private_chat) },
{ GDBUS_ASYNC_METHOD("CreateMultiparty",
-   NULL, GDBUS_ARGS({ "calls", "o" }),
+   NULL, GDBUS_ARGS({ "calls", "ao" }),
multiparty_create) },
{ GDBUS_ASYNC_METHOD("HangupMultiparty", NULL, NULL,
multiparty_hangup) },
-- 
1.9.1
___
ofono mailing list
ofono@ofono.org
https://lists.ofono.org/mailman/listinfo/ofono


Re: Ublox Toby Modem

2016-04-22 Thread Yorn

Hi Dragos,

many thanks for all the effort! Comments inline:

Am 22.04.2016 um 12:23 schrieb Dragos Tatulea:

Hi Yorn,

On 04/21/2016 08:37 PM, Yorn wrote:

Hi Dragos

Am 21.04.2016 um 11:03 schrieb Dragos Tatulea:

Hi Yarn,

On 04/20/2016 07:54 PM, Yorn wrote:

Hi Dragos,

logs + comments inline

Am 20.04.2016 um 17:01 schrieb Dragos Tatulea:

Hi Yorn,

On 04/20/2016 04:24 PM, Yorn wrote:

Hi Dragos,

it is still active=0 :(

root@colibri-vf:~/test# ./list-contexts
[ /ublox_0 ]
   [ /ublox_0/context1 ]
   Username =
   AuthenticationMethod = chap
   Protocol = ip
   Name = Internet
   Settings = { }
   IPv6.Settings = { }
   Active = 0
   AccessPointName =
   Password =
   Type = internet


Can you run only oFono (no connman) with OFONO_AT_DEBUG env variable set
and run the following scripts:

enable-modem
online-modem
activate-context

Then send the logs.

Here they are [1]

I am actually a bit lost in the ublox AT Commands manual..

Do you have a chance to see something at the ofonod+AT logs with your 
expertice!?


oFono was able to register on the network an activate the context. This
part is interesting for you:

ofonod[369]: drivers/ubloxmodem/gprs-context.c:ublox_gprs_activate_primary() 
cid 1
ofonod[369]: Aux: > AT\r
ofonod[369]: Aux: < \r\nOK\r\n
ofonod[369]: Aux: Finally woke up the modem
ofonod[369]: Aux: > AT+CGDCONT=1,"IP","m2m.tele2.com"\r
*> context defined

ofonod[369]: Aux: < \r\nOK\r\n
ofonod[369]: drivers/ubloxmodem/gprs-context.c:cgdcont_cb() ok 1
ofonod[369]: Aux: > AT+CGACT=1,1\r
*> context activated

ofonod[369]: Aux: < \r\nOK\r\n
ofonod[369]: drivers/ubloxmodem/gprs-context.c:cgact_enable_cb() ok 1
ofonod[369]: Aux: > AT+CGCONTRDP=1\r
ofonod[369]: Aux: < \r\n+CREG: 5,"","0010",4\r\n\r\n+CGEV: ME PDN ACT 
1\r\n
ofonod[369]: src/network.c:ofono_netreg_status_notify() /ublox_0 status 5 tech 4
ofonod[369]: src/gprs.c:netreg_status_changed() 5
ofonod[369]: src/gprs.c:gprs_netreg_update() attach: 1, driver_attached: 1
ofonod[369]: Aux: < \r\n+CGCONTRDP: 1,0,"m2m.tele2.com","
ofonod[369]: Aux: < 
100.98.55.207.255.255.255.255","100.98.55.207","130.244.127.161","130.244.127.169","0.0.0.0","0.0.0.0",0\r\n
ofonod[369]: Aux: < \r\nOK\r\n
*> connection properties read successfully

ofonod[369]: drivers/ubloxmodem/gprs-context.c:cgcontrdp_cb() ok 1
ofonod[369]: src/modem.c:get_modem_property() modem 0x192a900 property 
NetworkInterface


The connman cellular service is set to "a" (association) from starting
connect cellular_240075810199181_context1
up until timeout.


Do you still run the oFono scripts? From the logs it looks like connman
is trying to activate an already active context.
The technologie and the service is running, but the association does not 
end successfully. Do I need to set something else in connman? Where do I 
have to look?


The try to connect ends up with:
Error /net/connman/service/cellular_240075810199181_context1: Did not 
receive a reply. Possible causes include: the remote application did not 
send a reply, the message bus security policy blocked the reply, the 
reply timeout expired, or the network connection was broken.






As a side note, oFono and ConnMan have persistent states for services and
contexts. They are stored under /var/lib/ofono|connman. When debugging I
found it useful sometimes to start with a clean state.

Thanks


___
ofono mailing list
ofono@ofono.org
https://lists.ofono.org/mailman/listinfo/ofono


Re: Ublox Toby Modem

2016-04-22 Thread Dragos Tatulea
Hi Yorn,

On 04/21/2016 08:37 PM, Yorn wrote:
> Hi Dragos
> 
> Am 21.04.2016 um 11:03 schrieb Dragos Tatulea:
>> Hi Yarn,
>>
>> On 04/20/2016 07:54 PM, Yorn wrote:
>>> Hi Dragos,
>>>
>>> logs + comments inline
>>>
>>> Am 20.04.2016 um 17:01 schrieb Dragos Tatulea:
 Hi Yorn,

 On 04/20/2016 04:24 PM, Yorn wrote:
> Hi Dragos,
>
> it is still active=0 :(
>
> root@colibri-vf:~/test# ./list-contexts
> [ /ublox_0 ]
>   [ /ublox_0/context1 ]
>   Username =
>   AuthenticationMethod = chap
>   Protocol = ip
>   Name = Internet
>   Settings = { }
>   IPv6.Settings = { }
>   Active = 0
>   AccessPointName =
>   Password =
>   Type = internet
>
 Can you run only oFono (no connman) with OFONO_AT_DEBUG env variable set
 and run the following scripts:

 enable-modem
 online-modem
 activate-context

 Then send the logs.
>>> Here they are [1]
> 
> I am actually a bit lost in the ublox AT Commands manual..
> 
> Do you have a chance to see something at the ofonod+AT logs with your 
> expertice!?
> 
oFono was able to register on the network an activate the context. This
part is interesting for you:

ofonod[369]: drivers/ubloxmodem/gprs-context.c:ublox_gprs_activate_primary() 
cid 1
ofonod[369]: Aux: > AT\r
ofonod[369]: Aux: < \r\nOK\r\n
ofonod[369]: Aux: Finally woke up the modem
ofonod[369]: Aux: > AT+CGDCONT=1,"IP","m2m.tele2.com"\r
*> context defined

ofonod[369]: Aux: < \r\nOK\r\n
ofonod[369]: drivers/ubloxmodem/gprs-context.c:cgdcont_cb() ok 1
ofonod[369]: Aux: > AT+CGACT=1,1\r
*> context activated

ofonod[369]: Aux: < \r\nOK\r\n
ofonod[369]: drivers/ubloxmodem/gprs-context.c:cgact_enable_cb() ok 1
ofonod[369]: Aux: > AT+CGCONTRDP=1\r
ofonod[369]: Aux: < \r\n+CREG: 5,"","0010",4\r\n\r\n+CGEV: ME PDN ACT 
1\r\n
ofonod[369]: src/network.c:ofono_netreg_status_notify() /ublox_0 status 5 tech 4
ofonod[369]: src/gprs.c:netreg_status_changed() 5
ofonod[369]: src/gprs.c:gprs_netreg_update() attach: 1, driver_attached: 1
ofonod[369]: Aux: < \r\n+CGCONTRDP: 1,0,"m2m.tele2.com","
ofonod[369]: Aux: < 
100.98.55.207.255.255.255.255","100.98.55.207","130.244.127.161","130.244.127.169","0.0.0.0","0.0.0.0",0\r\n
ofonod[369]: Aux: < \r\nOK\r\n
*> connection properties read successfully

ofonod[369]: drivers/ubloxmodem/gprs-context.c:cgcontrdp_cb() ok 1
ofonod[369]: src/modem.c:get_modem_property() modem 0x192a900 property 
NetworkInterface

> The connman cellular service is set to "a" (association) from starting
> connect cellular_240075810199181_context1
> up until timeout.
> 
Do you still run the oFono scripts? From the logs it looks like connman
is trying to activate an already active context.


As a side note, oFono and ConnMan have persistent states for services and
contexts. They are stored under /var/lib/ofono|connman. When debugging I
found it useful sometimes to start with a clean state.

Thanks
-- 
Dragos Tatulea
Software Developer @ Endocode AG
dra...@endocode.com

Endocode AG, Brückenstraße 5A, 10179 Berlin
+49 30 1206 4472 | i...@endocode.com | www.endocode.com

Vorstandsvorsitzender: Mirko Boehm
Vorstände: Dr. Thomas Fricke, Sebastian Sucker
Aufsichtsratsvorsitzende: Alexandra Boehm

Registergericht: Amtsgericht Charlottenburg - HRB 150748 B
___
ofono mailing list
ofono@ofono.org
https://lists.ofono.org/mailman/listinfo/ofono