All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] gril: Fix access to notify callbacks
@ 2015-11-02 16:48 Alfonso Sanchez-Beato
  2015-11-02 18:41 ` Denis Kenzior
  0 siblings, 1 reply; 2+ messages in thread
From: Alfonso Sanchez-Beato @ 2015-11-02 16:48 UTC (permalink / raw)
  To: ofono

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

Entries to the table of notification callbacks can be added by the
callbacks while being called. This caused a glib error as gril was
using an iterator to the hash table while the table was being modified.
Fixed by avoiding the unnecesary loop.
---
 gril/gril.c | 36 ++++++++++++------------------------
 1 file changed, 12 insertions(+), 24 deletions(-)

diff --git a/gril/gril.c b/gril/gril.c
index ead8206..d279c44 100644
--- a/gril/gril.c
+++ b/gril/gril.c
@@ -420,48 +420,36 @@ static gboolean node_check_destroyed(struct ril_notify_node *node,
 
 static void handle_unsol_req(struct ril_s *p, struct ril_msg *message)
 {
-	GHashTableIter iter;
 	struct ril_notify *notify;
-	int req_key;
-	gpointer key, value;
-	GList *list_item;
-	struct ril_notify_node *node;
-	gboolean found = FALSE;
 
 	if (p->notify_list == NULL)
 		return;
 
 	p->in_notify = TRUE;
 
-	g_hash_table_iter_init(&iter, p->notify_list);
+	notify = g_hash_table_lookup(p->notify_list, &message->req);
+	if (notify != NULL) {
+		GSList *list_item;
 
-	while (g_hash_table_iter_next(&iter, &key, &value)) {
-		req_key = *((int *)key);
-		notify = value;
-
-		if (req_key != message->req)
-			continue;
+		for (list_item = notify->nodes; list_item;
+				list_item = g_slist_next(list_item)) {
+			struct ril_notify_node *node = list_item->data;
 
-		list_item = (GList *) notify->nodes;
-
-		while (list_item != NULL) {
-			node = list_item->data;
+			if (node->destroyed)
+				continue;
 
 			node->callback(message, node->user_data);
-			found = TRUE;
-			list_item = (GList *) g_slist_next(list_item);
 		}
-	}
-
-	/* Only log events not being listended for... */
-	if (!found)
+	} else {
+		/* Only log events not being listended for... */
 		DBG("RIL Event slot %d: %s\n",
 			p->slot, unsol_request_to_string(p, message->req));
+	}
 
 	p->in_notify = FALSE;
 
 	/* Now destroy nodes possibly removed by callbacks */
-	if (found)
+	if (notify != NULL)
 		ril_unregister_all(p, FALSE, node_check_destroyed,
 					GUINT_TO_POINTER(TRUE));
 }
-- 
2.1.4


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

* Re: [PATCH] gril: Fix access to notify callbacks
  2015-11-02 16:48 [PATCH] gril: Fix access to notify callbacks Alfonso Sanchez-Beato
@ 2015-11-02 18:41 ` Denis Kenzior
  0 siblings, 0 replies; 2+ messages in thread
From: Denis Kenzior @ 2015-11-02 18:41 UTC (permalink / raw)
  To: ofono

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

Hi Alfonso,

On 11/02/2015 10:48 AM, Alfonso Sanchez-Beato wrote:
> Entries to the table of notification callbacks can be added by the
> callbacks while being called. This caused a glib error as gril was
> using an iterator to the hash table while the table was being modified.
> Fixed by avoiding the unnecesary loop.
> ---
>   gril/gril.c | 36 ++++++++++++------------------------
>   1 file changed, 12 insertions(+), 24 deletions(-)
>

Applied, thanks.

Regards,
-Denis


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

end of thread, other threads:[~2015-11-02 18:41 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-11-02 16:48 [PATCH] gril: Fix access to notify callbacks Alfonso Sanchez-Beato
2015-11-02 18:41 ` 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.