All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 00/24] [RFC] Don't rely on undefined behavior when casting function pointers
@ 2016-04-22 13:10 John Ernberg
  2016-04-22 13:10 ` [PATCH 01/24] atmodem: don't " John Ernberg
  2016-04-22 20:42 ` [PATCH 00/24] [RFC] Don't " Denis Kenzior
  0 siblings, 2 replies; 29+ messages in thread
From: John Ernberg @ 2016-04-22 13:10 UTC (permalink / raw)
  To: ofono

[-- Attachment #1: Type: text/plain, Size: 3476 bytes --]

From: John Ernberg <john.ernberg@actia.se>

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

^ permalink raw reply	[flat|nested] 29+ messages in thread

* [PATCH 01/24] atmodem: don't rely on undefined behavior when casting function pointers
  2016-04-22 13:10 [PATCH 00/24] [RFC] Don't rely on undefined behavior when casting function pointers John Ernberg
@ 2016-04-22 13:10 ` John Ernberg
  2016-04-22 13:10   ` [PATCH 02/24] hfpmodem: " John Ernberg
  2016-04-22 20:42 ` [PATCH 00/24] [RFC] Don't " Denis Kenzior
  1 sibling, 1 reply; 29+ messages in thread
From: John Ernberg @ 2016-04-22 13:10 UTC (permalink / raw)
  To: ofono

[-- Attachment #1: Type: text/plain, Size: 904 bytes --]

From: John Ernberg <john.ernberg@actia.se>

---
 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

^ permalink raw reply related	[flat|nested] 29+ messages in thread

* [PATCH 02/24] hfpmodem: don't rely on undefined behavior when casting function pointers
  2016-04-22 13:10 ` [PATCH 01/24] atmodem: don't " John Ernberg
@ 2016-04-22 13:10   ` John Ernberg
  2016-04-22 13:10     ` [PATCH 03/24] ifxmodem: " John Ernberg
  0 siblings, 1 reply; 29+ messages in thread
From: John Ernberg @ 2016-04-22 13:10 UTC (permalink / raw)
  To: ofono

[-- Attachment #1: Type: text/plain, Size: 968 bytes --]

From: John Ernberg <john.ernberg@actia.se>

---
 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

^ permalink raw reply related	[flat|nested] 29+ messages in thread

* [PATCH 03/24] ifxmodem: don't rely on undefined behavior when casting function pointers
  2016-04-22 13:10   ` [PATCH 02/24] hfpmodem: " John Ernberg
@ 2016-04-22 13:10     ` John Ernberg
  2016-04-22 13:10       ` [PATCH 04/24] ril: " John Ernberg
  0 siblings, 1 reply; 29+ messages in thread
From: John Ernberg @ 2016-04-22 13:10 UTC (permalink / raw)
  To: ofono

[-- Attachment #1: Type: text/plain, Size: 638 bytes --]

From: John Ernberg <john.ernberg@actia.se>

---
 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

^ permalink raw reply related	[flat|nested] 29+ messages in thread

* [PATCH 04/24] ril: don't rely on undefined behavior when casting function pointers
  2016-04-22 13:10     ` [PATCH 03/24] ifxmodem: " John Ernberg
@ 2016-04-22 13:10       ` John Ernberg
  2016-04-22 13:10         ` [PATCH 05/24] stemodem: " John Ernberg
  0 siblings, 1 reply; 29+ messages in thread
From: John Ernberg @ 2016-04-22 13:10 UTC (permalink / raw)
  To: ofono

[-- Attachment #1: Type: text/plain, Size: 859 bytes --]

From: John Ernberg <john.ernberg@actia.se>

---
 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

^ permalink raw reply related	[flat|nested] 29+ messages in thread

* [PATCH 06/24] gatchat: don't rely on undefined behavior when casting function pointers
  2016-04-22 13:10         ` [PATCH 05/24] stemodem: " John Ernberg
@ 2016-04-22 13:10           ` John Ernberg
  2016-04-22 13:10             ` [PATCH 07/24] bluez4: " John Ernberg
  0 siblings, 1 reply; 29+ messages in thread
From: John Ernberg @ 2016-04-22 13:10 UTC (permalink / raw)
  To: ofono

[-- Attachment #1: Type: text/plain, Size: 1697 bytes --]

From: John Ernberg <john.ernberg@actia.se>

---
 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

^ permalink raw reply related	[flat|nested] 29+ messages in thread

* [PATCH 07/24] bluez4: don't rely on undefined behavior when casting function pointers
  2016-04-22 13:10           ` [PATCH 06/24] gatchat: " John Ernberg
@ 2016-04-22 13:10             ` John Ernberg
  2016-04-22 13:10               ` [PATCH 08/24] sm: " John Ernberg
  0 siblings, 1 reply; 29+ messages in thread
From: John Ernberg @ 2016-04-22 13:10 UTC (permalink / raw)
  To: ofono

[-- Attachment #1: Type: text/plain, Size: 1219 bytes --]

From: John Ernberg <john.ernberg@actia.se>

---
 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

^ permalink raw reply related	[flat|nested] 29+ messages in thread

* [PATCH 05/24] stemodem: don't rely on undefined behavior when casting function pointers
  2016-04-22 13:10       ` [PATCH 04/24] ril: " John Ernberg
@ 2016-04-22 13:10         ` John Ernberg
  2016-04-22 13:10           ` [PATCH 06/24] gatchat: " John Ernberg
  0 siblings, 1 reply; 29+ messages in thread
From: John Ernberg @ 2016-04-22 13:10 UTC (permalink / raw)
  To: ofono

[-- Attachment #1: Type: text/plain, Size: 647 bytes --]

From: John Ernberg <john.ernberg@actia.se>

---
 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

^ permalink raw reply related	[flat|nested] 29+ messages in thread

* [PATCH 08/24] sm: don't rely on undefined behavior when casting function pointers
  2016-04-22 13:10             ` [PATCH 07/24] bluez4: " John Ernberg
@ 2016-04-22 13:10               ` John Ernberg
  2016-04-22 13:10                 ` [PATCH 09/24] cbs: " John Ernberg
  0 siblings, 1 reply; 29+ messages in thread
From: John Ernberg @ 2016-04-22 13:10 UTC (permalink / raw)
  To: ofono

[-- Attachment #1: Type: text/plain, Size: 1042 bytes --]

From: John Ernberg <john.ernberg@actia.se>

---
 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

^ permalink raw reply related	[flat|nested] 29+ messages in thread

* [PATCH 09/24] cbs: don't rely on undefined behavior when casting function pointers
  2016-04-22 13:10               ` [PATCH 08/24] sm: " John Ernberg
@ 2016-04-22 13:10                 ` John Ernberg
  2016-04-22 13:10                   ` [PATCH 10/24] cdma/sms: " John Ernberg
  0 siblings, 1 reply; 29+ messages in thread
From: John Ernberg @ 2016-04-22 13:10 UTC (permalink / raw)
  To: ofono

[-- Attachment #1: Type: text/plain, Size: 3013 bytes --]

From: John Ernberg <john.ernberg@actia.se>

---
 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

^ permalink raw reply related	[flat|nested] 29+ messages in thread

* [PATCH 10/24] cdma/sms: don't rely on undefined behavior when casting function pointers
  2016-04-22 13:10                 ` [PATCH 09/24] cbs: " John Ernberg
@ 2016-04-22 13:10                   ` John Ernberg
  2016-04-22 13:10                     ` [PATCH 11/24] handsfree: " John Ernberg
  0 siblings, 1 reply; 29+ messages in thread
From: John Ernberg @ 2016-04-22 13:10 UTC (permalink / raw)
  To: ofono

[-- Attachment #1: Type: text/plain, Size: 539 bytes --]

From: John Ernberg <john.ernberg@actia.se>

---
 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

^ permalink raw reply related	[flat|nested] 29+ messages in thread

* [PATCH 11/24] handsfree: don't rely on undefined behavior when casting function pointers
  2016-04-22 13:10                   ` [PATCH 10/24] cdma/sms: " John Ernberg
@ 2016-04-22 13:10                     ` John Ernberg
  2016-04-22 13:10                       ` [PATCH 12/24] modem: " John Ernberg
  0 siblings, 1 reply; 29+ messages in thread
From: John Ernberg @ 2016-04-22 13:10 UTC (permalink / raw)
  To: ofono

[-- Attachment #1: Type: text/plain, Size: 670 bytes --]

From: John Ernberg <john.ernberg@actia.se>

---
 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

^ permalink raw reply related	[flat|nested] 29+ messages in thread

* [PATCH 12/24] modem: don't rely on undefined behavior when casting function pointers
  2016-04-22 13:10                     ` [PATCH 11/24] handsfree: " John Ernberg
@ 2016-04-22 13:10                       ` John Ernberg
  2016-04-22 13:10                         ` [PATCH 13/24] network: " John Ernberg
  0 siblings, 1 reply; 29+ messages in thread
From: John Ernberg @ 2016-04-22 13:10 UTC (permalink / raw)
  To: ofono

[-- Attachment #1: Type: text/plain, Size: 794 bytes --]

From: John Ernberg <john.ernberg@actia.se>

---
 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

^ permalink raw reply related	[flat|nested] 29+ messages in thread

* [PATCH 13/24] network: don't rely on undefined behavior when casting function pointers
  2016-04-22 13:10                       ` [PATCH 12/24] modem: " John Ernberg
@ 2016-04-22 13:10                         ` John Ernberg
  2016-04-22 13:10                           ` [PATCH 14/24] phonebook: " John Ernberg
  0 siblings, 1 reply; 29+ messages in thread
From: John Ernberg @ 2016-04-22 13:10 UTC (permalink / raw)
  To: ofono

[-- Attachment #1: Type: text/plain, Size: 532 bytes --]

From: John Ernberg <john.ernberg@actia.se>

---
 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

^ permalink raw reply related	[flat|nested] 29+ messages in thread

* [PATCH 14/24] phonebook: don't rely on undefined behavior when casting function pointers
  2016-04-22 13:10                         ` [PATCH 13/24] network: " John Ernberg
@ 2016-04-22 13:10                           ` John Ernberg
  2016-04-22 13:10                             ` [PATCH 15/24] sim: " John Ernberg
  0 siblings, 1 reply; 29+ messages in thread
From: John Ernberg @ 2016-04-22 13:10 UTC (permalink / raw)
  To: ofono

[-- Attachment #1: Type: text/plain, Size: 2665 bytes --]

From: John Ernberg <john.ernberg@actia.se>

---
 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

^ permalink raw reply related	[flat|nested] 29+ messages in thread

* [PATCH 15/24] sim: don't rely on undefined behavior when casting function pointers
  2016-04-22 13:10                           ` [PATCH 14/24] phonebook: " John Ernberg
@ 2016-04-22 13:10                             ` John Ernberg
  2016-04-22 13:10                               ` [PATCH 16/24] simfs: " John Ernberg
  0 siblings, 1 reply; 29+ messages in thread
From: John Ernberg @ 2016-04-22 13:10 UTC (permalink / raw)
  To: ofono

[-- Attachment #1: Type: text/plain, Size: 2839 bytes --]

From: John Ernberg <john.ernberg@actia.se>

---
 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

^ permalink raw reply related	[flat|nested] 29+ messages in thread

* [PATCH 16/24] simfs: don't rely on undefined behavior when casting function pointers
  2016-04-22 13:10                             ` [PATCH 15/24] sim: " John Ernberg
@ 2016-04-22 13:10                               ` John Ernberg
  2016-04-22 13:10                                 ` [PATCH 17/24] simutil: " John Ernberg
  0 siblings, 1 reply; 29+ messages in thread
From: John Ernberg @ 2016-04-22 13:10 UTC (permalink / raw)
  To: ofono

[-- Attachment #1: Type: text/plain, Size: 809 bytes --]

From: John Ernberg <john.ernberg@actia.se>

---
 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

^ permalink raw reply related	[flat|nested] 29+ messages in thread

* [PATCH 17/24] simutil: don't rely on undefined behavior when casting function pointers
  2016-04-22 13:10                               ` [PATCH 16/24] simfs: " John Ernberg
@ 2016-04-22 13:10                                 ` John Ernberg
  2016-04-22 13:10                                   ` [PATCH 18/24] sms: " John Ernberg
  0 siblings, 1 reply; 29+ messages in thread
From: John Ernberg @ 2016-04-22 13:10 UTC (permalink / raw)
  To: ofono

[-- Attachment #1: Type: text/plain, Size: 779 bytes --]

From: John Ernberg <john.ernberg@actia.se>

---
 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

^ permalink raw reply related	[flat|nested] 29+ messages in thread

* [PATCH 18/24] sms: don't rely on undefined behavior when casting function pointers
  2016-04-22 13:10                                 ` [PATCH 17/24] simutil: " John Ernberg
@ 2016-04-22 13:10                                   ` John Ernberg
  2016-04-22 13:10                                     ` [PATCH 19/24] smsutil: " John Ernberg
  0 siblings, 1 reply; 29+ messages in thread
From: John Ernberg @ 2016-04-22 13:10 UTC (permalink / raw)
  To: ofono

[-- Attachment #1: Type: text/plain, Size: 1236 bytes --]

From: John Ernberg <john.ernberg@actia.se>

---
 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

^ permalink raw reply related	[flat|nested] 29+ messages in thread

* [PATCH 19/24] smsutil: don't rely on undefined behavior when casting function pointers
  2016-04-22 13:10                                   ` [PATCH 18/24] sms: " John Ernberg
@ 2016-04-22 13:10                                     ` John Ernberg
  2016-04-22 13:10                                       ` [PATCH 20/24] stk: " John Ernberg
  0 siblings, 1 reply; 29+ messages in thread
From: John Ernberg @ 2016-04-22 13:10 UTC (permalink / raw)
  To: ofono

[-- Attachment #1: Type: text/plain, Size: 2377 bytes --]

From: John Ernberg <john.ernberg@actia.se>

---
 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

^ permalink raw reply related	[flat|nested] 29+ messages in thread

* [PATCH 20/24] stk: don't rely on undefined behavior when casting function pointers
  2016-04-22 13:10                                     ` [PATCH 19/24] smsutil: " John Ernberg
@ 2016-04-22 13:10                                       ` John Ernberg
  2016-04-22 13:10                                         ` [PATCH 21/24] stkutil: " John Ernberg
  2016-04-22 20:44                                         ` [PATCH 20/24] stk: " Denis Kenzior
  0 siblings, 2 replies; 29+ messages in thread
From: John Ernberg @ 2016-04-22 13:10 UTC (permalink / raw)
  To: ofono

[-- Attachment #1: Type: text/plain, Size: 1207 bytes --]

From: John Ernberg <john.ernberg@actia.se>

---
 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

^ permalink raw reply related	[flat|nested] 29+ messages in thread

* [PATCH 21/24] stkutil: don't rely on undefined behavior when casting function pointers
  2016-04-22 13:10                                       ` [PATCH 20/24] stk: " John Ernberg
@ 2016-04-22 13:10                                         ` John Ernberg
  2016-04-22 13:10                                           ` [PATCH 22/24] ussd: " John Ernberg
  2016-04-22 20:44                                         ` [PATCH 20/24] stk: " Denis Kenzior
  1 sibling, 1 reply; 29+ messages in thread
From: John Ernberg @ 2016-04-22 13:10 UTC (permalink / raw)
  To: ofono

[-- Attachment #1: Type: text/plain, Size: 4586 bytes --]

From: John Ernberg <john.ernberg@actia.se>

---
 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

^ permalink raw reply related	[flat|nested] 29+ messages in thread

* [PATCH 22/24] ussd: don't rely on undefined behavior when casting function pointers
  2016-04-22 13:10                                         ` [PATCH 21/24] stkutil: " John Ernberg
@ 2016-04-22 13:10                                           ` John Ernberg
  2016-04-22 13:10                                             ` [PATCH 23/24] voicecall: " John Ernberg
  0 siblings, 1 reply; 29+ messages in thread
From: John Ernberg @ 2016-04-22 13:10 UTC (permalink / raw)
  To: ofono

[-- Attachment #1: Type: text/plain, Size: 1225 bytes --]

From: John Ernberg <john.ernberg@actia.se>

---
 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

^ permalink raw reply related	[flat|nested] 29+ messages in thread

* [PATCH 23/24] voicecall: don't rely on undefined behavior when casting function pointers
  2016-04-22 13:10                                           ` [PATCH 22/24] ussd: " John Ernberg
@ 2016-04-22 13:10                                             ` John Ernberg
  2016-04-22 13:10                                               ` [PATCH 24/24] unittest: " John Ernberg
  0 siblings, 1 reply; 29+ messages in thread
From: John Ernberg @ 2016-04-22 13:10 UTC (permalink / raw)
  To: ofono

[-- Attachment #1: Type: text/plain, Size: 963 bytes --]

From: John Ernberg <john.ernberg@actia.se>

---
 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

^ permalink raw reply related	[flat|nested] 29+ messages in thread

* [PATCH 24/24] unittest: don't rely on undefined behavior when casting function pointers
  2016-04-22 13:10                                             ` [PATCH 23/24] voicecall: " John Ernberg
@ 2016-04-22 13:10                                               ` John Ernberg
  0 siblings, 0 replies; 29+ messages in thread
From: John Ernberg @ 2016-04-22 13:10 UTC (permalink / raw)
  To: ofono

[-- Attachment #1: Type: text/plain, Size: 2230 bytes --]

From: John Ernberg <john.ernberg@actia.se>

---
 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

^ permalink raw reply related	[flat|nested] 29+ messages in thread

* Re: [PATCH 00/24] [RFC] Don't rely on undefined behavior when casting function pointers
  2016-04-22 13:10 [PATCH 00/24] [RFC] Don't rely on undefined behavior when casting function pointers John Ernberg
  2016-04-22 13:10 ` [PATCH 01/24] atmodem: don't " John Ernberg
@ 2016-04-22 20:42 ` Denis Kenzior
  1 sibling, 0 replies; 29+ messages in thread
From: Denis Kenzior @ 2016-04-22 20:42 UTC (permalink / raw)
  To: ofono

[-- Attachment #1: Type: text/plain, Size: 556 bytes --]

Hi John,

On 04/22/2016 08:10 AM, John Ernberg wrote:
> From: John Ernberg <john.ernberg@actia.se>
>
> 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


^ permalink raw reply	[flat|nested] 29+ messages in thread

* Re: [PATCH 20/24] stk: don't rely on undefined behavior when casting function pointers
  2016-04-22 13:10                                       ` [PATCH 20/24] stk: " John Ernberg
  2016-04-22 13:10                                         ` [PATCH 21/24] stkutil: " John Ernberg
@ 2016-04-22 20:44                                         ` Denis Kenzior
  2016-04-25  6:38                                           ` John Ernberg
  1 sibling, 1 reply; 29+ messages in thread
From: Denis Kenzior @ 2016-04-22 20:44 UTC (permalink / raw)
  To: ofono

[-- Attachment #1: Type: text/plain, Size: 1392 bytes --]

Hi John,

On 04/22/2016 08:10 AM, John Ernberg wrote:
> From: John Ernberg <john.ernberg@actia.se>
>
> ---
>   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

^ permalink raw reply	[flat|nested] 29+ messages in thread

* Re: [PATCH 20/24] stk: don't rely on undefined behavior when casting function pointers
  2016-04-22 20:44                                         ` [PATCH 20/24] stk: " Denis Kenzior
@ 2016-04-25  6:38                                           ` John Ernberg
  2016-04-25 17:21                                             ` Denis Kenzior
  0 siblings, 1 reply; 29+ messages in thread
From: John Ernberg @ 2016-04-25  6:38 UTC (permalink / raw)
  To: ofono

[-- Attachment #1: Type: text/plain, Size: 1818 bytes --]

Hi Dennis,

On 04/22/2016 10:44 PM, Denis Kenzior wrote:
> Hi John,
>
> On 04/22/2016 08:10 AM, John Ernberg wrote:
>> From: John Ernberg <john.ernberg@actia.se>
>>
>> ---
>>   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?
It would require a glib required version bump from 2.28 to 2.32, the 
solution in the patch is 2.28 friendly. If it's ok to bump glib, I will 
redo the patch to use g_queue_free_full instead.
>
>>       g_queue_free(stk->envelope_q);
>>
>>       ofono_modem_remove_interface(modem, OFONO_STK_INTERFACE);
>>
>
> Regards,
> -Denis
Best regards // John Ernberg

^ permalink raw reply	[flat|nested] 29+ messages in thread

* Re: [PATCH 20/24] stk: don't rely on undefined behavior when casting function pointers
  2016-04-25  6:38                                           ` John Ernberg
@ 2016-04-25 17:21                                             ` Denis Kenzior
  0 siblings, 0 replies; 29+ messages in thread
From: Denis Kenzior @ 2016-04-25 17:21 UTC (permalink / raw)
  To: ofono

[-- Attachment #1: Type: text/plain, Size: 492 bytes --]

Hi John,

<snip>

 >>> -    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?
> It would require a glib required version bump from 2.28 to 2.32, the
> solution in the patch is 2.28 friendly. If it's ok to bump glib, I will
> redo the patch to use g_queue_free_full instead.
>>

Given than glib 2.32 is over 4 years old, I think it safe to do that.

Regards,
-Denis


^ permalink raw reply	[flat|nested] 29+ messages in thread

end of thread, other threads:[~2016-04-25 17:21 UTC | newest]

Thread overview: 29+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-04-22 13:10 [PATCH 00/24] [RFC] Don't rely on undefined behavior when casting function pointers John Ernberg
2016-04-22 13:10 ` [PATCH 01/24] atmodem: don't " John Ernberg
2016-04-22 13:10   ` [PATCH 02/24] hfpmodem: " John Ernberg
2016-04-22 13:10     ` [PATCH 03/24] ifxmodem: " John Ernberg
2016-04-22 13:10       ` [PATCH 04/24] ril: " John Ernberg
2016-04-22 13:10         ` [PATCH 05/24] stemodem: " John Ernberg
2016-04-22 13:10           ` [PATCH 06/24] gatchat: " John Ernberg
2016-04-22 13:10             ` [PATCH 07/24] bluez4: " John Ernberg
2016-04-22 13:10               ` [PATCH 08/24] sm: " John Ernberg
2016-04-22 13:10                 ` [PATCH 09/24] cbs: " John Ernberg
2016-04-22 13:10                   ` [PATCH 10/24] cdma/sms: " John Ernberg
2016-04-22 13:10                     ` [PATCH 11/24] handsfree: " John Ernberg
2016-04-22 13:10                       ` [PATCH 12/24] modem: " John Ernberg
2016-04-22 13:10                         ` [PATCH 13/24] network: " John Ernberg
2016-04-22 13:10                           ` [PATCH 14/24] phonebook: " John Ernberg
2016-04-22 13:10                             ` [PATCH 15/24] sim: " John Ernberg
2016-04-22 13:10                               ` [PATCH 16/24] simfs: " John Ernberg
2016-04-22 13:10                                 ` [PATCH 17/24] simutil: " John Ernberg
2016-04-22 13:10                                   ` [PATCH 18/24] sms: " John Ernberg
2016-04-22 13:10                                     ` [PATCH 19/24] smsutil: " John Ernberg
2016-04-22 13:10                                       ` [PATCH 20/24] stk: " John Ernberg
2016-04-22 13:10                                         ` [PATCH 21/24] stkutil: " John Ernberg
2016-04-22 13:10                                           ` [PATCH 22/24] ussd: " John Ernberg
2016-04-22 13:10                                             ` [PATCH 23/24] voicecall: " John Ernberg
2016-04-22 13:10                                               ` [PATCH 24/24] unittest: " John Ernberg
2016-04-22 20:44                                         ` [PATCH 20/24] stk: " Denis Kenzior
2016-04-25  6:38                                           ` John Ernberg
2016-04-25 17:21                                             ` Denis Kenzior
2016-04-22 20:42 ` [PATCH 00/24] [RFC] Don't " Denis Kenzior

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.