diff mbox series

[1/2] qmimodem: Use l_queue instead of GList for notifications

Message ID 20240222235356.32485-1-steve.schrock@getcruise.com (mailing list archive)
State Accepted
Commit 6254bf0ce2d77bf0b259286d251dec0ef17f40e0
Headers show
Series [1/2] qmimodem: Use l_queue instead of GList for notifications | expand

Commit Message

Steve Schrock Feb. 22, 2024, 11:53 p.m. UTC
---
 drivers/qmimodem/qmi.c | 52 ++++++++++++++++++++----------------------
 1 file changed, 25 insertions(+), 27 deletions(-)

Comments

patchwork-bot+ofono@kernel.org Feb. 23, 2024, 4:10 p.m. UTC | #1
Hello:

This series was applied to ofono.git (master)
by Denis Kenzior <denkenz@gmail.com>:

On Thu, 22 Feb 2024 23:53:55 +0000 you wrote:
> ---
>  drivers/qmimodem/qmi.c | 52 ++++++++++++++++++++----------------------
>  1 file changed, 25 insertions(+), 27 deletions(-)

Here is the summary with links:
  - [1/2] qmimodem: Use l_queue instead of GList for notifications
    https://git.kernel.org/pub/scm/network/ofono/ofono.git/?id=6254bf0ce2d7
  - [2/2] qmimodem: Use l_queue instead of GList for pending service creation
    (no matching commit)

You are awesome, thank you!
diff mbox series

Patch

diff --git a/drivers/qmimodem/qmi.c b/drivers/qmimodem/qmi.c
index 268db1f7..168dee1a 100644
--- a/drivers/qmimodem/qmi.c
+++ b/drivers/qmimodem/qmi.c
@@ -112,7 +112,7 @@  struct qmi_service {
 	uint16_t minor;
 	uint8_t client_id;
 	uint16_t next_notify_id;
-	GList *notify_list;
+	struct l_queue *notify_list;
 };
 
 struct qmi_param {
@@ -256,7 +256,7 @@  static void __discovery_free(void *data)
 	destroy(d);
 }
 
-static void __notify_free(gpointer data, gpointer user_data)
+static void __notify_free(void *data)
 {
 	struct qmi_notify *notify = data;
 
@@ -266,12 +266,12 @@  static void __notify_free(gpointer data, gpointer user_data)
 	l_free(notify);
 }
 
-static gint __notify_compare(gconstpointer a, gconstpointer b)
+static bool __notify_compare(const void *data, const void *user_data)
 {
-	const struct qmi_notify *notify = a;
-	uint16_t id = L_PTR_TO_UINT(b);
+	const struct qmi_notify *notify = data;
+	uint16_t id = L_PTR_TO_UINT(user_data);
 
-	return notify->id - id;
+	return notify->id == id;
 }
 
 struct service_find_by_type_data {
@@ -717,23 +717,26 @@  static uint16_t __request_submit(struct qmi_device *device,
 	return req->tid;
 }
 
+static void service_notify_if_message_matches(void *data, void *user_data)
+{
+	struct qmi_notify *notify = data;
+	struct qmi_result *result = user_data;
+
+	if (notify->message == result->message)
+		notify->callback(result, notify->user_data);
+}
+
 static void service_notify(const void *key, void *value, void *user_data)
 {
 	struct qmi_service *service = value;
 	struct qmi_result *result = user_data;
-	GList *list;
 
 	/* ignore those that are in process of creation */
 	if (L_PTR_TO_UINT(key) & 0x80000000)
 		return;
 
-	for (list = g_list_first(service->notify_list); list;
-						list = g_list_next(list)) {
-		struct qmi_notify *notify = list->data;
-
-		if (notify->message == result->message)
-			notify->callback(result, notify->user_data);
-	}
+	l_queue_foreach(service->notify_list, service_notify_if_message_matches,
+				result);
 }
 
 static void handle_indication(struct qmi_device *device,
@@ -1666,6 +1669,7 @@  static void qmux_client_create_callback(uint16_t message, uint16_t length,
 	service->minor = data->minor;
 
 	service->client_id = client_id->client;
+	service->notify_list = l_queue_new();
 
 	__debug_device(device, "service created [client=%d,type=%d]",
 					service->client_id, service->type);
@@ -2452,7 +2456,7 @@  uint16_t qmi_service_register(struct qmi_service *service,
 	notify->user_data = user_data;
 	notify->destroy = destroy;
 
-	service->notify_list = g_list_append(service->notify_list, notify);
+	l_queue_push_tail(service->notify_list, notify);
 
 	return notify->id;
 }
@@ -2461,21 +2465,17 @@  bool qmi_service_unregister(struct qmi_service *service, uint16_t id)
 {
 	unsigned int nid = id;
 	struct qmi_notify *notify;
-	GList *list;
 
 	if (!service || !id)
 		return false;
 
-	list = g_list_find_custom(service->notify_list,
-				L_UINT_TO_PTR(nid), __notify_compare);
-	if (!list)
-		return false;
-
-	notify = list->data;
+	notify = l_queue_remove_if(service->notify_list, __notify_compare,
+					L_UINT_TO_PTR(nid));
 
-	service->notify_list = g_list_delete_link(service->notify_list, list);
+	if (!notify)
+		return false;
 
-	__notify_free(notify, NULL);
+	__notify_free(notify);
 
 	return true;
 }
@@ -2485,9 +2485,7 @@  bool qmi_service_unregister_all(struct qmi_service *service)
 	if (!service)
 		return false;
 
-	g_list_foreach(service->notify_list, __notify_free, NULL);
-	g_list_free(service->notify_list);
-
+	l_queue_destroy(service->notify_list, __notify_free);
 	service->notify_list = NULL;
 
 	return true;